Make WordPress Core


Ignore:
Timestamp:
03/12/2026 07:54:50 AM (7 months ago)
Author:
gziolo
Message:

Connectors: Remove redundant helper and improve PHPDoc

Remove _wp_connectors_get_connector_settings() and inline ksort()
into _wp_connectors_get_connector_script_module_data(). Expand
@return and @phpstan-return array shapes for wp_get_connector()
and wp_get_connectors(). Make logo_url and credentials_url truly
optional. Rename test class to wpGetConnectors.

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

Follow-up to [61943].

Props gziolo, westonruter.
Fixes #64791.

File:
1 edited

Legend:

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

    r61943 r61983  
    1717 *
    1818 * @phpstan-type Connector array{
    19  *     name: string,
    20  *     description: string,
    21  *     logo_url?: string|null,
    22  *     type: string,
     19 *     name: non-empty-string,
     20 *     description: non-empty-string,
     21 *     logo_url?: non-empty-string,
     22 *     type: 'ai_provider',
    2323 *     authentication: array{
    24  *         method: string,
    25  *         credentials_url?: string|null,
    26  *         setting_name?: string
     24 *         method: 'api_key'|'none',
     25 *         credentials_url?: non-empty-string,
     26 *         setting_name?: non-empty-string
    2727 *     },
    2828 *     plugin?: array{
    29  *         slug: string
     29 *         slug: non-empty-string
    3030 *     }
    3131 * }
    … …  
    6363         *     @type string $name           Required. The connector's display name.
    6464         *     @type string $description    Optional. The connector's description. Default empty string.
    65          *     @type string|null $logo_url  Optional. URL to the connector's logo image. Default null.
     65         *     @type string $logo_url       Optional. URL to the connector's logo image.
    6666         *     @type string $type           Required. The connector type. Currently, only 'ai_provider' is supported.
    6767         *     @type array  $authentication {
    6868         *         Required. Authentication configuration.
    6969         *
    70          *         @type string      $method          Required. The authentication method: 'api_key' or 'none'.
    71          *         @type string|null $credentials_url Optional. URL where users can obtain API credentials.
     70         *         @type string $method          Required. The authentication method: 'api_key' or 'none'.
     71         *         @type string $credentials_url Optional. URL where users can obtain API credentials.
    7272         *     }
    73          *     @type array  $plugin {
     73         *     @type array  $plugin         {
    7474         *         Optional. Plugin data for install/activate UI.
    7575         *
    … …  
    159159
    160160                if ( 'api_key' === $args['authentication']['method'] ) {
    161                         $connector['authentication']['credentials_url'] = $args['authentication']['credentials_url'] ?? null;
    162                         $connector['authentication']['setting_name']    = "connectors_ai_{$id}_api_key";
     161                        if ( ! empty( $args['authentication']['credentials_url'] ) && is_string( $args['authentication']['credentials_url'] ) ) {
     162                                $connector['authentication']['credentials_url'] = $args['authentication']['credentials_url'];
     163                        }
     164                        $connector['authentication']['setting_name'] = "connectors_ai_{$id}_api_key";
    163165                }
    164166
    … …  
    207209         * @see wp_get_connectors()
    208210         *
    209          * @return array<string, array> The array of registered connectors keyed by connector ID.
     211         * @return array Connector settings keyed by connector ID.
     212         *
    210213         * @phpstan-return array<string, Connector>
    211214         */
Note: See TracChangeset for help on using the changeset viewer.