WP_Hook::add_filter()
Adds a callback function to a filter hook.
Method of the class: WP_Hook{}
No Hooks.
Return
null
. Nothing (null).
Usage
$WP_Hook = new WP_Hook(); $WP_Hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
- $hook_name(string) (required)
- The name of the filter to add the callback to.
- $callback(callable) (required)
- The callback to be run when the filter is applied.
- $priority(int) (required)
- 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.
- $accepted_args(int) (required)
- The number of arguments the function accepts.
Changelog
Since 4.7.0 | Introduced. |
WP_Hook::add_filter() WP Hook::add filter code WP 6.7.1
public function add_filter( $hook_name, $callback, $priority, $accepted_args ) { $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 ) { ksort( $this->callbacks, SORT_NUMERIC ); } $this->priorities = array_keys( $this->callbacks ); if ( $this->nesting_level > 0 ) { $this->resort_active_iterations( $priority, $priority_existed ); } }