Пример #1
0
/**
 * Removes a function from a specified filter hook.
 *
 * This function removes a function attached to a specified filter hook. This
 * method can be used to remove default functions attached to a specific filter
 * hook and possibly replace them with a substitute.
 *
 * To remove a hook, the $function_to_remove and $priority arguments must match
 * when the hook was added. This goes for both filters and actions. No warning
 * will be given on removal failure.
 *
 * @author WordPress
 * @global array $filters Stores all of the filters
 *
 * @param string $filter The filter hook to which the function to be removed is hooked.
 * @param callback $function_to_remove The name of the function which should be removed.
 * @param int $priority optional. The priority of the function (default: 10).
 * @return boolean Whether the function existed before it was removed.
 */
function remove_filter($filter, $function_to_remove, $priority = 10)
{
    $function_to_remove = _build_callback_string($function_to_remove);
    $r = isset($GLOBALS['filters'][$filter][$priority][$function_to_remove]);
    if (true === $r) {
        unset($GLOBALS['filters'][$filter][$priority][$function_to_remove]);
        if (empty($GLOBALS['filters'][$filter][$priority])) {
            unset($GLOBALS['filters'][$filter][$priority]);
        }
    }
    return $r;
}
Пример #2
0
/**
 * Hooks a function or method to a specific filter action.
 *
 * Filters are the hooks that Lilina launches to modify text of various types
 * before adding it to the database or sending it to the browser screen. Plugins
 * can specify that one or more of its PHP functions is executed to
 * modify specific types of text at these times, using the Filter API.
 *
 * To use the API, the following code should be used to bind a callback to the
 * filter.
 *
 * <code>
 * function example_hook($example) { echo $example; }
 * add_filter('example_filter', 'example_hook');
 * </code>
 *
 * In WordPress 1.5.1+, hooked functions can take extra arguments that are set
 * when the matching do_action() or apply_filters() call is run. The
 * $accepted_args allow for calling functions only when the number of args
 * match. Hooked functions can take extra arguments that are set when the
 * matching do_action() or apply_filters() call is run. For example, the action
 * comment_id_not_found will pass any functions that hook onto it the ID of the
 * requested comment.
 *
 * <strong>Note:</strong> the function will return true no matter if the
 * function was hooked fails or not. There are no checks for whether the
 * function exists beforehand and no checks to whether the <tt>$function_to_add
 * is even a string. It is up to you to take care and this is done for
 * optimization purposes, so everything is as quick as possible.
 *
 * @author WordPress
 * @global array $filters Stores all of the filters added in the form of
 *	filters['tag']['array of priorities']['array of functions serialized']['array of ['array (functions, accepted_args)']']
 *
 * @param string $filter The name of the filter to hook the $function_to_add to.
 * @param callback $function The name of the function to be called 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). 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.
 * @param int $num_args optional. The number of arguments the function accept (default 1).
 * @return boolean true
 */
function add_filter($filter, $function, $priority = 10, $num_args = 1)
{
    global $filters;
    $id = _build_callback_string($function);
    $filters[$filter][$priority][$id] = array('function' => $function, 'num_args' => $num_args);
    return true;
}