_deprecated_hook( string $hook, string $version, string $replacement = '', string $message = '' )
- Since
- 4.6.0, 5.4.0
- Source
wp-includes/functions.php:5932
Description
Use the 'deprecated_hook_run' action to get the backtrace describing where the deprecated hook was called.
Default behavior is to trigger a user error if WP_DEBUG is true.
This function is called by the do_action_deprecated() and apply_filters_deprecated() functions, and so generally does not need to be called directly.
Compatibility
- WordPress
- since 5.4.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$hookstring- The hook that was used.
$versionstring- The version of WordPress that deprecated the hook.
$replacementstringoptional- The hook that should have been used. Default empty string.Default:
'' $messagestringoptional- A message regarding the change. Default empty.Default:
''
Performance profile
How much work a call to _deprecated_hook() 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
- 14–42
- Plugin surface
- 2 hooks
- 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 53.
Third-party callbacks on 'deprecated_hook_run', 'deprecated_hook_trigger_error' run inside this call, and their cost is not bounded by anything here.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
do_action()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 · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost _deprecated_hook() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 14 | do_action() |
!apply_filters() | 19 | do_action(), apply_filters() |
apply_filters() | 39–42 | do_action(), apply_filters(), __(), sprintf(), wp_trigger_error() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 53 | 14–42 | 4 | |
| 8.5 | 53 | 14–42 | 4 | |
| 8.4 | 53 | 14–42 | 4 | |
| 8.3 | 53 | 14–42 | 4 | |
| 8.2 | 53 | 14–42 | 4 | |
| 8.1 | 53 | 14–42 | 4 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 54 | 14–42 | 4 |
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 · 2
2 hooks fire while _deprecated_hook() runs, in this order:
- do_action( deprecated_hook_run )actionline 5943 (+11 into the body)
Fires when a deprecated hook is called.
- apply_filters( deprecated_hook_trigger_error )filterline 5953 (+21 into the body)
Filters whether to trigger deprecated hook errors.
Uses · 4
- do_action()Calls the callback functions that have been added to an action hook.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- __()Retrieves the translation of $text.
- wp_trigger_error()Generates a user-level error/warning/notice/deprecation message.
Used by · 2
- apply_filters_deprecated()Fires functions attached to a deprecated filter hook.
- do_action_deprecated()Fires functions attached to a deprecated action hook.
Source code
function _deprecated_hook( $hook, $version, $replacement = '', $message = '' ) { /** * Fires when a deprecated hook is called. * * @since 4.6.0 * * @param string $hook The hook that was called. * @param string $replacement The hook that should be used as a replacement. * @param string $version The version of WordPress that deprecated the argument used. * @param string $message A message regarding the change. */ do_action( 'deprecated_hook_run', $hook, $replacement, $version, $message ); /** * Filters whether to trigger deprecated hook errors. * * @since 4.6.0 * * @param bool $trigger Whether to trigger deprecated hook errors. Requires * `WP_DEBUG` to be defined true. */ if ( WP_DEBUG && apply_filters( 'deprecated_hook_trigger_error', true ) ) { $message = empty( $message ) ? '' : ' ' . $message; if ( $replacement ) { $message = sprintf( /* translators: 1: WordPress hook name, 2: Version number, 3: Alternative hook name. */ __( 'Hook %1$s is <strong>deprecated</strong> since version %2$s! Use %3$s instead.' ), $hook, $version, $replacement ) . $message; } else { $message = sprintf( /* translators: 1: WordPress hook name, 2: Version number. */ __( 'Hook %1$s is <strong>deprecated</strong> since version %2$s with no alternative available.' ), $hook, $version ) . $message; } wp_trigger_error( '', $message, E_USER_DEPRECATED ); }}Changelog
Introduced in 4.6.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/functions.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.