[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> connectors.php (summary)

Connectors API.

File Size: 965 lines (33 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 1 file
 wp-admin/includes/plugin.php

Defines 16 functions

  wp_is_connector_registered()
  wp_get_connector()
  wp_get_connectors()
  _wp_connectors_resolve_ai_provider_logo_url()
  _wp_connectors_init()
  _wp_connectors_register_default_ai_providers()
  _wp_connectors_mask_api_key()
  _wp_connectors_get_api_key_source()
  wp_connectors_parse_application_password_credentials()
  wp_connectors_get_application_password_credentials()
  _wp_connectors_is_ai_api_key_valid()
  wp_connectors_sanitize_application_password_credentials()
  _wp_connectors_rest_settings_dispatch()
  _wp_register_default_connector_settings()
  _wp_connectors_pass_default_keys_to_ai_client()
  _wp_connectors_get_connector_script_module_data()

Functions
Functions that are not part of a class:

wp_is_connector_registered( string $id )   X-Ref
Checks if a connector is registered.

param: string $id The connector identifier.
return: bool True if the connector is registered, false otherwise.

wp_get_connector( string $id )   X-Ref
Retrieves a registered connector.

param: string $id The connector identifier.
return: array|null {

wp_get_connectors()   X-Ref
Retrieves all registered connectors.

return: array {

_wp_connectors_resolve_ai_provider_logo_url( string $path )   X-Ref
Resolves an AI provider logo file path to a URL.

Converts an absolute file path to a plugin URL. The path must reside within
the plugins or must-use plugins directory.

param: string $path Absolute path to the logo file.
return: non-empty-string|null The URL to the logo file, or null if the path is invalid.

_wp_connectors_init()   X-Ref
Initializes the connector registry with default connectors and fires the registration action.

Creates the registry instance, registers built-in connectors (which cannot be unhooked),
and then fires the `wp_connectors_init` action for plugins to register their own connectors.


_wp_connectors_register_default_ai_providers( WP_Connector_Registry $registry )   X-Ref
Registers connectors for the built-in AI providers.

param: WP_Connector_Registry $registry The connector registry instance.

_wp_connectors_mask_api_key( string $key )   X-Ref
Masks an API key, showing only the last 4 characters.

param: string $key The API key to mask.
return: string The masked key, e.g. "************fj39".

_wp_connectors_get_api_key_source( string $setting_name, string $env_var_name = '', string $constant_name = '' )   X-Ref
Determines the source of an API key for a given connector.

Checks in order: environment variable, PHP constant, database.
Environment variable and constant are only checked when their
respective names are provided.

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'.

wp_connectors_parse_application_password_credentials( string $value )   X-Ref
Parses a `username:password` credentials string.

Splits on the first colon, matching the HTTP Basic authentication
userinfo format, so passwords may contain colons.

param: string $value The raw credentials string.
return: array{username: string, password: string} Parsed credentials. Both values

wp_connectors_get_application_password_credentials( array $auth )   X-Ref
Resolves application-password credentials for a connector.

Checks in order: environment variable, PHP constant, database. The
environment variable and constant are only checked when their respective
names are provided, and must contain the credentials as a single
`username:password` string. A non-empty environment variable or constant
that cannot be parsed as `username:password` is reported with
`_doing_it_wrong()` and ignored, so resolution falls through to the next
source.

param: array $auth The connector's authentication configuration.
return: array{username: string, password: string, source: string} Resolved credentials and

_wp_connectors_is_ai_api_key_valid( string $key, string $provider_id )   X-Ref
Checks whether an API key is valid for a given provider.

param: string $key         The API key to check.
param: string $provider_id The WP AI client provider ID.
return: bool|null True if valid, false if invalid, null if unable to determine.

wp_connectors_sanitize_application_password_credentials( $value, string $option = '' )   X-Ref
Sanitizes stored application-password credentials for a connector.

Credential fields that are missing or not strings keep their currently
stored values, so partial updates cannot silently clear a stored secret.
A password matching the mask that `_wp_connectors_rest_settings_dispatch()`
places in REST responses also keeps the stored password, so a masked
settings response can be submitted back to the endpoint unchanged.
Pass an empty string to clear a field.
If the sanitized username is empty, both fields are discarded so partial
credentials cannot leave an orphaned secret.

param: mixed  $value  The submitted setting value.
param: string $option The option name being sanitized. Passed explicitly by the
return: array{username: string, password: string} Sanitized credentials.

_wp_connectors_rest_settings_dispatch( WP_REST_Response $response, WP_REST_Server $server, WP_REST_Request $request )   X-Ref
Masks and validates connector credentials in REST responses.

On every `/wp/v2/settings` response, masks connector API key values and the
password field of default application-password credential objects.

On POST or PUT requests, validates each updated AI provider API key before
masking. If validation fails, the key is reverted to an empty string.
Application password values are masked but not validated.

param: WP_REST_Response $response The response object.
param: WP_REST_Server   $server   The server instance.
param: WP_REST_Request  $request  The request object.
return: WP_REST_Response The modified response with masked/validated keys.

_wp_register_default_connector_settings()   X-Ref
Registers default connector settings.


_wp_connectors_pass_default_keys_to_ai_client()   X-Ref
Passes stored connector API keys to the WP AI client.


_wp_connectors_get_connector_script_module_data( array $data )   X-Ref
Exposes connector settings to the connectors-wp-admin script module.

param: array<string, mixed> $data Existing script module data.
return: array<string, mixed> Script module data with connectors added.



Generated : Thu Jul 23 08:20:17 2026 Cross-referenced by PHPXref