Title: WP_AI_Client_Prompt_Builder::__call
Published: May 20, 2026

---

# WP_AI_Client_Prompt_Builder::__call( string $name,  $arguments ): mixed

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/__call/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/__call/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/__call/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/__call/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/__call/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/__call/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/__call/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/__call/?output_format=md#wp--skip-link--target)

Magic method to proxy snake_case method calls to their PHP AI Client camelCase counterparts.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/__call/?output_format=md#description)󠁿

This allows WordPress developers to use snake_case naming conventions. It catches
any exceptions thrown, stores them, and returns a [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
when a terminate method is called.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/__call/?output_format=md#parameters)󠁿

 `$name`stringrequired

The method name in snake_case.

mixed> $arguments The method arguments.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/__call/?output_format=md#return)󠁿

 mixed The result of the method call.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/__call/?output_format=md#source)󠁿

    ```php
    public function __call( string $name, array $arguments ) {
    	/*
    	 * If an error occurred in a previous method call, either return the error for terminate methods,
    	 * or return the same instance for other methods to maintain the fluent interface.
    	 */
    	if ( null !== $this->error ) {
    		if ( self::is_generating_method( $name ) ) {
    			return $this->error;
    		}
    		if ( self::is_support_check_method( $name ) ) {
    			return false;
    		}
    		return $this;
    	}

    	// Check if the prompt should be prevented for is_supported* and generate_*/convert_text_to_speech* methods.
    	if ( self::is_support_check_method( $name ) || self::is_generating_method( $name ) ) {
    		// If AI is not supported, then there's no need to apply the filter as the prompt will be prevented anyway.
    		$is_ai_disabled = ! wp_supports_ai();
    		$prevent        = $is_ai_disabled;
    		if ( ! $prevent ) {
    			/**
    			 * Filters whether to prevent the prompt from being executed.
    			 *
    			 * @since 7.0.0
    			 *
    			 * @param bool                        $prevent Whether to prevent the prompt. Default false.
    			 * @param WP_AI_Client_Prompt_Builder $builder A clone of the prompt builder instance (read-only).
    			 */
    			$prevent = (bool) apply_filters( 'wp_ai_client_prevent_prompt', false, clone $this );
    		}

    		if ( $prevent ) {
    			// For is_supported* methods, return false.
    			if ( self::is_support_check_method( $name ) ) {
    				return false;
    			}

    			$error_message = $is_ai_disabled
    				? __( 'AI features are not supported in this environment.' )
    				: __( 'Prompt execution was prevented by a filter.' );

    			// For generate_* and convert_text_to_speech* methods, create a WP_Error.
    			$this->error = new WP_Error(
    				'prompt_prevented',
    				$error_message,
    				array(
    					'status' => 503,
    				)
    			);

    			if ( self::is_generating_method( $name ) ) {
    				return $this->error;
    			}
    			return $this;
    		}
    	}

    	try {
    		$callable = $this->get_builder_callable( $name );
    		$result   = $callable( ...$arguments );

    		// If the result is a PromptBuilder, return the current instance to allow method chaining.
    		if ( $result instanceof PromptBuilder ) {
    			return $this;
    		}

    		return $result;
    	} catch ( Exception $e ) {
    		$this->error = $this->exception_to_wp_error( $e );

    		if ( self::is_generating_method( $name ) ) {
    			return $this->error;
    		}
    		return $this;
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/ai-client/class-wp-ai-client-prompt-builder.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/ai-client/class-wp-ai-client-prompt-builder.php#L293)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/ai-client/class-wp-ai-client-prompt-builder.php#L293-L369)

## 󠀁[Hooks](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/__call/?output_format=md#hooks)󠁿

 [apply_filters( ‘wp_ai_client_prevent_prompt’, bool $prevent, WP_AI_Client_Prompt_Builder $builder )](https://developer.wordpress.org/reference/hooks/wp_ai_client_prevent_prompt/)

Filters whether to prevent the prompt from being executed.

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/__call/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_AI_Client_Prompt_Builder::is_generating_method()](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/is_generating_method/)`wp-includes/ai-client/class-wp-ai-client-prompt-builder.php` |

Checks if a method name is a generating method (generate_*, convert_text_to_speech*).

  | 
| [WP_AI_Client_Prompt_Builder::is_support_check_method()](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/is_support_check_method/)`wp-includes/ai-client/class-wp-ai-client-prompt-builder.php` |

Checks if a method name is a support check method (is_supported*).

  | 
| [WP_AI_Client_Prompt_Builder::get_builder_callable()](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/get_builder_callable/)`wp-includes/ai-client/class-wp-ai-client-prompt-builder.php` |

Retrieves a callable for a given PHP AI Client SDK prompt builder method name.

  | 
| [WP_AI_Client_Prompt_Builder::exception_to_wp_error()](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/exception_to_wp_error/)`wp-includes/ai-client/class-wp-ai-client-prompt-builder.php` |

Converts an exception into a [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) with a structured error code and message.

  | 
| [wp_supports_ai()](https://developer.wordpress.org/reference/functions/wp_supports_ai/)`wp-includes/ai-client.php` |

Returns whether AI features are supported in the current environment.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [WP_Error::__construct()](https://developer.wordpress.org/reference/classes/wp_error/__construct/)`wp-includes/class-wp-error.php` |

Initializes the error.

  |

[Show 3 more](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/__call/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/__call/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_ai_client_prompt_builder/__call/?output_format=md#changelog)󠁿

| Version | Description | 
| [7.0.0](https://developer.wordpress.org/reference/since/7.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_ai_client_prompt_builder%2F__call%2F)
before being able to contribute a note or feedback.