| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * WordPress AI Client API. 4 * 5 * @package WordPress 6 * @subpackage AI 7 * @since 7.0.0 8 */ 9 10 use WordPress\AiClient\AiClient; 11 use WordPress\AiClient\Messages\DTO\Message; 12 use WordPress\AiClient\Messages\DTO\MessagePart; 13 14 /** 15 * Returns whether AI features are supported in the current environment. 16 * 17 * @since 7.0.0 18 * 19 * @return bool Whether AI features are supported. 20 */ 21 function wp_supports_ai(): bool { 22 // Return early if AI is disabled by the current environment. 23 if ( defined( 'WP_AI_SUPPORT' ) && ! WP_AI_SUPPORT ) { 24 return false; 25 } 26 27 /** 28 * Filters whether the current request can use AI. 29 * 30 * This allows plugins and 3rd-party code to disable AI features on a per-request basis, or to even override explicit 31 * preferences defined by the site owner. 32 * 33 * @since 7.0.0 34 * 35 * @param bool $is_enabled Whether AI is available. Default to true. 36 */ 37 return (bool) apply_filters( 'wp_supports_ai', true ); 38 } 39 40 /** 41 * Creates a new AI prompt builder using the default provider registry. 42 * 43 * This is the main entry point for generating AI content in WordPress. It returns 44 * a fluent builder that can be used to configure and execute AI prompts. 45 * 46 * The prompt can be provided as a simple string for basic text prompts, or as more 47 * complex types for advanced use cases like multi-modal content or conversation history. 48 * 49 * @since 7.0.0 50 * 51 * @param string|MessagePart|Message|array|list<string|MessagePart|array>|list<Message>|null $prompt Optional. Initial prompt content. 52 * A string for simple text prompts, 53 * a MessagePart or Message object for 54 * structured content, an array for a 55 * message array shape, or a list of 56 * parts or messages for multi-turn 57 * conversations. Default null. 58 * @return WP_AI_Client_Prompt_Builder The prompt builder instance. 59 */ 60 function wp_ai_client_prompt( $prompt = null ): WP_AI_Client_Prompt_Builder { 61 return new WP_AI_Client_Prompt_Builder( AiClient::defaultRegistry(), $prompt ); 62 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sat Jun 13 09:38:55 2026 | Cross-referenced by PHPXref |