Skip to content

Commit 4910777

Browse files
authored
Merge branch 'WordPress:trunk' into trunk
2 parents a1aa783 + b5ba245 commit 4910777

8 files changed

Lines changed: 1196 additions & 66 deletions

src/wp-includes/class-wp-connector-registry.php

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* logo_url?: non-empty-string,
3434
* type: non-empty-string,
3535
* authentication: array{
36-
* method: 'api_key'|'none',
36+
* method: 'api_key'|'application_password'|'none',
3737
* credentials_url?: non-empty-string,
3838
* setting_name?: non-empty-string,
3939
* constant_name?: non-empty-string,
@@ -69,12 +69,11 @@ final class WP_Connector_Registry {
6969
* Registers a new connector.
7070
*
7171
* Validates the provided arguments and stores the connector in the registry.
72-
* For connectors with `api_key` authentication, a `setting_name` can be provided
73-
* explicitly. If omitted, one is automatically generated using the pattern
74-
* `connectors_{$type}_{$id}_api_key`, with hyphens in the type and ID normalized
75-
* to underscores (e.g., connector type `spam_filtering` with ID `my_plugin` produces
76-
* `connectors_spam_filtering_my_plugin_api_key`). This setting name is used for the
77-
* Settings API registration and REST API exposure.
72+
* For connectors with `api_key` or `application_password` authentication, a
73+
* `setting_name` can be provided explicitly. When omitted, setting names are
74+
* automatically generated using the pattern `connectors_{$type}_{$id}_{$method}`,
75+
* with hyphens in the type and ID normalized to underscores. These setting
76+
* names are used for Settings API registration and REST API exposure.
7877
*
7978
* Registering a connector with an ID that is already registered will trigger a
8079
* `_doing_it_wrong()` notice and return `null`. To override an existing connector,
@@ -96,16 +95,24 @@ final class WP_Connector_Registry {
9695
* @type array $authentication {
9796
* Required. Authentication configuration.
9897
*
99-
* @type string $method Required. The authentication method: 'api_key' or 'none'.
98+
* @type string $method Required. The authentication method: 'api_key',
99+
* 'application_password', or 'none'.
100100
* @type string $credentials_url Optional. URL where users can obtain API credentials.
101-
* @type string $setting_name Optional. The setting name for the API key.
102-
* When omitted, auto-generated as
103-
* `connectors_{$type}_{$id}_api_key`.
101+
* @type string $setting_name Optional. The setting name for the API key
102+
* or application-password credentials. When
103+
* omitted, auto-generated as
104+
* `connectors_{$type}_{$id}_api_key` for API
105+
* keys and `connectors_{$type}_{$id}_application_password`
106+
* for application passwords.
104107
* Must be a non-empty string when provided.
105108
* @type string $constant_name Optional. PHP constant name for the API key
106-
* (e.g. 'ANTHROPIC_API_KEY'). Only checked when provided.
109+
* (e.g. 'ANTHROPIC_API_KEY') or for application-password
110+
* credentials in `username:password` format. Only checked
111+
* when provided.
107112
* @type string $env_var_name Optional. Environment variable name for the API key
108-
* (e.g. 'ANTHROPIC_API_KEY'). Only checked when provided.
113+
* (e.g. 'ANTHROPIC_API_KEY') or for application-password
114+
* credentials in `username:password` format. Only checked
115+
* when provided.
109116
* }
110117
* @type array $plugin {
111118
* Optional. Plugin data for install/activate UI.
@@ -126,7 +133,7 @@ final class WP_Connector_Registry {
126133
* logo_url?: non-empty-string,
127134
* type: non-empty-string,
128135
* authentication: array{
129-
* method: 'api_key'|'none',
136+
* method: 'api_key'|'application_password'|'none',
130137
* credentials_url?: non-empty-string,
131138
* setting_name?: non-empty-string,
132139
* constant_name?: non-empty-string,
@@ -192,11 +199,11 @@ public function register( string $id, array $args ): ?array {
192199
return null;
193200
}
194201

195-
if ( empty( $args['authentication']['method'] ) || ! in_array( $args['authentication']['method'], array( 'api_key', 'none' ), true ) ) {
202+
if ( empty( $args['authentication']['method'] ) || ! in_array( $args['authentication']['method'], array( 'api_key', 'application_password', 'none' ), true ) ) {
196203
_doing_it_wrong(
197204
__METHOD__,
198205
/* translators: %s: Connector ID. */
199-
sprintf( __( 'Connector "%s" authentication method must be "api_key" or "none".' ), esc_html( $id ) ),
206+
sprintf( __( 'Connector "%s" authentication method must be "api_key", "application_password", or "none".' ), esc_html( $id ) ),
200207
'7.0.0'
201208
);
202209
return null;
@@ -220,10 +227,13 @@ public function register( string $id, array $args ): ?array {
220227
$connector['logo_url'] = $args['logo_url'];
221228
}
222229

223-
if ( 'api_key' === $args['authentication']['method'] ) {
230+
$requires_credentials = in_array( $args['authentication']['method'], array( 'api_key', 'application_password' ), true );
231+
232+
if ( $requires_credentials ) {
224233
if ( ! empty( $args['authentication']['credentials_url'] ) && is_string( $args['authentication']['credentials_url'] ) ) {
225234
$connector['authentication']['credentials_url'] = $args['authentication']['credentials_url'];
226235
}
236+
227237
if ( isset( $args['authentication']['setting_name'] ) ) {
228238
if ( ! is_string( $args['authentication']['setting_name'] ) || '' === $args['authentication']['setting_name'] ) {
229239
_doing_it_wrong(
@@ -236,8 +246,9 @@ public function register( string $id, array $args ): ?array {
236246
}
237247
$connector['authentication']['setting_name'] = $args['authentication']['setting_name'];
238248
} else {
239-
$connector['authentication']['setting_name'] = str_replace( '-', '_', "connectors_{$connector['type']}_{$id}_api_key" );
249+
$connector['authentication']['setting_name'] = str_replace( '-', '_', "connectors_{$connector['type']}_{$id}_{$args['authentication']['method']}" );
240250
}
251+
241252
if ( isset( $args['authentication']['constant_name'] ) ) {
242253
if ( ! is_string( $args['authentication']['constant_name'] ) || '' === $args['authentication']['constant_name'] ) {
243254
_doing_it_wrong(

0 commit comments

Comments
 (0)