Skip to content

Commit bd4090d

Browse files
gzioloclaude
andcommitted
Connectors: Add registry guards before registering settings and passing keys.
Skip `register_setting` in `_wp_register_default_connector_settings()` when the AI provider is not in the registry, preventing REST-exposed settings that silently reject values. Reorder the `hasProvider` check in `_wp_connectors_pass_default_keys_to_ai_client()` to run before reading the option. Update the REST settings test to reflect that connector settings are only registered when their provider is active. Follow-up to [555bb8a], [bd6c4c8]. See #64791. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2b6427b commit bd4090d

File tree

3 files changed

+12
-26
lines changed

3 files changed

+12
-26
lines changed

src/wp-includes/connectors.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,19 @@ function _wp_connectors_validate_keys_in_rest( WP_REST_Response $response, WP_RE
316316
* @access private
317317
*/
318318
function _wp_register_default_connector_settings(): void {
319+
$registry = AiClient::defaultRegistry();
320+
319321
foreach ( _wp_connectors_get_connector_settings() as $connector_id => $connector_data ) {
320322
$auth = $connector_data['authentication'];
321323
if ( 'ai_provider' !== $connector_data['type'] || 'api_key' !== $auth['method'] || empty( $auth['setting_name'] ) ) {
322324
continue;
323325
}
324326

327+
// Skip registering the setting if the provider is not in the registry.
328+
if ( ! $registry->hasProvider( $connector_id ) ) {
329+
continue;
330+
}
331+
325332
$setting_name = $auth['setting_name'];
326333
register_setting(
327334
'connectors',
@@ -375,8 +382,12 @@ function _wp_connectors_pass_default_keys_to_ai_client(): void {
375382
continue;
376383
}
377384

385+
if ( ! $registry->hasProvider( $connector_id ) ) {
386+
continue;
387+
}
388+
378389
$api_key = _wp_connectors_get_real_api_key( $auth['setting_name'], '_wp_connectors_mask_api_key' );
379-
if ( '' === $api_key || ! $registry->hasProvider( $connector_id ) ) {
390+
if ( '' === $api_key ) {
380391
continue;
381392
}
382393

tests/phpunit/tests/rest-api/rest-settings-controller.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@ public function test_get_items() {
120120
'default_comment_status',
121121
'site_icon', // Registered in wp-includes/blocks/site-logo.php
122122
'wp_enable_real_time_collaboration',
123-
// Connectors API keys are registered in _wp_register_default_connector_settings() in wp-includes/connectors.php.
124-
'connectors_ai_anthropic_api_key',
125-
'connectors_ai_google_api_key',
126-
'connectors_ai_openai_api_key',
127123
);
128124

129125
if ( ! is_multisite() ) {

tests/qunit/fixtures/wp-api-generated.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11066,24 +11066,6 @@ mockedApiResponse.Schema = {
1106611066
"PATCH"
1106711067
],
1106811068
"args": {
11069-
"connectors_ai_anthropic_api_key": {
11070-
"title": "Anthropic API Key",
11071-
"description": "API key for the Anthropic AI provider.",
11072-
"type": "string",
11073-
"required": false
11074-
},
11075-
"connectors_ai_google_api_key": {
11076-
"title": "Google API Key",
11077-
"description": "API key for the Google AI provider.",
11078-
"type": "string",
11079-
"required": false
11080-
},
11081-
"connectors_ai_openai_api_key": {
11082-
"title": "OpenAI API Key",
11083-
"description": "API key for the OpenAI AI provider.",
11084-
"type": "string",
11085-
"required": false
11086-
},
1108711069
"title": {
1108811070
"title": "Title",
1108911071
"description": "Site title.",
@@ -14762,9 +14744,6 @@ mockedApiResponse.CommentModel = {
1476214744
};
1476314745

1476414746
mockedApiResponse.settings = {
14765-
"connectors_ai_anthropic_api_key": "",
14766-
"connectors_ai_google_api_key": "",
14767-
"connectors_ai_openai_api_key": "",
1476814747
"title": "Test Blog",
1476914748
"description": "",
1477014749
"url": "http://example.org",

0 commit comments

Comments
 (0)