wppaste
WordPress

WP_Hook

Since
4.7.0
Source
wp-includes/class-wp-hook.php:18
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.
$prioritiesarrayprotected
Priorities list.
$iterationsarrayprivate
The priority keys of actively running iterations of a hook.
$current_priorityarrayprivate
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

Source code

#[AllowDynamicProperties]final class WP_Hook implements Iterator, ArrayAccess { 	/**	 * Hook callbacks.	 *	 * @since 4.7.0	 * @var array	 */	public $callbacks = array(); 	/**	 * Priorities list.	 *	 * @since 6.4.0	 * @var array	 */	protected $priorities = array(); 	/**	 * The priority keys of actively running iterations of a hook.	 *	 * @since 4.7.0	 * @var array	 */	private $iterations = array(); 	/**	 * The current priority of actively running iterations of a hook.	 *	 * @since 4.7.0	 * @var array	 */	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 ); 		$priority_existed = isset( $this->callbacks[ $priority ] ); 		$this->callbacks[ $priority ][ $idx ] = array(			'function'      => $callback,			'accepted_args' => (int) $accepted_args,		); 		// If we're adding a new priority to the list, put them back in sorted order.		if ( ! $priority_existed && count( $this->callbacks ) > 1 ) {

Changelog

Introduced in 4.7.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

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

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 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.