Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/wp-includes/class-wp-connector-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ final class WP_Connector_Registry {
* For connectors with `api_key` authentication, a `setting_name` can be provided
* explicitly. If omitted, one is automatically generated using the pattern
* `connectors_{$type}_{$id}_api_key`, with hyphens in the type and ID normalized
* to underscores (e.g., connector type `spam_filtering` with ID `akismet` produces
* `connectors_spam_filtering_akismet_api_key`). This setting name is used for the
* to underscores (e.g., connector type `spam_filtering` with ID `my_plugin` produces
* `connectors_spam_filtering_my_plugin_api_key`). This setting name is used for the
* Settings API registration and REST API exposure.
*
* Registering a connector with an ID that is already registered will trigger a
Expand Down Expand Up @@ -110,7 +110,7 @@ final class WP_Connector_Registry {
* Optional. Plugin data for install/activate UI.
*
* @type string $file The plugin's main file path relative to the plugins
* directory (e.g. 'akismet/akismet.php' or 'hello.php').
* directory (e.g. 'my-plugin/my-plugin.php' or 'hello.php').
* }
* }
* @return array|null The registered connector data on success, null on failure.
Expand Down
29 changes: 5 additions & 24 deletions src/wp-includes/connectors.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function wp_is_connector_registered( string $id ): bool {
* Optional. Plugin data for install/activate UI.
*
* @type string $file The plugin's main file path relative to the plugins
* directory (e.g. 'akismet/akismet.php' or 'hello.php').
* directory (e.g. 'my-plugin/my-plugin.php' or 'hello.php').
* }
* }
* @phpstan-return ?array{
Expand Down Expand Up @@ -120,7 +120,7 @@ function wp_get_connector( string $id ): ?array {
* Optional. Plugin data for install/activate UI.
*
* @type string $file The plugin's main file path relative to the plugins
* directory (e.g. 'akismet/akismet.php' or 'hello.php').
* directory (e.g. 'my-plugin/my-plugin.php' or 'hello.php').
* }
* }
* }
Expand Down Expand Up @@ -210,25 +210,6 @@ function _wp_connectors_init(): void {
_wp_connectors_register_default_ai_providers( $registry );
}

// Non-AI default connectors.
$registry->register(
'akismet',
array(
'name' => __( 'Akismet Anti-spam' ),
'description' => __( 'Protect your site from spam.' ),
'type' => 'spam_filtering',
'plugin' => array(
'file' => 'akismet/akismet.php',
),
'authentication' => array(
'method' => 'api_key',
'credentials_url' => 'https://akismet.com/get/',
'setting_name' => 'wordpress_api_key',
'constant_name' => 'WPCOM_API_KEY',
),
)
);

/**
* Fires when the connector registry is ready for plugins to register connectors.
*
Expand Down Expand Up @@ -417,9 +398,9 @@ function _wp_connectors_mask_api_key( string $key ): string {
* @since 7.0.0
* @access private
*
* @param string $setting_name The option name for the API key (e.g., 'connectors_spam_filtering_akismet_api_key').
* @param string $env_var_name Optional. Environment variable name to check (e.g., 'AKISMET_API_KEY').
* @param string $constant_name Optional. PHP constant name to check (e.g., 'AKISMET_API_KEY').
* @param string $setting_name The option name for the API key (e.g., 'connectors_spam_filtering_my_plugin_api_key').
* @param string $env_var_name Optional. Environment variable name to check (e.g., 'MY_PLUGIN_API_KEY').
* @param string $constant_name Optional. PHP constant name to check (e.g., 'MY_PLUGIN_API_KEY').
* @return string The key source: 'env', 'constant', 'database', or 'none'.
*/
function _wp_connectors_get_api_key_source( string $setting_name, string $env_var_name = '', string $constant_name = '' ): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ public function test_returns_expected_connector_keys(): void {
$this->assertArrayHasKey( 'google', $connectors );
$this->assertArrayHasKey( 'openai', $connectors );
$this->assertArrayHasKey( 'anthropic', $connectors );
$this->assertArrayHasKey( 'akismet', $connectors );
$this->assertArrayHasKey( 'mock-connectors-test', $connectors );
$this->assertCount( 5, $connectors );
$this->assertCount( 4, $connectors );
}

/**
Expand All @@ -57,7 +56,7 @@ public function test_each_connector_has_required_fields(): void {
$this->assertArrayHasKey( 'description', $connector_data, "Connector '{$connector_id}' is missing 'description'." );
$this->assertIsString( $connector_data['description'], "Connector '{$connector_id}' description should be a string." );
$this->assertArrayHasKey( 'type', $connector_data, "Connector '{$connector_id}' is missing 'type'." );
$this->assertContains( $connector_data['type'], array( 'ai_provider', 'spam_filtering' ), "Connector '{$connector_id}' has unexpected type '{$connector_data['type']}'." );
$this->assertContains( $connector_data['type'], array( 'ai_provider' ), "Connector '{$connector_id}' has unexpected type '{$connector_data['type']}'." );
$this->assertArrayHasKey( 'authentication', $connector_data, "Connector '{$connector_id}' is missing 'authentication'." );
$this->assertIsArray( $connector_data['authentication'], "Connector '{$connector_id}' authentication should be an array." );
$this->assertArrayHasKey( 'method', $connector_data['authentication'], "Connector '{$connector_id}' authentication is missing 'method'." );
Expand All @@ -80,16 +79,11 @@ public function test_api_key_connectors_have_setting_name_and_credentials_url():
++$api_key_count;

$this->assertArrayHasKey( 'setting_name', $connector_data['authentication'], "Connector '{$connector_id}' authentication is missing 'setting_name'." );

// AI providers use the connectors_ai_{id}_api_key convention.
// Non-AI connectors may use custom setting names.
if ( 'ai_provider' === $connector_data['type'] ) {
$this->assertSame(
'connectors_ai_' . str_replace( '-', '_', $connector_id ) . '_api_key',
$connector_data['authentication']['setting_name'] ?? null,
"Connector '{$connector_id}' setting_name does not match expected format."
);
}
$this->assertSame(
'connectors_ai_' . str_replace( '-', '_', $connector_id ) . '_api_key',
$connector_data['authentication']['setting_name'] ?? null,
"Connector '{$connector_id}' setting_name does not match expected format."
);
}

$this->assertGreaterThan( 0, $api_key_count, 'At least one connector should use api_key authentication.' );
Expand Down
1 change: 0 additions & 1 deletion tests/phpunit/tests/rest-api/rest-settings-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ public function test_get_items() {
'default_ping_status',
'default_comment_status',
'site_icon', // Registered in wp-includes/blocks/site-logo.php
'wordpress_api_key', // Registered by Akismet connector.
'wp_collaboration_enabled',
);

Expand Down
7 changes: 0 additions & 7 deletions tests/qunit/fixtures/wp-api-generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -11011,12 +11011,6 @@ mockedApiResponse.Schema = {
"PATCH"
],
"args": {
"wordpress_api_key": {
"title": "Akismet Anti-spam API Key",
"description": "API key for the Akismet Anti-spam connector.",
"type": "string",
"required": false
},
"title": {
"title": "Title",
"description": "Site title.",
Expand Down Expand Up @@ -14550,7 +14544,6 @@ mockedApiResponse.CommentModel = {
};

mockedApiResponse.settings = {
"wordpress_api_key": "",
"title": "Test Blog",
"description": "",
"url": "http://example.org",
Expand Down
Loading