WP_Hook
- Since
- 4.7.0
- Source
wp-includes/class-wp-hook.php:26
Core class used to implement action and filter hook functionality.
Compatibility
- WordPress
- since 4.7.0
- 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).
Properties · 6
$callbacksarraypublic- Hook callbacks keyed by priority.
$prioritieslist<int>protected- Priorities list.
$iterationsarray<int,private- The priority keys of actively running iterations of a hook.
$current_priorityarray<int,private- The current priority of actively running iterations of a hook.
$nesting_levelintprivate- Number of levels this hook can be recursively called.
$doing_actionboolprivate- Flag for if we're currently doing an action, rather than a filter.
Methods · 20
- add_filter()Adds a callback function to a filter hook.
- resort_active_iterations()Handles resetting callback priority keys mid-iteration.
- remove_filter()Removes a callback function from a filter hook.
- has_filter()Checks if a specific callback has been registered for this hook.
- has_filters()Checks if any callbacks have been registered for this hook.
- remove_all_filters()Removes all callbacks from the current filter.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- do_action()Calls the callback functions that have been added to an action hook.
- do_all_hook()Processes the functions hooked into the 'all' hook.
- current_priority()Return the current priority level of the currently running iteration of the hook.
- build_preinitialized_hooks()Normalizes filters set up before WordPress has initialized to WP_Hook objects.
- offsetExists()Determines whether an offset value exists.
- offsetGet()Retrieves a value at a specified offset.
- offsetSet()Sets a value at a specified offset.
- offsetUnset()Unsets a specified offset.
- current()Returns the current element.
- next()Moves forward to the next element.
- key()Returns the key of the current element.
- valid()Checks if current position is valid.
- rewind()Rewinds the Iterator to the first element.
Source code
#[AllowDynamicProperties]final class WP_Hook implements Iterator, ArrayAccess { /** * Hook callbacks keyed by priority. * * @since 4.7.0 * @var array * @phpstan-var array<int, array<string, Hook_Callback>> */ public $callbacks = array(); /** * Priorities list. * * @since 6.4.0 * @var list<int> */ protected $priorities = array(); /** * The priority keys of actively running iterations of a hook. * * @since 4.7.0 * @var array<int, list<int>> */ private $iterations = array(); /** * The current priority of actively running iterations of a hook. * * @since 4.7.0 * @var array<int, int> */ private $current_priority = array(); /** * Number of levels this hook can be recursively called. * * @since 4.7.0 * @var int */ private $nesting_level = 0; /** * Flag for if we're currently doing an action, rather than a filter. * * @since 4.7.0 * @var bool */ private $doing_action = false; /** * Adds a callback function to a filter hook. * * @since 4.7.0 * * @param string $hook_name The name of the filter to add the callback to. * @param callable $callback The callback to be run when the filter is applied. * @param int $priority The order in which the functions associated with a particular filter * are executed. Lower numbers correspond with earlier execution, * and functions with the same priority are executed in the order * in which they were added to the filter. * @param int $accepted_args The number of arguments the function accepts. */ public function add_filter( $hook_name, $callback, $priority, $accepted_args ) { if ( null === $priority ) { $priority = 0; } $idx = _wp_filter_build_unique_id( $hook_name, $callback, $priority ); if ( null === $idx ) { return; } $priority_existed = isset( $this->callbacks[ $priority ] ); $this->callbacks[ $priority ][ $idx ] = array( 'function' => $callback, 'accepted_args' => (int) $accepted_args,Changelog
Introduced in 4.7.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 7.1.0 tag, from
src/wp-includes/class-wp-hook.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.