Make WordPress Core

Opened 4 weeks ago

Closed 3 weeks ago

Last modified 11 days ago

#64730 closed enhancement (fixed)

Connectors: Backport Connectors Screen

Reported by: jorgefilipecosta's profile jorgefilipecosta Owned by: jorgefilipecosta's profile jorgefilipecosta
Milestone: 7.0 Priority: high
Severity: normal Version: trunk
Component: Administration Keywords: has-patch has-unit-tests needs-dev-note
Focuses: Cc:

Description

Backport of โ€‹Gutenberg PR #75833.
Core PR: โ€‹#11056.

The generated Connectors JS/runtime artifacts will be included during the core Gutenberg sync. This ticket tracks the backport of the PHP integration that wires the feature into wp-admin and REST settings.

What This Changes

Registers a new submenu under Settings:
wp-admin/options-general.php?page=connectors-wp-admin
Menu label: Connectors
Position: between General and Writing (position 1)
Registers connector settings (REST-exposed):
connectors_openai_api_key
connectors_anthropic_api_key
connectors_gemini_api_key
Adds API key masking on option reads.
Adds server-side key validation behavior for /wp/v2/settings responses:
when connector fields are requested via _fields, invalid keys are returned as invalid_key.
Passes stored connector keys to the AI client provider registry on init.
Adds guard checks so behavior no-ops when AI client/runtime callback is unavailable.

Testing Instructions

Visit wp-admin/options-general.php?page=connectors-wp-admin and verify the Connectors page appears under Settings.
Verify Connectors appears between General and Writing in the Settings submenu.
Install all AI provider plugins.
Set API keys for every supported provider.
Remove the key and set it again for every supported provider.
When a incorrect API key is provided then it isn't possible to save it.
API keys are properly masked on the frontend (including REST API response).
Deactivate the AI provider plugin from the Plugins screen and activate the plugin again from the Connectors screen.
Uninstall the AI provider plugin from the Plugins screen and install the plugin again from the Connectors screen.
Revoke a key that was valid on the provider website and veify the screen does not says connected anymore.

Change History (20)

This ticket was mentioned in โ€‹PR #11056 on โ€‹WordPress/wordpress-develop by โ€‹@jorgefilipecosta.


4 weeks ago
#1

  • Keywords has-unit-tests added

Trac ticket: https://core.trac.wordpress.org/ticket/64730
## Summary

  • Backport the PHP integration pieces from Gutenberg PR โ€‹https://github.com/WordPress/gutenberg/pull/75833.
  • Register the Settings > Connectors submenu (options-general.php?page=connectors-wp-admin).
  • Register default connector settings for:
    • connectors_openai_api_key
    • connectors_anthropic_api_key
    • connectors_gemini_api_key
  • Add API key masking and server-side validation wiring for settings reads/writes.
  • Expose invalid_key in /wp/v2/settings responses for requested connector fields when validation fails.
  • Pass stored connector keys into the WP AI client provider registry on init.

## Notes

  • JS/TS/runtime artifacts for Connectors will be included on the Gutenberg sync; this PR covers the missing PHP glue.
  • Includes guard checks so behavior is a no-op when the AI client (or Connectors render callback) is unavailable.

## Testing Instructions
Visit wp-admin/options-general.php?page=connectors-wp-admin and verify the Connectors page appears under Settings.
Verify Connectors appears between General and Writing in the Settings submenu.
Install all AI provider plugins.
Set API keys for every supported provider.
Remove the key and set it again for every supported provider.
When a incorrect API key is provided then it isn't possible to save it.
API keys are properly masked on the frontend (including REST API response).
Deactivate the AI provider plugin from the Plugins screen and activate the plugin again from the Connectors screen.
Uninstall the AI provider plugin from the Plugins screen and install the plugin again from the Connectors screen.
Revoke a key that was valid on the provider website and veify the screen does not says connected anymore.

โ€‹@gziolo commented on โ€‹PR #11056:


4 weeks ago
#2

I need to re-test the branch after all the refactoring applied based on the feedback provided, but it looks like we are good to go if it still works as expected ๐Ÿ˜…

โ€‹@mukesh27 commented on โ€‹PR #11056:


4 weeks ago
#3

I need to re-test the branch after all the refactoring applied based on the feedback provided, but it looks like we are good to go if it still works as expected ๐Ÿ˜…

Go for it.

โ€‹@gziolo commented on โ€‹PR #11056:


4 weeks ago
#4

@felixarntz and @JasonTheAdams, I added some basic testing coverage so we can iterate on the codebase with more confidence. The part with test trait for the AI provider (โ€‹https://github.com/WordPress/wordpress-develop/pull/11056/commits/4c380a96775f5e362fea4ecb20083ea9886bbe46) was modeled after tests for WP AI Client. I would appreciate a sanity check in case you discover some obvious mistakes or immediate room for improvement. I will take care of it in follow up commit, as I don't consider non-production code a blocker.

#5 @jorgefilipecosta
4 weeks ago

  • Owner set to jorgefilipecosta
  • Resolution set to fixed
  • Status changed from new to closed

In 61749:

Connectors: Backport Gutenberg connectors screen.

Adds wp-includes/connectors.php (loaded from wp-settings.php) and registers
a Settings > Connectors submenu when the AI client and Connectors admin page
renderer are available.
Registers connector API key settings in /wp/v2/settings, masks key values on
option reads, validates keys against provider configuration, and returns
invalid_key for explicitly requested connector fields when validation fails.
Stored connector keys are also passed to the AI client registry on init.

Gutenberg PR at โ€‹https://github.com/WordPress/gutenberg/pull/75833.
Developed in โ€‹https://github.com/WordPress/wordpress-develop/pull/11056.

Props jorgefilipecosta, gziolo, flixos90, justlevine, westonruter, jeffpaul, JasonTheAdams, audrasjb, shaunandrews, noruzzaman, mukesh27.
Fixes #64730.

This ticket was mentioned in โ€‹PR #11080 on โ€‹WordPress/wordpress-develop by โ€‹@gziolo.


4 weeks ago
#6

## Summary

  • Expand _wp_connectors_get_provider_settings() to dynamically fetch registered providers from the AI Client registry, in addition to the three hardcoded featured providers (Gemini, OpenAI, Claude).
  • Restructure the return value to be keyed by provider ID with name, description, credentials_url at the top level and settings as a nested array.
  • Filter out providers whose authentication method is not api_key.
  • Update all consumer functions (_wp_connectors_validate_keys_in_rest, _wp_register_default_connector_settings, _wp_connectors_pass_default_keys_to_ai_client) to use the new structure.
  • Update and expand unit tests to cover dynamically registered providers using the mock provider trait.

## Test plan

  • [ ] Verify npm run test:php -- --group connectors passes (14 tests, 64 assertions).
  • [ ] Confirm the three featured providers (google, openai, anthropic) still appear with correct names, descriptions, and credentials URLs.
  • [ ] Confirm a third-party provider plugin registered via AiClient::defaultRegistry()->registerProvider() with API key auth appears in the settings.
  • [ ] Confirm providers without API key authentication are excluded from the settings.

๐Ÿค– Generated with โ€‹Claude Code

โ€‹@gziolo commented on โ€‹PR #11080:


4 weeks ago
#7

@felixarntz, there are still some things to address, but it's close to ready to include all basic metadata that we could expose to the client to automatically expose their cards for registered plugins that implement AI providers.

We would always show 3 featured AI providers by default, but their metadata would be replaced as soon as the corresponding plugin gets installed. For all other AI providers, they would show up on the Connectors screen only after they get installed, solely based on the metadata used during registration.

#8 @gziolo
4 weeks ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

โ€‹@gziolo commented on โ€‹PR #11080:


4 weeks ago
#9

I synced changes from โ€‹https://github.com/WordPress/gutenberg/pull/76014 based on the feedback provided there.

โ€‹@gziolo commented on โ€‹PR #11080:


4 weeks ago
#12

@jorgefilipecosta, I synced all the changes from the Gutenberg plugin merged with โ€‹https://github.com/WordPress/gutenberg/pull/76014, and addressed all your feedback.

โ€‹@gziolo commented on โ€‹PR #11080:


4 weeks ago
#13

@ellatrix, would it be possible to sync Gutenberg plugin changes (3763f32faee3ede110074e6539b9be970d1f4983) as part of this PR? They are necessary so these changes continue to work.

โ€‹@ellatrix commented on โ€‹PR #11080:


4 weeks ago
#14

Yes, but if you can, I'd do an update up until (and excluding) the commit you need that includes a log of all changes that were made in Gutenberg. Then you could update the sha as part of this PR that just bumps it by one commit. We currently don't have a good process for this because it's all new. How would we have done it for packages? Cc @desrosj because I know you really like to have the changelog in the commit message.

โ€‹@justlevine commented on โ€‹PR #11080:


3 weeks ago
#15

@jorgefilipecosta, I synced all the changes from the Gutenberg plugin merged with โ€‹WordPress/gutenberg#76014, and addressed all your feedback.

https://private-user-images.githubusercontent.com/699132/557486825-fa507b8e-acb5-4a41-87cb-a452e8c77a83.png

@gziolo @jorgefilipecosta I'm catching up - did the rest of the feedback from the initial โ€‹https://github.com/WordPress/gutenberg/pull/75833 make it in too?

Particularly on my mind is the unencrypted API key storage.

โ€‹@gziolo commented on โ€‹PR #11080:


3 weeks ago
#16

Particularly on my mind is the unencrypted API key storage.

It's now tracked in https://core.trac.wordpress.org/ticket/64789 with the list of proposed actions to keep the discussion going.

#17 @gziolo
3 weeks ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 61824:

Connectors: Dynamically register providers from WP AI Client registry.

Replaces _wp_connectors_get_provider_settings() with
_wp_connectors_get_connector_settings() that returns a richer structure keyed
by connector ID, including name, description, type, plugin slug, and an
authentication sub-object (method, credentials_url, setting_name).

The new function merges hardcoded defaults for featured providers (Anthropic,
Google, OpenAI) with metadata from the WP AI Client registry, allowing
dynamically registered providers to appear alongside built-in ones. Providers
are sorted alphabetically with ksort().

Additionally:

  • Renames _wp_connectors_is_api_key_valid() to _wp_connectors_is_ai_api_key_valid().
  • Adds _wp_connectors_get_connector_script_module_data() to expose connector settings to the connectors-wp-admin script module.
  • Includes plugin slug data for featured connectors to support install/activate UI.
  • Removes redundant class_exists checks for AiClient.
  • Runs init hooks at priority 20 so provider plugins registered at default priority are available.
  • Unhooks connector registration during tests to prevent duplicate registrations.

Synced from โ€‹https://github.com/WordPress/gutenberg/pull/76014.
Developed in โ€‹https://github.com/WordPress/wordpress-develop/pull/11080.

Follow-up to [61749].

Props gziolo, jorgefilipecosta, justlevine, flixos90, ellatrix.
Fixes #64730.

This ticket was mentioned in โ€‹PR #11157 on โ€‹WordPress/wordpress-develop by โ€‹@jorgefilipecosta.


3 weeks ago
#18

Follow-up for โ€‹https://github.com/WordPress/wordpress-develop/pull/11056.
Synced from โ€‹https://github.com/WordPress/gutenberg/pull/76142.

## Summary

Changes the Connectors screen URL from a query parameter page to a direct file, following the Settings menu naming convention used by other settings pages (options-general.php, options-writing.php, etc.).

Before: /wp-admin/admin.php?page=connectors-wp-admin
After: /wp-admin/options-connectors.php

## Changes

  • Add src/wp-admin/options-connectors.php direct admin file
  • Add submenu entry in menu.php at position 1 (after General)
  • Update script_module_data filter to options-connectors-wp-admin

## Test plan

  • [ ] Navigate to Settings > Connectors
  • [ ] Verify URL is options-connectors.php
  • [ ] Verify connector cards appear (Anthropic, Google, OpenAI)
  • [ ] Verify API key management works correctly

#19 @gziolo
3 weeks ago

In 61825:

Connectors: Change admin URL to options-connectors.php.

Changes the Connectors screen URL from a query parameter page to a direct file, following the Settings menu naming convention used by other settings pages (options-general.php, options-writing.php, etc.).

  • Adds src/wp-admin/options-connectors.php as a direct admin screen file.
  • Adds a static submenu entry in menu.php at position 12 (after General).
  • Removes _wp_connectors_add_settings_menu_item() and its admin_menu hook from connectors.php.
  • Updates the script_module_data filter from connectors-wp-admin to options-connectors-wp-admin.

Synced from โ€‹https://github.com/WordPress/gutenberg/pull/76142.
Developed in โ€‹https://github.com/WordPress/wordpress-develop/pull/11157.

Follow-up to [61749], [61824].
See #64730.

Props jorgefilipecosta, gziolo.
Fixes #64790.

#20 @amykamala
11 days ago

  • Keywords needs-dev-note added
Note: See TracTickets for help on using tickets.