@@ -37,7 +37,41 @@ function wp_is_connector_registered( string $id ): bool {
3737 * @see WP_Connector_Registry::get_registered()
3838 *
3939 * @param string $id The connector identifier.
40- * @return array|null The registered connector data, or null if not registered.
40+ * @return array|null {
41+ * Connector data, or null if not registered.
42+ *
43+ * @type string $name The connector's display name.
44+ * @type string $description The connector's description.
45+ * @type string $logo_url Optional. URL to the connector's logo image.
46+ * @type string $type The connector type. Currently, only 'ai_provider' is supported.
47+ * @type array $authentication {
48+ * Authentication configuration. When method is 'api_key', includes
49+ * credentials_url and setting_name. When 'none', only method is present.
50+ *
51+ * @type string $method The authentication method: 'api_key' or 'none'.
52+ * @type string $credentials_url Optional. URL where users can obtain API credentials.
53+ * @type string $setting_name Optional. The setting name for the API key.
54+ * }
55+ * @type array $plugin {
56+ * Optional. Plugin data for install/activate UI.
57+ *
58+ * @type string $slug The WordPress.org plugin slug.
59+ * }
60+ * }
61+ * @phpstan-return ?array{
62+ * name: non-empty-string,
63+ * description: non-empty-string,
64+ * logo_url?: non-empty-string,
65+ * type: 'ai_provider',
66+ * authentication: array{
67+ * method: 'api_key'|'none',
68+ * credentials_url?: non-empty-string,
69+ * setting_name?: non-empty-string
70+ * },
71+ * plugin?: array{
72+ * slug: non-empty-string
73+ * }
74+ * }
4175 */
4276function wp_get_connector ( string $ id ): ?array {
4377 $ registry = WP_Connector_Registry::get_instance ();
@@ -55,7 +89,45 @@ function wp_get_connector( string $id ): ?array {
5589 *
5690 * @see WP_Connector_Registry::get_all_registered()
5791 *
58- * @return array[] An array of registered connectors keyed by connector ID.
92+ * @return array {
93+ * Connector settings keyed by connector ID.
94+ *
95+ * @type array ...$0 {
96+ * Data for a single connector.
97+ *
98+ * @type string $name The connector's display name.
99+ * @type string $description The connector's description.
100+ * @type string $logo_url Optional. URL to the connector's logo image.
101+ * @type string $type The connector type. Currently, only 'ai_provider' is supported.
102+ * @type array $authentication {
103+ * Authentication configuration. When method is 'api_key', includes
104+ * credentials_url and setting_name. When 'none', only method is present.
105+ *
106+ * @type string $method The authentication method: 'api_key' or 'none'.
107+ * @type string $credentials_url Optional. URL where users can obtain API credentials.
108+ * @type string $setting_name Optional. The setting name for the API key.
109+ * }
110+ * @type array $plugin {
111+ * Optional. Plugin data for install/activate UI.
112+ *
113+ * @type string $slug The WordPress.org plugin slug.
114+ * }
115+ * }
116+ * }
117+ * @phpstan-return array<string, array{
118+ * name: non-empty-string,
119+ * description: non-empty-string,
120+ * logo_url?: non-empty-string,
121+ * type: 'ai_provider',
122+ * authentication: array{
123+ * method: 'api_key'|'none',
124+ * credentials_url?: non-empty-string,
125+ * setting_name?: non-empty-string
126+ * },
127+ * plugin?: array{
128+ * slug: non-empty-string
129+ * }
130+ * }>
59131 */
60132function wp_get_connectors (): array {
61133 $ registry = WP_Connector_Registry::get_instance ();
@@ -324,41 +396,6 @@ function _wp_connectors_get_real_api_key( string $option_name, callable $mask_ca
324396 return (string ) $ value ;
325397}
326398
327- /**
328- * Gets the registered connector settings.
329- *
330- * @since 7.0.0
331- * @access private
332- *
333- * @return array {
334- * Connector settings keyed by connector ID.
335- *
336- * @type array ...$0 {
337- * Data for a single connector.
338- *
339- * @type string $name The connector's display name.
340- * @type string $description The connector's description.
341- * @type string $type The connector type. Currently, only 'ai_provider' is supported.
342- * @type array $plugin Optional. Plugin data for install/activate UI.
343- * @type string $slug The WordPress.org plugin slug.
344- * }
345- * @type array $authentication {
346- * Authentication configuration. When method is 'api_key', includes
347- * credentials_url and setting_name. When 'none', only method is present.
348- *
349- * @type string $method The authentication method: 'api_key' or 'none'.
350- * @type string|null $credentials_url Optional. URL where users can obtain API credentials.
351- * @type string $setting_name Optional. The setting name for the API key.
352- * }
353- * }
354- * }
355- */
356- function _wp_connectors_get_connector_settings (): array {
357- $ connectors = wp_get_connectors ();
358- ksort ( $ connectors );
359- return $ connectors ;
360- }
361-
362399/**
363400 * Validates connector API keys in the REST response when explicitly requested.
364401 *
@@ -396,7 +433,7 @@ function _wp_connectors_validate_keys_in_rest( WP_REST_Response $response, WP_RE
396433 return $ response ;
397434 }
398435
399- foreach ( _wp_connectors_get_connector_settings () as $ connector_id => $ connector_data ) {
436+ foreach ( wp_get_connectors () as $ connector_id => $ connector_data ) {
400437 $ auth = $ connector_data ['authentication ' ];
401438 if ( 'ai_provider ' !== $ connector_data ['type ' ] || 'api_key ' !== $ auth ['method ' ] || empty ( $ auth ['setting_name ' ] ) ) {
402439 continue ;
@@ -431,7 +468,7 @@ function _wp_connectors_validate_keys_in_rest( WP_REST_Response $response, WP_RE
431468function _wp_register_default_connector_settings (): void {
432469 $ ai_registry = AiClient::defaultRegistry ();
433470
434- foreach ( _wp_connectors_get_connector_settings () as $ connector_id => $ connector_data ) {
471+ foreach ( wp_get_connectors () as $ connector_id => $ connector_data ) {
435472 $ auth = $ connector_data ['authentication ' ];
436473 if ( 'ai_provider ' !== $ connector_data ['type ' ] || 'api_key ' !== $ auth ['method ' ] || empty ( $ auth ['setting_name ' ] ) ) {
437474 continue ;
@@ -485,7 +522,7 @@ function _wp_register_default_connector_settings(): void {
485522function _wp_connectors_pass_default_keys_to_ai_client (): void {
486523 try {
487524 $ ai_registry = AiClient::defaultRegistry ();
488- foreach ( _wp_connectors_get_connector_settings () as $ connector_id => $ connector_data ) {
525+ foreach ( wp_get_connectors () as $ connector_id => $ connector_data ) {
489526 if ( 'ai_provider ' !== $ connector_data ['type ' ] ) {
490527 continue ;
491528 }
@@ -521,12 +558,12 @@ function _wp_connectors_pass_default_keys_to_ai_client(): void {
521558 * @since 7.0.0
522559 * @access private
523560 *
524- * @param array $data Existing script module data.
525- * @return array Script module data with connectors added.
561+ * @param array<string, mixed> $data Existing script module data.
562+ * @return array<string, mixed> Script module data with connectors added.
526563 */
527564function _wp_connectors_get_connector_script_module_data ( array $ data ): array {
528565 $ connectors = array ();
529- foreach ( _wp_connectors_get_connector_settings () as $ connector_id => $ connector_data ) {
566+ foreach ( wp_get_connectors () as $ connector_id => $ connector_data ) {
530567 $ auth = $ connector_data ['authentication ' ];
531568 $ auth_out = array ( 'method ' => $ auth ['method ' ] );
532569
@@ -548,6 +585,7 @@ function _wp_connectors_get_connector_script_module_data( array $data ): array {
548585
549586 $ connectors [ $ connector_id ] = $ connector_out ;
550587 }
588+ ksort ( $ connectors );
551589 $ data ['connectors ' ] = $ connectors ;
552590 return $ data ;
553591}
0 commit comments