Ejemplo n.º 1
0
/**
 * 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.
 * <code>
 * function example_hook($string, $arg1, $arg2)
 * {
 *		//Do stuff
 *		return $string;
 * }
 * $value = apply_filters('example_filter', 'filter me', 'arg1', 'arg2');
 * </code>
 *
 * @package WordPress
 * @global array $filters Stores all of the filters
 *
 * @param string $filter_name The name of the filter hook.
 * @param mixed $value The value on which the filters hooked to <tt>$filter_name</tt> are applied on.
 * @param mixed $var,... Additional variables passed to the functions hooked to <tt>$filter_name</tt>.
 * @return mixed The filtered value after all hooked functions are applied to it.
 */
function apply_filters($filter_name, $string = '')
{
    global $filters;
    $args = func_get_args();
    // Do 'all' actions first
    if (isset($filters['all'])) {
        _call_all_hook($args);
    }
    if (!isset($filters[$filter_name])) {
        return $string;
    }
    ksort($filters[$filter_name]);
    reset($filters[$filter_name]);
    global $current_filter;
    $current_filter = $filter_name;
    do {
        foreach ((array) current($filters[$filter_name]) as $filter) {
            $filter_function = $filter['function'];
            $string = call_user_func_array($filter['function'], array_slice($args, 1, (int) $filter['num_args']));
        }
    } while (next($filters[$filter_name]) !== false);
    $current_filter = '';
    return $string;
}
Ejemplo n.º 2
0
/**
 * Execute functions hooked on a specific action hook, specifying arguments in an array.
 *
 * @see do_action() This function is identical, but the arguments passed to the
 * functions hooked to <tt>$tag</tt> are supplied using an array.
 *
 * @package WordPress
 * @subpackage Plugin
 * @since 2.1
 * @global array $wp_filter Stores all of the filters
 * @global array $wp_actions Increments the amount of times action was triggered.
 *
 * @param string $tag The name of the action to be executed.
 * @param array $args The arguments supplied to the functions hooked to <tt>$tag</tt>
 * @return null Will return null if $tag does not exist in $wp_filter array
 */
function do_action_ref_array($tag, $args)
{
    global $filters;
    global $current_filter;
    $current_filter = $tag;
    // Do 'all' actions first
    if (isset($filters['all'])) {
        $all_args = func_get_args();
        _call_all_hook($all_args);
    }
    if (!isset($filters[$tag])) {
        return;
    }
    ksort($filters[$tag]);
    reset($filters[$tag]);
    do {
        foreach ((array) current($filters[$tag]) as $action) {
            call_user_func_array($action['function'], array_slice($args, 0, (int) $action['num_args']));
        }
    } while (next($filters[$tag]) !== false);
    $current_filter = '';
}
Ejemplo n.º 3
0
 /**
  * Execute functions hooked on a specific filter hook, specifying arguments in an array.
  *
  * @see apply_filters() This function is identical, but the arguments passed to the
  * functions hooked to `$tag` are supplied using an array.
  * 
  * @param string $tag  The name of the filter hook.
  * @param array  $args The arguments supplied to the functions hooked to $tag.
  * @return mixed The filtered value after all hooked functions are applied to it.
  */
 function apply_filters_ref_array($tag, $args)
 {
     // Do 'all' actions first
     if (isset($this->filter['all'])) {
         $this->current_filter[] = $tag;
         $all_args = func_get_args();
         _call_all_hook($all_args);
     }
     if (!isset($this->filter[$tag])) {
         if (isset($this->filter['all'])) {
             array_pop($this->current_filter);
         }
         return $args[0];
     }
     if (!isset($this->filter['all'])) {
         $this->current_filter[] = $tag;
     }
     // Sort
     if (!isset($this->merged_filters[$tag])) {
         ksort($this->filter[$tag]);
         $this->merged_filters[$tag] = true;
     }
     reset($this->filter[$tag]);
     do {
         foreach ((array) current($this->filter[$tag]) as $the_) {
             if (!is_null($the_['function'])) {
                 $args[0] = call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
             }
         }
     } while (next($this->filter[$tag]) !== false);
     array_pop($this->current_filter);
     return $args[0];
 }