/**
 * Execute functions hooked on a specific action hook, specifying arguments in a array.
 * 
 * This function is identical to {@link do_action}, but the argumetns passe to 
 * the functions hooked to <tt>$tag</tt> are supplied using an array.
 * @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>
 */
function do_action_ref_array($tag, $args) {
	global $wp_filter, $wp_actions;

	if ( !is_array($wp_actions) )
		$wp_actions = array($tag);
	else
		$wp_actions[] = $tag;

	merge_filters($tag);

	if ( !isset($wp_filter[$tag]) )
		return;

	do{
		foreach( (array) current($wp_filter[$tag]) as $the_ )
			if ( !is_null($the_['function']) )
				call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));

	} while ( next($wp_filter[$tag]) );

}
function do_action($tag, $arg = '') {
	global $wp_filter;
	$extra_args = array_slice(func_get_args(), 2);
 	if ( is_array($arg) )
 		$args = array_merge($arg, $extra_args);
	else
		$args = array_merge(array($arg), $extra_args);

	merge_filters($tag);

	if ( !isset($wp_filter[$tag]) ) {
		return;
	}
	foreach ($wp_filter[$tag] as $priority => $functions) {
		if ( !is_null($functions) ) {
			foreach($functions as $function) {

				$function_name = $function['function'];
				$accepted_args = $function['accepted_args'];

				if ( $accepted_args == 1 ) {
					if ( is_array($arg) )
						$the_args = $arg;
					else
						$the_args = array($arg);
				} elseif ( $accepted_args > 1 ) {
					$the_args = array_slice($args, 0, $accepted_args);
				} elseif ( $accepted_args == 0 ) {
					$the_args = NULL;
				} else {
					$the_args = $args;
				}

				$string = call_user_func_array($function_name, $the_args);
			}
		}
	}
}
function do_action($tag, $arg = '') {
	global $wp_filter;

	if ( is_array($arg) )
		$args = $arg + array_slice(func_get_args(), 2);
	else
		$args = array($arg) + array_slice(func_get_args(), 2);
	
	merge_filters($tag);
	
	if (isset($wp_filter[$tag])) {
		foreach ($wp_filter[$tag] as $priority => $functions) {
			if (!is_null($functions)) {
				foreach($functions as $function) {
					$string = call_user_func_array($function, $args);
				}
			}
		}
	}
}
Example #4
0
function apply_filters($tag, $string)
{
    global $wp_filter, $merged_filters;
    if (!isset($merged_filters[$tag])) {
        merge_filters($tag);
    }
    if (!isset($wp_filter[$tag])) {
        return $string;
    }
    reset($wp_filter[$tag]);
    $args = func_get_args();
    do {
        foreach ((array) current($wp_filter[$tag]) as $the_) {
            if (!is_null($the_['function'])) {
                $args[1] = $string;
                $string = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
            }
        }
    } while (next($wp_filter[$tag]) !== false);
    return $string;
}
function do_action_ref_array($tag, $args) {
	global $wp_filter, $wp_actions;

	if ( !is_array($wp_actions) )
		$wp_actions = array($tag);
	else
		$wp_actions[] = $tag;

	merge_filters($tag);

	if ( !isset($wp_filter[$tag]) )
		return;

	foreach ( (array) $wp_filter[$tag] as $priority => $functions ) {
		if ( !is_null($functions) ) {
			foreach ( (array) $functions as $function ) {
				$function_name = $function['function'];
				$accepted_args = $function['accepted_args'];
				if ( $accepted_args > 0 )
					$the_args = array_slice($args, 0, $accepted_args);
				elseif ( 0 == $accepted_args )
					$the_args = NULL;
				else
					$the_args = $args;

				call_user_func_array($function_name, $the_args);
			}
		}
	}
}