wppaste
WordPress

WP_Connector_Registry

Since
7.0.0
Source
wp-includes/class-wp-connector-registry.php:48
Manages the registration and lookup of connectors.

Description

This is an internal class. Use the public API functions to interact with connectors:

  • wp_is_connector_registered() — check if a connector exists.
  • wp_get_connector() — retrieve a single connector's data.
  • wp_get_connectors() — retrieve all registered connectors.

Plugins receive the registry instance via the wp_connectors_init action to register or override connectors directly.

Compatibility

WordPress
since 7.0.0
  • 6.7.10
  • 6.8.11
  • 6.9.10
  • 7.0.7
  • 7.1.3

Present in 2 of the 5 tracked releases, added in 7.0.0.

Properties · 2

$instanceprivate static
The singleton instance of the registry.
$registered_connectorsarray<string,private
Holds the registered connectors.

Methods · 7

Source code

final class WP_Connector_Registry {	/**	 * The singleton instance of the registry.	 *	 * @since 7.0.0	 */	private static ?WP_Connector_Registry $instance = null; 	/**	 * Holds the registered connectors.	 *	 * Each connector is stored as an associative array with keys:	 * name, description, type, authentication, and optionally plugin.	 *	 * @since 7.0.0	 * @var array<string, array>	 * @phpstan-var array<string, Connector>	 */	private array $registered_connectors = array(); 	/**	 * Registers a new connector.	 *	 * Validates the provided arguments and stores the connector in the registry.	 * For connectors with `api_key` authentication, a `setting_name` can be provided	 * explicitly. If omitted, one is automatically generated using the pattern	 * `connectors_{$type}_{$id}_api_key`, with hyphens in the type and ID normalized	 * to underscores (e.g., connector type `spam_filtering` with ID `my_plugin` produces	 * `connectors_spam_filtering_my_plugin_api_key`). This setting name is used for the	 * Settings API registration and REST API exposure.	 *	 * Registering a connector with an ID that is already registered will trigger a	 * `_doing_it_wrong()` notice and return `null`. To override an existing connector,	 * call `unregister()` first.	 *	 * @since 7.0.0	 *	 * @see WP_Connector_Registry::unregister()	 *	 * @param string $id   The unique connector identifier. Must match the pattern	 *                     `/^[a-z0-9_-]+$/` (lowercase alphanumeric, hyphens, and underscores only).	 * @param array  $args {	 *     An associative array of arguments for the connector.	 *	 *     @type string $name           Required. The connector's display name.	 *     @type string $description    Optional. The connector's description. Default empty string.	 *     @type string $logo_url       Optional. URL to the connector's logo image.	 *     @type string $type           Required. The connector type, e.g. 'ai_provider'.	 *     @type array  $authentication {	 *         Required. Authentication configuration.	 *	 *         @type string $method          Required. The authentication method: 'api_key' or 'none'.	 *         @type string $credentials_url Optional. URL where users can obtain API credentials.	 *         @type string $setting_name    Optional. The setting name for the API key.	 *                                       When omitted, auto-generated as	 *                                       `connectors_{$type}_{$id}_api_key`.	 *                                       Must be a non-empty string when provided.	 *         @type string $constant_name   Optional. PHP constant name for the API key	 *                                       (e.g. 'ANTHROPIC_API_KEY'). Only checked when provided.	 *         @type string $env_var_name    Optional. Environment variable name for the API key	 *                                       (e.g. 'ANTHROPIC_API_KEY'). Only checked when provided.	 *     }	 *     @type array  $plugin         {	 *         Optional. Plugin data for install/activate UI.	 *	 *         @type string   $file      Optional. The plugin's main file path relative to the	 *                                   plugins directory (e.g. 'my-plugin/my-plugin.php' or	 *                                   'hello.php').	 *         @type callable $is_active Optional callback to determine whether the plugin	 *                                   is active. Receives no arguments and must return bool.	 *                                   Defaults to `__return_true`.	 *     }	 * }	 * @return array|null The registered connector data on success, null on failure.	 *	 * @phpstan-param array{	 *     name: non-empty-string,	 *     description?: string,	 *     logo_url?: non-empty-string,	 *     type: non-empty-string,

Changelog

Introduced in 7.0.0. Unchanged from 7.0.7 through 7.1.3.

  1. 7.0.7
  2. 7.1.3

Signature, return type and hooks compared across 2 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.7 tag, from src/wp-includes/class-wp-connector-registry.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.