current_fiter() from tellyworth. fixes #5232

git-svn-id: http://svn.automattic.com/wordpress/trunk@6318 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2007-11-06 21:38:04 +00:00
parent f1a6553227
commit 0e63de02ca
1 changed files with 26 additions and 6 deletions

View File

@ -107,7 +107,9 @@ function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1)
* @return string The text in <tt>$string</tt> after all hooked functions are applied to it. * @return string The text in <tt>$string</tt> after all hooked functions are applied to it.
*/ */
function apply_filters($tag, $value) { function apply_filters($tag, $value) {
global $wp_filter, $merged_filters; global $wp_filter, $merged_filters, $wp_current_filter;
@$wp_current_filter[] = $tag;
// Do 'all' actions first // Do 'all' actions first
if ( isset($wp_filter['all']) ) { if ( isset($wp_filter['all']) ) {
@ -120,8 +122,10 @@ function apply_filters($tag, $value) {
} while ( next($wp_filter['all']) !== false ); } while ( next($wp_filter['all']) !== false );
} }
if ( !isset($wp_filter[$tag]) ) if ( !isset($wp_filter[$tag]) ) {
array_pop($wp_current_filter);
return $value; return $value;
}
// Sort // Sort
if ( !isset( $merged_filters[ $tag ] ) ) { if ( !isset( $merged_filters[ $tag ] ) ) {
@ -143,6 +147,8 @@ function apply_filters($tag, $value) {
} while ( next($wp_filter[$tag]) !== false ); } while ( next($wp_filter[$tag]) !== false );
array_pop( $wp_current_filter );
return $value; return $value;
} }
@ -181,6 +187,15 @@ function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args
} }
/**
* Return the name of the current filter or action.
*/
function current_filter() {
global $wp_current_filter;
return end( $wp_current_filter );
}
/** /**
* Hooks a function on to a specific action. * Hooks a function on to a specific action.
* *
@ -233,7 +248,7 @@ function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1)
* @return null Will return null if $tag does not exist in $wp_filter array * @return null Will return null if $tag does not exist in $wp_filter array
*/ */
function do_action($tag, $arg = '') { function do_action($tag, $arg = '') {
global $wp_action, $wp_actions; global $wp_action, $wp_actions, $wp_current_filter;
if ( is_array($wp_actions) ) if ( is_array($wp_actions) )
$wp_actions[] = $tag; $wp_actions[] = $tag;
@ -248,6 +263,8 @@ function do_action($tag, $arg = '') {
for ( $a = 2; $a < func_num_args(); $a++ ) for ( $a = 2; $a < func_num_args(); $a++ )
$args[] = func_get_arg($a); $args[] = func_get_arg($a);
@$wp_current_filter[] = $tag;
// Do 'all' actions first // Do 'all' actions first
if ( isset($wp_action['all']) ) { if ( isset($wp_action['all']) ) {
do { do {
@ -258,8 +275,10 @@ function do_action($tag, $arg = '') {
} while ( next($wp_action['all']) !== false ); } while ( next($wp_action['all']) !== false );
} }
if ( !isset($wp_action[$tag]) ) if ( !isset($wp_action[$tag]) ) {
array_pop($wp_current_filter);
return; return;
}
// Sort // Sort
if ( !isset( $merged_actions[ $tag ] ) ) { if ( !isset( $merged_actions[ $tag ] ) ) {
@ -277,6 +296,7 @@ function do_action($tag, $arg = '') {
} while ( next($wp_action[$tag]) !== false ); } while ( next($wp_action[$tag]) !== false );
array_pop($wp_current_filter);
} }
/** /**