ZHXCore CMS

Filters


Based on the Wordpress hook functions.

Add Filter

Hook a function or method to a specific filter action.

ZHXCORE provides filter hooks to permit plugins to modify various types of internal data at runtime. A plugin can modify data by binding a callback to a filter hook. When the filter is later applied, each bound callback is run in order of priority, and given the opportunity to modify a value by returning a new value.

add_filter( string $tag, callable $function_to_add, int $priority = 10, int $accepted_args = 1 )

The following example shows how a callback function is bound to a filter hook.

Note that $zhxcore is passed to the callback, (maybe) modified, then returned:

function zhxcore_callback( $zhxcore ) {

    // Maybe modify $zhxcore in some way.

    return $zhxcore;
}    

add_filter( 'zhxcore_filter', 'zhxcore_callback' ); 

Bound callbacks can accept from none (0) or all of the arguments passed as parameters in the corresponding apply_filters() call.

In other words, if an apply_filters() call passes four(4) total arguments, callbacks bound to it can accept none (0) (the same as 1) of the arguments or up to four(4). The important part is that the $accepted_args value must reflect the number of arguments the bound callback actually opted to accept. If no arguments were accepted by the callback that is considered to be the same as accepting 1 argument.

Required Type Name Description Default Value
Yes String $tag The name of the action to which the $function_to_add is hooked. --/--
Yes Callable $function_to_add The callback to be run when the filter is applied. --/--
No Int $priority Used to specify the order in which the functions associated with a particular action 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 action. 10
No Int $accepted_args The number of arguments the function accepts. 1

Apply Filters

Call the functions added to a filter hook.

The callback functions attached to filter hook $tag are invoked by calling this function. This function can be used to create a new filter hook by simply calling this function with the name of the new hook specified using the $tag parameter.

The function allows for additional arguments to be added and passed to hooks.

apply_filters( string $tag, mixed $value )

Required Type Name Description Default Value
Yes String $tag The name of the filter hook. --/--
Yes mixed $value The value on which the filters hooked to $tag are applied on. --/--
Yes mixed $var,... Additional variables passed to the functions hooked to $tag. --/--

Additional Resources

You can find additional information on these function as they work in the same manner wordpress.