- Timestamp:
- 03/19/2026 01:55:45 PM (7 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/ai-client/class-wp-ai-client-prompt-builder.php
r62037 r62067 46 46 * 47 47 * @since 7.0.0 48 * 49 * @phpstan-import-type Prompt from PromptBuilder 48 50 * 49 51 * @method self with_text(string $text) Adds text to the current message. … … 171 173 * @since 7.0.0 172 174 * 173 * @param ProviderRegistry $registry The provider registry for finding suitable models.174 * @param string|MessagePart|Message|array|list<string|MessagePart|array>|list<Message>|null$prompt Optional. Initial prompt content.175 * A string for simple text prompts,176 * a MessagePart or Message object for177 * structured content, an array for a178 * message array shape, or a list of179 * parts or messages for multi-turn180 * conversations. Default null.175 * @param ProviderRegistry $registry The provider registry for finding suitable models. 176 * @param Prompt $prompt Optional. Initial prompt content. 177 * A string for simple text prompts, 178 * a MessagePart or Message object for 179 * structured content, an array for a 180 * message array shape, or a list of 181 * parts or messages for multi-turn 182 * conversations. Default null. 181 183 */ 182 184 public function __construct( ProviderRegistry $registry, $prompt = null ) { … … 290 292 // Check if the prompt should be prevented for is_supported* and generate_*/convert_text_to_speech* methods. 291 293 if ( self::is_support_check_method( $name ) || self::is_generating_method( $name ) ) { 292 /** 293 * Filters whether to prevent the prompt from being executed. 294 * 295 * @since 7.0.0 296 * 297 * @param bool $prevent Whether to prevent the prompt. Default false. 298 * @param WP_AI_Client_Prompt_Builder $builder A clone of the prompt builder instance (read-only). 299 */ 300 $prevent = (bool) apply_filters( 'wp_ai_client_prevent_prompt', false, clone $this ); 294 // If AI is not supported, then there's no need to apply the filter as the prompt will be prevented anyway. 295 $is_ai_disabled = ! wp_supports_ai(); 296 $prevent = $is_ai_disabled; 297 if ( ! $prevent ) { 298 /** 299 * Filters whether to prevent the prompt from being executed. 300 * 301 * @since 7.0.0 302 * 303 * @param bool $prevent Whether to prevent the prompt. Default false. 304 * @param WP_AI_Client_Prompt_Builder $builder A clone of the prompt builder instance (read-only). 305 */ 306 $prevent = (bool) apply_filters( 'wp_ai_client_prevent_prompt', false, clone $this ); 307 } 301 308 302 309 if ( $prevent ) { … … 306 313 } 307 314 315 $error_message = $is_ai_disabled 316 ? __( 'AI features are not supported in this environment.' ) 317 : __( 'Prompt execution was prevented by a filter.' ); 318 308 319 // For generate_* and convert_text_to_speech* methods, create a WP_Error. 309 320 $this->error = new WP_Error( 310 321 'prompt_prevented', 311 __( 'Prompt execution was prevented by a filter.' ),322 $error_message, 312 323 array( 313 324 'status' => 503, … … 424 435 $camel_case_name = $this->snake_to_camel_case( $name ); 425 436 426 if ( ! is_callable( array( $this->builder, $camel_case_name ) ) ) { 437 $method = array( $this->builder, $camel_case_name ); 438 if ( ! is_callable( $method ) ) { 427 439 throw new BadMethodCallException( 428 440 sprintf( … … 435 447 } 436 448 437 return array( $this->builder, $camel_case_name );449 return $method; 438 450 } 439 451
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)