From 682c92d45cdaa3a27b8b0cf16f56442d30077f94 Mon Sep 17 00:00:00 2001 From: Aditya Singh Date: Thu, 2 Apr 2026 11:15:10 +0530 Subject: [PATCH 1/3] Connectors: account for mu-plugins when resolving plugin.file status fixes #76984 --- lib/experimental/connectors/default-connectors.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/experimental/connectors/default-connectors.php b/lib/experimental/connectors/default-connectors.php index 9842c3a8e4ae7b..fe40daac7e447b 100644 --- a/lib/experimental/connectors/default-connectors.php +++ b/lib/experimental/connectors/default-connectors.php @@ -524,9 +524,11 @@ function _gutenberg_get_connector_script_module_data( array $data ): array { ); if ( ! empty( $connector_data['plugin']['file'] ) ) { - $file = $connector_data['plugin']['file']; - $is_installed = file_exists( WP_PLUGIN_DIR . '/' . $file ); - $is_activated = $is_installed && is_plugin_active( $file ); + $file = $connector_data['plugin']['file']; + $is_in_regular_plugins = file_exists( WP_PLUGIN_DIR . '/' . $file ); + $is_in_mu_plugins = file_exists( WPMU_PLUGIN_DIR . '/' . $file ); + $is_installed = $is_in_regular_plugins || $is_in_mu_plugins; + $is_activated = $is_installed && ( $is_in_mu_plugins || is_plugin_active( $file ) ); $connector_out['plugin'] = array( 'file' => $file, From 9298eaf99f13ec7b4fef5723fa5d04502f9ac36a Mon Sep 17 00:00:00 2001 From: Aditya Singh Date: Fri, 3 Apr 2026 16:58:14 +0530 Subject: [PATCH 2/3] Connectors: Add is_active callback to plugin definition for better activation checks --- .../class-wp-connector-registry.php | 19 ++++++++++++++++++- .../connectors/default-connectors.php | 19 +++++++++++++------ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/lib/compat/wordpress-7.0/class-wp-connector-registry.php b/lib/compat/wordpress-7.0/class-wp-connector-registry.php index 691e480b4fa7a3..e6fbd2d5842c5f 100644 --- a/lib/compat/wordpress-7.0/class-wp-connector-registry.php +++ b/lib/compat/wordpress-7.0/class-wp-connector-registry.php @@ -28,7 +28,8 @@ * env_var_name?: non-empty-string * }, * plugin?: array{ - * file: non-empty-string + * file: non-empty-string, + * is_active?: callable(): bool * } * } */ @@ -99,6 +100,8 @@ final class WP_Connector_Registry { * * @type string $file The plugin's main file path relative to the plugins * directory (e.g. 'akismet/akismet.php' or 'hello.php'). + * @type callable $is_active Optional callback to determine whether the plugin + * is active. Receives no arguments and must return bool. * } * } * @return array|null The registered connector data on success, null on failure. @@ -233,6 +236,20 @@ public function register( string $id, array $args ): ?array { if ( ! empty( $args['plugin'] ) && is_array( $args['plugin'] ) && ! empty( $args['plugin']['file'] ) ) { $connector['plugin'] = array( 'file' => $args['plugin']['file'] ); + + if ( isset( $args['plugin']['is_active'] ) ) { + if ( ! is_callable( $args['plugin']['is_active'] ) ) { + _doing_it_wrong( + __METHOD__, + /* translators: %s: Connector ID. */ + sprintf( __( 'Connector "%s" plugin is_active must be callable.' ), esc_html( $id ) ), + '7.0.0' + ); + return null; + } + + $connector['plugin']['is_active'] = $args['plugin']['is_active']; + } } $this->registered_connectors[ $id ] = $connector; diff --git a/lib/experimental/connectors/default-connectors.php b/lib/experimental/connectors/default-connectors.php index fe40daac7e447b..fb04fd101bcece 100644 --- a/lib/experimental/connectors/default-connectors.php +++ b/lib/experimental/connectors/default-connectors.php @@ -31,7 +31,10 @@ function _gutenberg_connectors_init(): void { 'description' => __( 'Protect your site from spam.', 'gutenberg' ), 'type' => 'spam_filtering', 'plugin' => array( - 'file' => 'akismet/akismet.php', + 'file' => 'akismet/akismet.php', + 'is_active' => function () { + return defined( 'AKISMET_VERSION' ) && class_exists( 'Akismet', false ); + }, ), 'authentication' => array( 'method' => 'api_key', @@ -524,11 +527,15 @@ function _gutenberg_get_connector_script_module_data( array $data ): array { ); if ( ! empty( $connector_data['plugin']['file'] ) ) { - $file = $connector_data['plugin']['file']; - $is_in_regular_plugins = file_exists( WP_PLUGIN_DIR . '/' . $file ); - $is_in_mu_plugins = file_exists( WPMU_PLUGIN_DIR . '/' . $file ); - $is_installed = $is_in_regular_plugins || $is_in_mu_plugins; - $is_activated = $is_installed && ( $is_in_mu_plugins || is_plugin_active( $file ) ); + $file = $connector_data['plugin']['file']; + + if ( ! empty( $connector_data['plugin']['is_active'] ) && is_callable( $connector_data['plugin']['is_active'] ) ) { + $is_activated = (bool) call_user_func( $connector_data['plugin']['is_active'] ); + $is_installed = $is_activated; + } else { + $is_installed = file_exists( WP_PLUGIN_DIR . '/' . $file ); + $is_activated = $is_installed && is_plugin_active( $file ); + } $connector_out['plugin'] = array( 'file' => $file, From d78692b88fb579d775186a3b78129e3bf6f56c8c Mon Sep 17 00:00:00 2001 From: Aditya Singh Date: Fri, 3 Apr 2026 23:04:15 +0530 Subject: [PATCH 3/3] Connectors: Refactor plugin detection and remove hardcoded Akismet logic Updated _gutenberg_get_connector_script_module_data to prioritize the is_active callback Removed the manual Akismet registration from _gutenberg_connectors_init --- .../connectors/default-connectors.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/experimental/connectors/default-connectors.php b/lib/experimental/connectors/default-connectors.php index fb04fd101bcece..2d08f162738004 100644 --- a/lib/experimental/connectors/default-connectors.php +++ b/lib/experimental/connectors/default-connectors.php @@ -31,10 +31,7 @@ function _gutenberg_connectors_init(): void { 'description' => __( 'Protect your site from spam.', 'gutenberg' ), 'type' => 'spam_filtering', 'plugin' => array( - 'file' => 'akismet/akismet.php', - 'is_active' => function () { - return defined( 'AKISMET_VERSION' ) && class_exists( 'Akismet', false ); - }, + 'file' => 'akismet/akismet.php', ), 'authentication' => array( 'method' => 'api_key', @@ -527,14 +524,22 @@ function _gutenberg_get_connector_script_module_data( array $data ): array { ); if ( ! empty( $connector_data['plugin']['file'] ) ) { - $file = $connector_data['plugin']['file']; + $file = $connector_data['plugin']['file']; + $is_installed = false; + $is_activated = false; if ( ! empty( $connector_data['plugin']['is_active'] ) && is_callable( $connector_data['plugin']['is_active'] ) ) { $is_activated = (bool) call_user_func( $connector_data['plugin']['is_active'] ); - $is_installed = $is_activated; + } + + if ( ! $is_activated ) { + $is_activated = is_plugin_active( $file ); + } + + if ( $is_activated ) { + $is_installed = true; } else { $is_installed = file_exists( WP_PLUGIN_DIR . '/' . $file ); - $is_activated = $is_installed && is_plugin_active( $file ); } $connector_out['plugin'] = array(