diff --git a/includes/bootstrap.php b/includes/bootstrap.php index e243be3e..760aa77f 100644 --- a/includes/bootstrap.php +++ b/includes/bootstrap.php @@ -125,6 +125,39 @@ static function () { return true; } +/** + * Checks whether the current WordPress environment supports AI. + * + * Displays an admin notice if not. + * + * @since x.x.x + * + * @return bool True if AI is supported, false otherwise. + */ +function check_ai_support(): bool { + // @todo Remove the function check once the minimum WordPress version is 7.0 or higher. + if ( ! function_exists( 'wp_supports_ai' ) || wp_supports_ai() ) { + return true; + } + + foreach ( array( 'admin_notices', 'network_admin_notices' ) as $hook ) { + add_action( + $hook, + static function () { + wp_admin_notice( + esc_html__( 'Your WordPress environment has AI functionality disabled. The AI Experiments plugin will not work until AI support is enabled.', 'ai' ), + array( + 'type' => 'error', + 'dismiss' => false, + ) + ); + } + ); + } + + return false; +} + /** * Adds action links to the plugin list table. * @@ -306,8 +339,8 @@ function load(): void { return; } - // Check version requirements. - if ( ! check_php_version() || ! check_wp_version() ) { + // Check plugin requirements. + if ( ! check_php_version() || ! check_wp_version() || ! check_ai_support() ) { return; } @@ -331,8 +364,8 @@ function load(): void { // Add plugin action links. add_filter( 'plugin_action_links_' . plugin_basename( WPAI_PLUGIN_FILE ), __NAMESPACE__ . '\plugin_action_links' ); - // Hook feature initialization to init. - add_action( 'init', __NAMESPACE__ . '\initialize_features', 15 ); + // Hook experiment initialization to init. + add_action( 'init', __NAMESPACE__ . '\initialize_experiments' ); } /**