wppaste
WordPress

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

Since
7.0.0
Source
wp-includes/ai-client/class-wp-ai-client-prompt-builder.php:293
Magic method to proxy snake_case method calls to their PHP AI Client camelCase counterparts.

Description

This allows WordPress developers to use snake_case naming conventions. It catches any exceptions thrown, stores them, and returns a WP_Error when a terminate method is called.

Compatibility

WordPress
since 7.0.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in 2 of the 5 tracked releases, added in 7.0.0, and compiles on PHP 7.4 through 8.6-dev.

Parameters

$namestring
The method name in snake_case.
$argumentsarray

Return value

mixed
The result of the method call.

Performance profile

How much work a call to WP_AI_Client_Prompt_Builder::__call() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
11–53

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 101.

Plugin surface
1 hook

Third-party callbacks on 'wp_ai_client_prevent_prompt' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_filters()called directly

Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 13 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_AI_Client_Prompt_Builder::__call() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
::is_generating_method()11::is_generating_method()
!::is_generating_method()14–15::is_generating_method(), ::is_support_check_method()
::is_support_check_method()20::is_support_check_method(), wp_supports_ai(), ::is_support_check_method()
::is_generating_method()24::is_support_check_method(), ::is_generating_method(), wp_supports_ai(), ::is_support_check_method()
!::is_support_check_method() && !::is_generating_method()25–26::is_support_check_method(), ::is_generating_method(), ->get_builder_callable()
::is_support_check_method()30::is_support_check_method(), wp_supports_ai(), apply_filters(), ::is_support_check_method()
::is_generating_method()34::is_support_check_method(), ::is_generating_method(), wp_supports_ai(), apply_filters(), ::is_support_check_method()
::is_support_check_method()37–38::is_support_check_method(), wp_supports_ai(), apply_filters(), ->get_builder_callable()
always38–39::is_support_check_method(), wp_supports_ai(), ::is_support_check_method(), __(), ::is_generating_method()
!::is_support_check_method() && ::is_generating_method()41–42::is_support_check_method(), ::is_generating_method(), wp_supports_ai(), apply_filters(), ->get_builder_callable()
!::is_support_check_method() && ::is_generating_method()42–43::is_support_check_method(), ::is_generating_method(), wp_supports_ai(), ::is_support_check_method(), __(), ::is_generating_method()
always48–49::is_support_check_method(), wp_supports_ai(), apply_filters(), ::is_support_check_method(), __(), ::is_generating_method()
1 further outcome, up to 53 instructions
!::is_support_check_method() && ::is_generating_method()52–53::is_support_check_method(), ::is_generating_method(), wp_supports_ai(), apply_filters(), ::is_support_check_method(), __(), ::is_generating_method()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev9911–52122 fewer instructions than PHP 8.5
8.510111–5312
8.410111–5312
8.310111–5312
8.210111–5312
8.110111–53121 more instruction than PHP 7.4
7.410011–5312

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while WP_AI_Client_Prompt_Builder::__call() runs, in this order:

  1. apply_filters( wp_ai_client_prevent_prompt )filterline 322 (+29 into the body)

    Filters whether to prevent the prompt from being executed.

Uses · 8

Source code

	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;		}	}

Changelog

Introduced in 7.0.0. Unchanged from 7.0.4 through 7.1.0.

  1. 7.0.4
  2. 7.1.0

Signature, return type and hooks compared across 2 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/ai-client/class-wp-ai-client-prompt-builder.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.