From 2f39fe244c60d736fdd78b00d31de7a183b2fecb Mon Sep 17 00:00:00 2001 From: raftaar1191 Date: Fri, 27 Mar 2026 13:22:36 +0530 Subject: [PATCH 1/5] Fix #1222: respect wp_supports_ai() in Namer --- includes/Admin/Namer_Page.php | 25 ++++++++++----- includes/Traits/AI_Utils.php | 60 +++++++++++++++++++++++++++++++---- 2 files changed, 71 insertions(+), 14 deletions(-) diff --git a/includes/Admin/Namer_Page.php b/includes/Admin/Namer_Page.php index 9b58c06e0..d3e0a8dbe 100644 --- a/includes/Admin/Namer_Page.php +++ b/includes/Admin/Namer_Page.php @@ -268,15 +268,24 @@ public function render_page() { -

- -

-

- - - -

+
+

+ get_error_message() ); + ?> +

+
+ check_ai_prerequisites() && is_wp_error( $this->check_ai_connectors() ) ) { + ?> +

+ + + +

+ diff --git a/includes/Traits/AI_Utils.php b/includes/Traits/AI_Utils.php index 18a9fd6f4..ea67ca191 100644 --- a/includes/Traits/AI_Utils.php +++ b/includes/Traits/AI_Utils.php @@ -18,28 +18,54 @@ trait AI_Utils { /** - * Gets AI configuration from core AI connectors. + * Checks AI prerequisites: feature flag, function availability, and version. * * @since 1.9.0 * - * @param string $model_preference Selected model preference (optional). - * @return array|WP_Error AI config array or error. + * @return true|WP_Error True if all prerequisites are met, WP_Error otherwise. */ - protected function get_ai_config( $model_preference = '' ) { + protected function check_ai_prerequisites() { + + if ( function_exists( 'wp_supports_ai' ) && ! wp_supports_ai() ) { + return new WP_Error( + 'ai_disabled', + __( 'The Plugin Check Namer feature requires AI support to be enabled on this site. Please enable AI functionality to use this feature.', 'plugin-check' ) + ); + } + if ( ! function_exists( 'wp_ai_client_prompt' ) ) { return new WP_Error( 'ai_client_not_available', - __( 'The AI client is not available. This feature requires WordPress 7.0 or newer.', 'plugin-check' ) + sprintf( + /* translators: %s: WordPress version. */ + __( 'The Plugin Check Namer Tool requires WordPress version 7.0 or newer. You are running WordPress version %s.', 'plugin-check' ), + get_bloginfo( 'version' ) + ) ); } if ( ! is_wp_version_compatible( '7.0' ) ) { return new WP_Error( 'ai_client_not_available', - __( 'The AI client is only available in WordPress 7.0 or newer.', 'plugin-check' ) + sprintf( + /* translators: %s: WordPress version. */ + __( 'The Plugin Check Namer Tool requires WordPress version 7.0 or higher. You are running WordPress version %s.', 'plugin-check' ), + get_bloginfo( 'version' ) + ) ); } + return true; + } + + /** + * Checks that at least one AI connector is configured and active. + * + * @since 1.9.0 + * + * @return true|WP_Error True if a connector is available, WP_Error otherwise. + */ + protected function check_ai_connectors() { if ( $this->has_no_active_ai_connectors() ) { return new WP_Error( 'ai_not_configured', @@ -47,6 +73,28 @@ protected function get_ai_config( $model_preference = '' ) { ); } + return true; + } + + /** + * Gets AI configuration from core AI connectors. + * + * @since 1.9.0 + * + * @param string $model_preference Selected model preference (optional). + * @return array|WP_Error AI config array or error. + */ + protected function get_ai_config( $model_preference = '' ) { + $prerequisites = $this->check_ai_prerequisites(); + if ( is_wp_error( $prerequisites ) ) { + return $prerequisites; + } + + $connectors = $this->check_ai_connectors(); + if ( is_wp_error( $connectors ) ) { + return $connectors; + } + $builder = wp_ai_client_prompt( 'Plugin Check AI availability test.' ); if ( is_wp_error( $builder ) ) { return $builder; From b79d690036f9e21228d64aa839d76e9e2c089918 Mon Sep 17 00:00:00 2001 From: raftaar1191 Date: Fri, 27 Mar 2026 13:26:00 +0530 Subject: [PATCH 2/5] Refine Namer notices for AI prerequisites --- includes/Admin/Namer_Page.php | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/includes/Admin/Namer_Page.php b/includes/Admin/Namer_Page.php index d3e0a8dbe..cb4b0d415 100644 --- a/includes/Admin/Namer_Page.php +++ b/includes/Admin/Namer_Page.php @@ -54,7 +54,6 @@ public function add_hooks() { add_action( 'admin_menu', array( $this, 'add_page' ) ); add_action( 'admin_post_' . self::ACTION_ANALYZE, array( $this, 'handle_analyze' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); - add_action( 'admin_notices', array( $this, 'render_ai_notice' ) ); add_action( 'wp_ajax_plugin_check_namer_analyze', array( $this, 'ajax_analyze' ) ); } @@ -214,40 +213,6 @@ protected function get_author_name_from_request() { return trim( $author ); } - /** - * Renders admin notice when AI connectors are not configured. - * - * @since 1.9.0 - */ - public function render_ai_notice() { - $screen = get_current_screen(); - if ( ! $screen || $screen->id !== $this->hook_suffix ) { - return; - } - - if ( ! current_user_can( 'manage_options' ) ) { - return; - } - - $ai_config = $this->get_ai_config(); - if ( ! is_wp_error( $ai_config ) ) { - return; - } - ?> -
-

- get_error_message() ) - ); - ?> -

-
- Date: Fri, 27 Mar 2026 13:28:20 +0530 Subject: [PATCH 3/5] Refine AI prerequisite and connector checks --- includes/Traits/AI_Utils.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/Traits/AI_Utils.php b/includes/Traits/AI_Utils.php index ea67ca191..cb92a0802 100644 --- a/includes/Traits/AI_Utils.php +++ b/includes/Traits/AI_Utils.php @@ -20,7 +20,7 @@ trait AI_Utils { /** * Checks AI prerequisites: feature flag, function availability, and version. * - * @since 1.9.0 + * @since 2.0.0 * * @return true|WP_Error True if all prerequisites are met, WP_Error otherwise. */ @@ -61,7 +61,7 @@ protected function check_ai_prerequisites() { /** * Checks that at least one AI connector is configured and active. * - * @since 1.9.0 + * @since 2.0.0 * * @return true|WP_Error True if a connector is available, WP_Error otherwise. */ @@ -85,6 +85,7 @@ protected function check_ai_connectors() { * @return array|WP_Error AI config array or error. */ protected function get_ai_config( $model_preference = '' ) { + $prerequisites = $this->check_ai_prerequisites(); if ( is_wp_error( $prerequisites ) ) { return $prerequisites; From 7e6e0679fa839d5af897751deee271732f1c0608 Mon Sep 17 00:00:00 2001 From: raftaar1191 Date: Fri, 27 Mar 2026 13:33:43 +0530 Subject: [PATCH 4/5] Fix PHPStan for wp_ai_client_prompt in AI_Utils --- includes/Traits/AI_Utils.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/includes/Traits/AI_Utils.php b/includes/Traits/AI_Utils.php index cb92a0802..6ab10c8e5 100644 --- a/includes/Traits/AI_Utils.php +++ b/includes/Traits/AI_Utils.php @@ -96,6 +96,13 @@ protected function get_ai_config( $model_preference = '' ) { return $connectors; } + if ( ! function_exists( 'wp_ai_client_prompt' ) ) { + return new WP_Error( + 'ai_client_not_available', + __( 'The AI client is not available. This feature requires WordPress 7.0 or newer.', 'plugin-check' ) + ); + } + $builder = wp_ai_client_prompt( 'Plugin Check AI availability test.' ); if ( is_wp_error( $builder ) ) { return $builder; From 9c9ff4669a5e4ed71ed2c96fb4c28edad7002a7c Mon Sep 17 00:00:00 2001 From: raftaar1191 Date: Fri, 27 Mar 2026 13:39:38 +0530 Subject: [PATCH 5/5] Refine AI_Utils checks after CI validation --- includes/Traits/AI_Utils.php | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/includes/Traits/AI_Utils.php b/includes/Traits/AI_Utils.php index 6ab10c8e5..cf43bfbd9 100644 --- a/includes/Traits/AI_Utils.php +++ b/includes/Traits/AI_Utils.php @@ -33,17 +33,6 @@ protected function check_ai_prerequisites() { ); } - if ( ! function_exists( 'wp_ai_client_prompt' ) ) { - return new WP_Error( - 'ai_client_not_available', - sprintf( - /* translators: %s: WordPress version. */ - __( 'The Plugin Check Namer Tool requires WordPress version 7.0 or newer. You are running WordPress version %s.', 'plugin-check' ), - get_bloginfo( 'version' ) - ) - ); - } - if ( ! is_wp_version_compatible( '7.0' ) ) { return new WP_Error( 'ai_client_not_available', @@ -99,7 +88,11 @@ protected function get_ai_config( $model_preference = '' ) { if ( ! function_exists( 'wp_ai_client_prompt' ) ) { return new WP_Error( 'ai_client_not_available', - __( 'The AI client is not available. This feature requires WordPress 7.0 or newer.', 'plugin-check' ) + sprintf( + /* translators: %s: WordPress version. */ + __( 'The Plugin Check Namer Tool requires WordPress version 7.0 or newer. You are running WordPress version %s.', 'plugin-check' ), + get_bloginfo( 'version' ) + ) ); }