177 | | * Execute functions hooked on a specific filter hook, specifying arguments in an array. |
178 | | * |
179 | | * @see apply_filters() This function is identical, but the arguments passed to the |
180 | | * functions hooked to <tt>$tag</tt> are supplied using an array. |
181 | | * |
182 | | * @package WordPress |
183 | | * @subpackage Plugin |
184 | | * @since 3.0.0 |
185 | | * @global array $wp_filter Stores all of the filters |
186 | | * @global array $merged_filters Merges the filter hooks using this function. |
187 | | * @global array $wp_current_filter stores the list of current filters with the current one last |
188 | | * |
189 | | * @param string $tag The name of the filter hook. |
190 | | * @param array $args The arguments supplied to the functions hooked to <tt>$tag</tt> |
191 | | * @return mixed The filtered value after all hooked functions are applied to it. |
192 | | */ |
193 | | function apply_filters_ref_array($tag, $args) { |
194 | | global $wp_filter, $merged_filters, $wp_current_filter; |
195 | | |
196 | | $wp_current_filter[] = $tag; |
197 | | |
198 | | // Do 'all' actions first |
199 | | if ( isset($wp_filter['all']) ) { |
200 | | $all_args = func_get_args(); |
201 | | _wp_call_all_hook($all_args); |
202 | | } |
203 | | |
204 | | if ( !isset($wp_filter[$tag]) ) { |
205 | | array_pop($wp_current_filter); |
206 | | return $args[0]; |
207 | | } |
208 | | |
209 | | // Sort |
210 | | if ( !isset( $merged_filters[ $tag ] ) ) { |
211 | | ksort($wp_filter[$tag]); |
212 | | $merged_filters[ $tag ] = true; |
213 | | } |
214 | | |
215 | | reset( $wp_filter[ $tag ] ); |
216 | | |
217 | | do { |
218 | | foreach( (array) current($wp_filter[$tag]) as $the_ ) |
219 | | if ( !is_null($the_['function']) ) |
220 | | $args[0] = call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args'])); |
221 | | |
222 | | } while ( next($wp_filter[$tag]) !== false ); |
223 | | |
224 | | array_pop( $wp_current_filter ); |
225 | | |
226 | | return $args[0]; |
227 | | } |
228 | | |
229 | | /** |
423 | | * Execute functions hooked on a specific action hook, specifying arguments in an array. |
424 | | * |
425 | | * @see do_action() This function is identical, but the arguments passed to the |
426 | | * functions hooked to <tt>$tag</tt> are supplied using an array. |
427 | | * |
428 | | * @package WordPress |
429 | | * @subpackage Plugin |
430 | | * @since 2.1 |
431 | | * @global array $wp_filter Stores all of the filters |
432 | | * @global array $wp_actions Increments the amount of times action was triggered. |
433 | | * |
434 | | * @param string $tag The name of the action to be executed. |
435 | | * @param array $args The arguments supplied to the functions hooked to <tt>$tag</tt> |
436 | | * @return null Will return null if $tag does not exist in $wp_filter array |
437 | | */ |
438 | | function do_action_ref_array($tag, $args) { |
439 | | global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter; |
440 | | |
441 | | if ( ! isset($wp_actions) ) |
442 | | $wp_actions = array(); |
443 | | |
444 | | if ( ! isset($wp_actions[$tag]) ) |
445 | | $wp_actions[$tag] = 1; |
446 | | else |
447 | | ++$wp_actions[$tag]; |
448 | | |
449 | | $wp_current_filter[] = $tag; |
450 | | |
451 | | // Do 'all' actions first |
452 | | if ( isset($wp_filter['all']) ) { |
453 | | $all_args = func_get_args(); |
454 | | _wp_call_all_hook($all_args); |
455 | | } |
456 | | |
457 | | if ( !isset($wp_filter[$tag]) ) { |
458 | | array_pop($wp_current_filter); |
459 | | return; |
460 | | } |
461 | | |
462 | | // Sort |
463 | | if ( !isset( $merged_filters[ $tag ] ) ) { |
464 | | ksort($wp_filter[$tag]); |
465 | | $merged_filters[ $tag ] = true; |
466 | | } |
467 | | |
468 | | reset( $wp_filter[ $tag ] ); |
469 | | |
470 | | do { |
471 | | foreach( (array) current($wp_filter[$tag]) as $the_ ) |
472 | | if ( !is_null($the_['function']) ) |
473 | | call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args'])); |
474 | | |
475 | | } while ( next($wp_filter[$tag]) !== false ); |
476 | | |
477 | | array_pop($wp_current_filter); |
478 | | } |
479 | | |
480 | | /** |