Adds a callback function to a filter hook.
$hook_namestringrequired
$callbackcallablerequired
$priorityintrequired
$accepted_argsintrequired
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 );
}
}
| Version | Description |
|---|---|
| 4.7.0 | Introduced. |
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_hook/add_filter