-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathai-services.php
98 lines (86 loc) · 2.67 KB
/
ai-services.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* Plugin Name: AI Services
* Plugin URI: https://wordpress.org/plugins/ai-services/
* Description: Makes AI centrally available in WordPress, whether via PHP, REST API, JavaScript, or WP-CLI - for any provider.
* Requires at least: 6.0
* Requires PHP: 7.2
* Version: 0.4.0
* Author: Felix Arntz
* Author URI: https://felix-arntz.me
* License: GPLv2 or later
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* Text Domain: ai-services
*
* @package ai-services
*/
// This loader file should remain compatible with PHP 5.2.
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
require_once plugin_dir_path( __FILE__ ) . 'constants.php';
/**
* Checks basic requirements and loads the plugin.
*
* @since 0.1.0
*/
function ai_services_load() /* @phpstan-ignore-line */ {
static $loaded = false;
// Check for supported PHP version.
if (
version_compare( phpversion(), AI_SERVICES_MINIMUM_PHP, '<' )
|| version_compare( get_bloginfo( 'version' ), AI_SERVICES_MINIMUM_WP, '<' )
) {
add_action( 'admin_notices', 'ai_services_display_version_requirements_notice' );
return;
}
// Register the autoloader.
if ( ! ai_services_register_autoloader() ) {
add_action( 'admin_notices', 'ai_services_display_composer_autoload_notice' );
return;
}
// Prevent loading the plugin twice.
if ( $loaded ) {
return;
}
$loaded = true;
// Load the plugin.
$class_name = 'Felix_Arntz\AI_Services\Plugin_Main';
$instance = new $class_name( __FILE__ );
$instance->add_hooks();
require_once plugin_dir_path( __FILE__ ) . 'includes/api.php';
}
/**
* Displays admin notice about unmet PHP version requirement.
*
* @since 0.1.0
*/
function ai_services_display_version_requirements_notice() /* @phpstan-ignore-line */ {
echo '<div class="notice notice-error"><p>';
echo esc_html(
sprintf(
/* translators: 1: required PHP version, 2: required WP version, 3: current PHP version, 4: current WP version */
__( 'AI Services requires at least PHP version %1$s and WordPress version %2$s. Your site is currently using PHP %3$s and WordPress %4$s.', 'ai-services' ),
AI_SERVICES_MINIMUM_PHP,
phpversion(),
AI_SERVICES_MINIMUM_WP,
get_bloginfo( 'version' )
)
);
echo '</p></div>';
}
/**
* Displays admin notice about missing Composer autoload files.
*
* @since 0.1.0
*/
function ai_services_display_composer_autoload_notice() /* @phpstan-ignore-line */ {
echo '<div class="notice notice-error"><p>';
printf(
/* translators: %s: composer install command */
esc_html__( 'Your installation of AI Services is incomplete. Please run %s.', 'ai-services' ),
'<code>composer install</code>'
);
echo '</p></div>';
}
ai_services_load();