Make WordPress Core


Ignore:
Timestamp:
03/16/2026 08:18:21 AM (8 months ago)
Author:
gziolo
Message:

Connectors: Improve inline documentation for the Connectors API

Adds comprehensive PHPDoc to connectors.php and class-wp-connector-registry.php covering API overview, AI provider auto-discovery, admin UI integration, initialization lifecycle, authentication, usage examples, cross-references, and metadata override patterns.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/11244.

Follow-up to [61943].

See #64791.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-connector-registry.php

    r61983 r62032  
    11<?php
    22/**
    3  * Connectors API
    4  *
    5  * Defines WP_Connector_Registry class.
     3 * Connectors API: WP_Connector_Registry class.
    64 *
    75 * @package WordPress
    … …  
    1311 * Manages the registration and lookup of connectors.
    1412 *
     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 *
    1522 * @since 7.0.0
    1623 * @access private
     24 *
     25 * @see wp_is_connector_registered()
     26 * @see wp_get_connector()
     27 * @see wp_get_connectors()
     28 * @see _wp_connectors_init()
    1729 *
    1830 * @phpstan-type Connector array{
    … …  
    5466         * Registers a new connector.
    5567         *
    56          * @since 7.0.0
    57          *
    58          * @param string $id   The unique connector identifier. Must contain only lowercase
    59          *                     alphanumeric characters and underscores.
     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         *
     78         * @since 7.0.0
     79         *
     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).
    6084         * @param array  $args {
    6185         *     An associative array of arguments for the connector.
    … …  
    176200         * Unregisters a connector.
    177201         *
    178          * @since 7.0.0
     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         *
     208         * @since 7.0.0
     209         *
     210         * @see WP_Connector_Registry::register()
     211         * @see WP_Connector_Registry::is_registered()
    179212         *
    180213         * @param string $id The connector identifier.
    … …  
    237270         *
    238271         * Do not use this method directly. Instead, use the `wp_get_connector()` function.
     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.
    239275         *
    240276         * @since 7.0.0
    … …  
    273309         * Sets the main instance of the registry class.
    274310         *
     311         * Called by `_wp_connectors_init()` during the `init` action. Must not be
     312         * called outside of that context.
     313         *
    275314         * @since 7.0.0
    276315         * @access private
     316         *
     317         * @see _wp_connectors_init()
    277318         *
    278319         * @param WP_Connector_Registry $registry The registry instance.
Note: See TracChangeset for help on using the changeset viewer.