diff --git a/src/wp-includes/connectors.php b/src/wp-includes/connectors.php index 63e018074fd58..993020b6f679c 100644 --- a/src/wp-includes/connectors.php +++ b/src/wp-includes/connectors.php @@ -552,9 +552,19 @@ function _wp_register_default_connector_settings(): void { continue; } - // For AI providers, skip if the provider is not in the AI Client registry. - if ( 'ai_provider' === $connector_data['type'] && ! $ai_registry->hasProvider( $connector_id ) ) { - continue; + if ( 'ai_provider' === $connector_data['type'] ) { + // For AI providers, skip if the provider is not in the AI Client registry. + if ( ! $ai_registry->hasProvider( $connector_id ) ) { + continue; + } + } else { + if ( ! isset( $connector_data['plugin']['is_active'] ) || ! is_callable( $connector_data['plugin']['is_active'] ) ) { + continue; + } + + if ( ! call_user_func( $connector_data['plugin']['is_active'] ) ) { + continue; + } } register_setting( diff --git a/tests/phpunit/tests/connectors/wpRegisterDefaultConnectorSettings.php b/tests/phpunit/tests/connectors/wpRegisterDefaultConnectorSettings.php new file mode 100644 index 0000000000000..19ba81ba8ac2b --- /dev/null +++ b/tests/phpunit/tests/connectors/wpRegisterDefaultConnectorSettings.php @@ -0,0 +1,67 @@ +original_registered_settings = $wp_registered_settings; + } + + /** + * Removes the test connector and restores registered settings. + */ + public function tear_down(): void { + $registry = WP_Connector_Registry::get_instance(); + if ( null !== $registry && $registry->is_registered( self::CONNECTOR_ID ) ) { + $registry->unregister( self::CONNECTOR_ID ); + } + + global $wp_registered_settings; + $wp_registered_settings = $this->original_registered_settings; + + parent::tear_down(); + } + + /** + * @ticket 64730 + */ + public function test_non_ai_connector_skipped_when_is_active_missing(): void { + WP_Connector_Registry::get_instance()->register( + self::CONNECTOR_ID, + array( + 'name' => 'Test Non-AI Connector', + 'description' => '', + 'type' => 'spam_filtering', + 'authentication' => array( + 'method' => 'api_key', + 'setting_name' => self::SETTING_NAME, + ), + ) + ); + + _wp_register_default_connector_settings(); + + $this->assertArrayNotHasKey( self::SETTING_NAME, get_registered_settings() ); + } +}