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.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

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` or `application_password` authentication, a	 * `setting_name` can be provided explicitly. When omitted, setting names are	 * automatically generated using the pattern `connectors_{$type}_{$id}_{$method}`,	 * with hyphens in the type and ID normalized to underscores. These setting	 * names are used for 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',	 *                                       'application_password', 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	 *                                       or application-password credentials. When	 *                                       omitted, auto-generated as	 *                                       `connectors_{$type}_{$id}_api_key` for API	 *                                       keys and `connectors_{$type}_{$id}_application_password`	 *                                       for application passwords.	 *                                       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') or for application-password	 *                                       credentials in `username:password` format. Only checked	 *                                       when provided.	 *         @type string $env_var_name    Optional. Environment variable name for the API key	 *                                       (e.g. 'ANTHROPIC_API_KEY') or for application-password	 *                                       credentials in `username:password` format. 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`.	 *     }	 * }

Changelog

Introduced in 7.0.0. Unchanged from 7.0.4 through 7.1.0.

  1. 7.0.4
  2. 7.1.0

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

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 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.