Skip to content

Instantly share code, notes, and snippets.

@mcaskill
Created January 18, 2019 17:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcaskill/f97201f1b5ffed9129da57144e0c254d to your computer and use it in GitHub Desktop.
Save mcaskill/f97201f1b5ffed9129da57144e0c254d to your computer and use it in GitHub Desktop.
WordPress \ Hooks : Hook a function or method to an array of actions or filters.
<?php
/**
* Hook a function or method to an array of actions.
*
* @param string[] $tags Array of names of filters to hook the $function callback to.
* @param callable $function_to_add The callback to be run when the filter is applied.
* @param int $priority Optional. Used to specify the order in which the functions
* associated with a particular action are executed. Default 10.
* @param int $accepted_args Optional. The number of arguments the function accepts. Default 1.
* @return true
*/
function add_actions( $tags, $function, $priority = 10, $accepted_args = 1 )
{
return add_filters( $tags, $function, $priority, $accepted_args );
}
/**
* Hook a function or method to an array of filters.
*
* @param string[] $tags Array of names of filters to hook the $function callback to.
* @param callable $function_to_add The callback to be run when the filter is applied.
* @param int $priority Optional. Used to specify the order in which the functions
* associated with a particular action are executed. Default 10.
* @param int $accepted_args Optional. The number of arguments the function accepts. Default 1.
* @return true
*/
function add_filters( $tags, $function, $priority = 10, $accepted_args = 1 )
{
foreach ((array) $tags as $tag ) {
add_filter( $tag, $function, $priority, $accepted_args );
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment