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
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
- Scaling
- Constant
- Instructions
- 11–53
- Plugin surface
- 1 hook
- Called by
- 0
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 101.
Third-party callbacks on 'wp_ai_client_prevent_prompt' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_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.
| When | Instructions | Calls 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() |
| always | 38–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() |
| always | 48–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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 99 | 11–52 | 12 | 2 fewer instructions than PHP 8.5 |
| 8.5 | 101 | 11–53 | 12 | |
| 8.4 | 101 | 11–53 | 12 | |
| 8.3 | 101 | 11–53 | 12 | |
| 8.2 | 101 | 11–53 | 12 | |
| 8.1 | 101 | 11–53 | 12 | 1 more instruction than PHP 7.4 |
| 7.4 | 100 | 11–53 | 12 |
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:
- apply_filters( wp_ai_client_prevent_prompt )filterline 322 (+29 into the body)
Filters whether to prevent the prompt from being executed.
Uses · 8
- wp_supports_ai()Returns whether AI features are supported in the current environment.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- __()Retrieves the translation of $text.
- WP_AI_Client_Prompt_Builder::is_generating_method()Checks if a method name is a generating method (generate_*, convert_text_to_speech*).
- WP_AI_Client_Prompt_Builder::is_support_check_method()Checks if a method name is a support check method (is_supported*).
- WP_Error::__construct()Initializes the error.
- WP_AI_Client_Prompt_Builder::get_builder_callable()Retrieves a callable for a given PHP AI Client SDK prompt builder method name.
- WP_AI_Client_Prompt_Builder::exception_to_wp_error()Converts an exception into a WP_Error with a structured error code and message.
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.
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.