Skip to content

Commit 7b43eae

Browse files
committed
Fix how wp_filter array is keyed. Props santosj/darkdragon. fixes WordPress#3875 for 2.2
git-svn-id: https://develop.svn.wordpress.org/branches/2.2@6014 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 8d39457 commit 7b43eae

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

wp-includes/plugin.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1)
1919
global $wp_filter, $merged_filters;
2020

2121
// So the format is wp_filter['tag']['array of priorities']['array of functions serialized']['array of ['array (functions, accepted_args)]']
22-
$wp_filter[$tag][$priority][serialize($function_to_add)] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
22+
$wp_filter[$tag][$priority][_wp_filter_build_unique_id($tag, $function_to_add, $priority)] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
2323
unset( $merged_filters[ $tag ] );
2424
return true;
2525
}
@@ -98,8 +98,8 @@ function merge_filters($tag) {
9898
*/
9999
function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
100100
global $wp_filter, $merged_filters;
101-
102-
unset($GLOBALS['wp_filter'][$tag][$priority][serialize($function_to_remove)]);
101+
102+
unset($GLOBALS['wp_filter'][$tag][$priority][_wp_filter_build_unique_id($tag, $function_to_remove, $priority)]);
103103
unset( $merged_filters[ $tag ] );
104104

105105
return true;
@@ -279,4 +279,29 @@ function register_deactivation_hook($file, $function) {
279279
add_action('deactivate_' . $file, $function);
280280
}
281281

282+
function _wp_filter_build_unique_id($tag, $function, $priority = 10)
283+
{
284+
global $wp_filter;
285+
286+
// If function then just skip all of the tests and not overwrite the following.
287+
if( is_string($function) )
288+
return $function;
289+
// Object Class Calling
290+
else if(is_object($function[0]) )
291+
{
292+
$obj_idx = get_class($function[0]).$function[1];
293+
if( is_null($function[0]->wp_filter_id) ) {
294+
$count = count((array)$wp_filter[$tag][$priority]);
295+
$function[0]->wp_filter_id = $count;
296+
$obj_idx .= $count;
297+
unset($count);
298+
} else
299+
$obj_idx .= $function[0]->wp_filter_id;
300+
return $obj_idx;
301+
}
302+
// Static Calling
303+
else if( is_string($function[0]) )
304+
return $function[0].$function[1];
305+
}
306+
282307
?>

0 commit comments

Comments
 (0)