Fix how wp_filter array is keyed. Props santosj/darkdragon. fixes #3875 for 2.3

git-svn-id: https://develop.svn.wordpress.org/trunk@5936 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2007-08-24 14:18:08 +00:00
parent 71252f8eac
commit 73d5479b43
1 changed files with 29 additions and 2 deletions

View File

@ -19,7 +19,9 @@ function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1)
global $wp_filter, $merged_filters;
// So the format is wp_filter['tag']['array of priorities']['array of functions serialized']['array of ['array (functions, accepted_args)]']
$wp_filter[$tag][$priority][serialize($function_to_add)] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
$idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority);
$wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
//$wp_filter[$tag][$priority][serialize($function_to_add)] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
unset( $merged_filters[ $tag ] );
return true;
}
@ -97,7 +99,7 @@ function merge_filters($tag) {
* @return boolean Whether the function is removed.
*/
function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
$function_to_remove = serialize($function_to_remove);
$function_to_remove = _wp_filter_build_unique_id($tag, $function_to_remove, $priority);
$r = isset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]);
@ -281,4 +283,29 @@ function register_deactivation_hook($file, $function) {
add_action('deactivate_' . $file, $function);
}
function _wp_filter_build_unique_id($tag, $function, $priority = 10)
{
global $wp_filter;
// If function then just skip all of the tests and not overwrite the following.
// Static Calling
if( is_string($function) )
return $function;
// Object Class Calling
else if(is_object($function[0]) )
{
$obj_idx = get_class($function[0]).$function[1];
if( is_null($function[0]->wp_filter_id) ) {
$count = count((array)$wp_filter[$tag][$priority]);
$function[0]->wp_filter_id = $count;
$obj_idx .= $count;
unset($count);
} else
$obj_idx .= $function[0]->wp_filter_id;
return $obj_idx;
}
else if( is_string($function[0]) )
return $function[0].$function[1];
}
?>