|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * Connectors API |
4 | | - * |
5 | | - * Defines WP_Connector_Registry class. |
| 3 | + * Connectors API: WP_Connector_Registry class. |
6 | 4 | * |
7 | 5 | * @package WordPress |
8 | 6 | * @subpackage Connectors |
|
12 | 10 | /** |
13 | 11 | * Manages the registration and lookup of connectors. |
14 | 12 | * |
| 13 | + * This is an internal class. Use the public API functions to interact with connectors: |
| 14 | + * |
| 15 | + * - `wp_is_connector_registered()` — check if a connector exists. |
| 16 | + * - `wp_get_connector()` — retrieve a single connector's data. |
| 17 | + * - `wp_get_connectors()` — retrieve all registered connectors. |
| 18 | + * |
| 19 | + * Plugins receive the registry instance via the `wp_connectors_init` action |
| 20 | + * to register or override connectors directly. |
| 21 | + * |
15 | 22 | * @since 7.0.0 |
16 | 23 | * @access private |
17 | 24 | * |
| 25 | + * @see wp_is_connector_registered() |
| 26 | + * @see wp_get_connector() |
| 27 | + * @see wp_get_connectors() |
| 28 | + * @see _wp_connectors_init() |
| 29 | + * |
18 | 30 | * @phpstan-type Connector array{ |
19 | 31 | * name: non-empty-string, |
20 | 32 | * description: non-empty-string, |
@@ -53,10 +65,22 @@ final class WP_Connector_Registry { |
53 | 65 | /** |
54 | 66 | * Registers a new connector. |
55 | 67 | * |
| 68 | + * Validates the provided arguments and stores the connector in the registry. |
| 69 | + * For connectors with `api_key` authentication, a `setting_name` is automatically |
| 70 | + * generated using the pattern `connectors_ai_{$id}_api_key` (e.g., connector ID |
| 71 | + * `openai` produces `connectors_ai_openai_api_key`). This setting name is used |
| 72 | + * for the Settings API registration and REST API exposure. |
| 73 | + * |
| 74 | + * Registering a connector with an ID that is already registered will trigger a |
| 75 | + * `_doing_it_wrong()` notice and return `null`. To override an existing connector, |
| 76 | + * call `unregister()` first. |
| 77 | + * |
56 | 78 | * @since 7.0.0 |
57 | 79 | * |
58 | | - * @param string $id The unique connector identifier. Must contain only lowercase |
59 | | - * alphanumeric characters and underscores. |
| 80 | + * @see WP_Connector_Registry::unregister() |
| 81 | + * |
| 82 | + * @param string $id The unique connector identifier. Must match the pattern |
| 83 | + * `/^[a-z0-9_]+$/` (lowercase alphanumeric and underscores only). |
60 | 84 | * @param array $args { |
61 | 85 | * An associative array of arguments for the connector. |
62 | 86 | * |
@@ -175,8 +199,17 @@ public function register( string $id, array $args ): ?array { |
175 | 199 | /** |
176 | 200 | * Unregisters a connector. |
177 | 201 | * |
| 202 | + * Returns the connector data on success, which can be modified and passed |
| 203 | + * back to `register()` to override a connector's metadata. |
| 204 | + * |
| 205 | + * Triggers a `_doing_it_wrong()` notice if the connector is not registered. |
| 206 | + * Use `is_registered()` to check first when the connector may not exist. |
| 207 | + * |
178 | 208 | * @since 7.0.0 |
179 | 209 | * |
| 210 | + * @see WP_Connector_Registry::register() |
| 211 | + * @see WP_Connector_Registry::is_registered() |
| 212 | + * |
180 | 213 | * @param string $id The connector identifier. |
181 | 214 | * @return array|null The unregistered connector data on success, null on failure. |
182 | 215 | * |
@@ -237,6 +270,9 @@ public function is_registered( string $id ): bool { |
237 | 270 | * |
238 | 271 | * Do not use this method directly. Instead, use the `wp_get_connector()` function. |
239 | 272 | * |
| 273 | + * Triggers a `_doing_it_wrong()` notice if the connector is not registered. |
| 274 | + * Use `is_registered()` to check first when the connector may not exist. |
| 275 | + * |
240 | 276 | * @since 7.0.0 |
241 | 277 | * |
242 | 278 | * @see wp_get_connector() |
@@ -272,9 +308,14 @@ public static function get_instance(): ?self { |
272 | 308 | /** |
273 | 309 | * Sets the main instance of the registry class. |
274 | 310 | * |
| 311 | + * Called by `_wp_connectors_init()` during the `init` action. Must not be |
| 312 | + * called outside of that context. |
| 313 | + * |
275 | 314 | * @since 7.0.0 |
276 | 315 | * @access private |
277 | 316 | * |
| 317 | + * @see _wp_connectors_init() |
| 318 | + * |
278 | 319 | * @param WP_Connector_Registry $registry The registry instance. |
279 | 320 | */ |
280 | 321 | public static function set_instance( WP_Connector_Registry $registry ): void { |
|
0 commit comments