[wp-trac] [WordPress Trac] #64924: Add a `has_ai_credentials()` function to WordPress core that plugins can use to check if AI credentials are available.

WordPress Trac noreply at wordpress.org
Sun Mar 22 18:33:51 UTC 2026


#64924: Add a `has_ai_credentials()` function to WordPress core that plugins can
use to check if AI credentials are available.
-------------------------------------+-------------------------------------
 Reporter:  raftaar1191              |      Owner:  (none)
     Type:  enhancement              |     Status:  new
 Priority:  normal                   |  Milestone:  Awaiting Review
Component:  AI                       |    Version:  trunk
 Severity:  normal                   |   Keywords:  2nd-opinion needs-patch
  Focuses:  accessibility,           |  needs-testing
  sustainability                     |
-------------------------------------+-------------------------------------
 == Summary ==

 Add a `has_ai_credentials()` function to WordPress core that plugins can
 use to check if AI credentials are available.

 == Description ==

 Currently, the `has_ai_credentials()` function exists in the WordPress AI
 plugin but should be moved to core so that all plugins can reliably check
 for the availability of AI credentials without having to implement their
 own logic.

 This is a common need for plugins that integrate with AI features but
 should only expose certain functionality when credentials are actually
 configured.

 == Proposed Solution ==

 Add the following function to WordPress core (recommended location: `wp-
 includes/ai.php`):

 {{{#!php
 /**
  * Checks if we have AI credentials set.
  *
  * @since 7.0
  *
  * @return bool True if we have AI credentials, false otherwise.
  */
 function has_ai_credentials(): bool {
         if ( ! function_exists( 'wp_get_connectors' ) ) {
                 return false;
         }

         foreach ( wp_get_connectors() as $connector_data ) {
                 if ( 'ai_provider' !== $connector_data['type'] ) {
                         continue;
                 }

                 $auth = $connector_data['authentication'];
                 if ( 'api_key' !== $auth['method'] || empty(
 $auth['setting_name'] ) ) {
                         continue;
                 }

                 if ( '' === get_option( $auth['setting_name'], '' ) ) {
                         continue;
                 }

                 return true;
         }

         /**
          * Filters whether AI credentials are available.
          *
          * Allows third-party plugins to declare credential availability
 for
          * connectors that do not rely on API key settings.
          *
          * @since 7.0
          *
          * @param bool  $has_credentials Whether AI credentials are
 available.
          * @param array $connector_data  The connector data.
          */
         return (bool) apply_filters( 'wp_has_ai_credentials', false,
 $connector_data );
 }
 }}}

 == Benefits ==

 * Provides a standard, core API for checking AI credential availability
 * Eliminates the need for plugins to implement their own credential-
 checking logic
 * Ensures consistency across the WordPress ecosystem
 * Allows the AI plugin to use core functionality rather than duplicating
 code

 == Current Implementation ==

 This function currently exists in the WordPress AI plugin:
 https://github.com/WordPress/ai/blob/32c5e2ddb435f30ddc40b48635c084de25846b5b/includes/helpers.php#L304

 == Related Tickets ==

 Part of the broader effort to expose AI APIs in WordPress core.

 == Acceptance Criteria ==

 * Function is added to core
 * Function is properly documented with inline PHPDoc
 * Function is exported in the public API
 * Tests are added for various scenarios (no credentials, credentials
 present, filter usage)
 * Documentation is updated

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64924>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list