diff --git a/src/wp-includes/connectors.php b/src/wp-includes/connectors.php index 68c8b4c1570d0..a11faeb637623 100644 --- a/src/wp-includes/connectors.php +++ b/src/wp-includes/connectors.php @@ -210,6 +210,25 @@ 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. * diff --git a/tests/phpunit/tests/connectors/wpConnectorsGetConnectorSettings.php b/tests/phpunit/tests/connectors/wpConnectorsGetConnectorSettings.php index cedac90111101..9d6c4b8486d9c 100644 --- a/tests/phpunit/tests/connectors/wpConnectorsGetConnectorSettings.php +++ b/tests/phpunit/tests/connectors/wpConnectorsGetConnectorSettings.php @@ -37,8 +37,9 @@ 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( 4, $connectors ); + $this->assertCount( 5, $connectors ); } /** @@ -56,7 +57,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' ), "Connector '{$connector_id}' has unexpected type '{$connector_data['type']}'." ); + $this->assertContains( $connector_data['type'], array( 'ai_provider', 'spam_filtering' ), "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'." ); @@ -79,11 +80,16 @@ 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'." ); - $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." - ); + + // 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->assertGreaterThan( 0, $api_key_count, 'At least one connector should use api_key authentication.' ); diff --git a/tests/phpunit/tests/rest-api/rest-settings-controller.php b/tests/phpunit/tests/rest-api/rest-settings-controller.php index b83cef41d2cf3..7f2ea9eba71f7 100644 --- a/tests/phpunit/tests/rest-api/rest-settings-controller.php +++ b/tests/phpunit/tests/rest-api/rest-settings-controller.php @@ -119,6 +119,7 @@ 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', ); diff --git a/tests/qunit/fixtures/wp-api-generated.js b/tests/qunit/fixtures/wp-api-generated.js index 003dc397ae305..c3ca057691308 100644 --- a/tests/qunit/fixtures/wp-api-generated.js +++ b/tests/qunit/fixtures/wp-api-generated.js @@ -11011,6 +11011,12 @@ 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.", @@ -14544,6 +14550,7 @@ mockedApiResponse.CommentModel = { }; mockedApiResponse.settings = { + "wordpress_api_key": "", "title": "Test Blog", "description": "", "url": "http://example.org",