-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
Problem
The API_Credentials_Manager::collect_providers() method collects provider metadata during AI_Client::init(). This happens early in the WordPress init action, making it difficult for plugins to register additional providers that appear on the credentials screen.
Currently, any providers registered after AI_Client::init() runs will:
- Be available in the runtime registry
- Not appear on the Settings → AI Credentials screen (because collection already happened)
Current Workaround
Plugins must carefully order their initialization to register providers before calling AI_Client::init():
// 1. Init HTTP discovery first
WP_AI_Client_Discovery_Strategy::init();
// 2. Register custom providers to the registry
AiClient::defaultRegistry()->registerProvider(MyProvider::class);
// 3. Then init AI_Client (which collects providers)
AI_Client::init();This is fragile and requires knowledge of internal implementation details.
Proposed Solution
Add a hook before provider collection:
private function collect_providers(): void {
global $wp_ai_client_providers_metadata;
if ( ! isset( $wp_ai_client_providers_metadata ) ) {
$wp_ai_client_providers_metadata = array();
}
// Allow plugins to register providers before collection
do_action( 'wp_ai_client_before_collect_providers', AiClient::defaultRegistry() );
$registry = AiClient::defaultRegistry();
// ... rest of collection logic
}This would allow plugins to simply:
add_action( 'wp_ai_client_before_collect_providers', function( $registry ) {
$registry->registerProvider( MyCustomProvider::class );
});Alternative
Collect providers lazily on admin_menu (only when the credentials screen is actually needed) instead of eagerly during init.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels