WP_Ability::invoke_callback( callable $callback, mixed $input = null ): mixed
- Since
- 6.9.0
- Source
wp-includes/abilities-api/class-wp-ability.php:585
Compatibility
- WordPress
- since 6.9.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 3 of the 5 tracked releases, added in 6.9.0, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$callbackcallable- The callable to invoke.
$inputmixedoptional- The input data for the ability. Default
null.Default:null
Return value
mixed- The result of the callable execution, or a
WP_Errorif the callback threw.
Performance profile
How much work a call to WP_Ability::invoke_callback() 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–13
- Plugin surface
- None
- Called by
- 2
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 33.
Nothing here hands control to plugin code.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()one call below WP_Ability::invoke_callback()
Further down the call graph this can also reach option, cache, serialize, query 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 · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Ability::invoke_callback() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 11–13 | ->get_input_schema() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 33 | 11–13 | 1 | |
| 8.5 | 33 | 11–13 | 1 | |
| 8.4 | 33 | 11–13 | 1 | |
| 8.3 | 33 | 11–13 | 1 | |
| 8.2 | 33 | 11–13 | 1 | |
| 8.1 | 33 | 11–13 | 1 | 1 more instruction than PHP 7.4 |
| 7.4 | 32 | 10–12 | 1 |
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.
Uses · 4
- __()Retrieves the translation of $text.
- esc_html()Escaping for HTML blocks.
- WP_Ability::get_input_schema()Retrieves the input schema for the ability.
- WP_Error::__construct()Initializes the error.
Used by · 2
- WP_Ability::check_permissions()Checks whether the ability has the necessary permissions.
- WP_Ability::do_execute()Executes the ability callback.
Source code
protected function invoke_callback( callable $callback, $input = null ) { $args = array(); if ( ! empty( $this->get_input_schema() ) ) { $args[] = $input; } try { return $callback( ...$args ); } catch ( Throwable $e ) { return new WP_Error( 'ability_callback_exception', sprintf( /* translators: 1: Ability name, 2: Exception message. */ __( 'Ability "%1$s" callback threw an exception: %2$s' ), $this->name, esc_html( $e->getMessage() ) ) ); } }Changelog
Introduced in 6.9.0. Unchanged from 6.9.7 through 7.1.0.
Signature, return type and hooks compared across 3 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/abilities-api/class-wp-ability.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.