Make WordPress Core

Ticket #3875: wp-includes.plugin.php.2.diff

File wp-includes.plugin.php.2.diff, 2.4 KB (added by santosj, 16 years ago)

Fixes issues in previous diff, overwriting.

  • plugin.php

     
    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        $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority);
     23        $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
     24        //$wp_filter[$tag][$priority][serialize($function_to_add)] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
    2325        unset( $merged_filters[ $tag ] );
    2426        return true;
    2527}
     
    9799 * @return boolean Whether the function is removed.
    98100 */
    99101function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {
    100         $function_to_remove = serialize($function_to_remove);
     102        $function_to_remove = _wp_filter_build_unique_id($tag, &$function_to_remove, $priority);
    101103
    102104        $r = isset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]);
    103105
     
    280282        add_action('deactivate_' . $file, $function);
    281283}
    282284
     285function _wp_filter_build_unique_id($tag, $function, $priority = 10)
     286{
     287        global $wp_filter;
     288       
     289        // If function then just skip all of the tests and not overwrite the following.
     290        if(is_string($function))
     291                return $function;
     292       
     293        $fn_idx = '';
     294       
     295        // Only test if using an array to call a class and method.
     296        // Else bypass all of the following checks.
     297        if(is_array($function))
     298        {
     299                // Expect most use cases for $obj to be objects and not strings
     300                if(is_object($function[0]))
     301                {
     302                        // We are going to use $classname more than once, store it
     303                        $classname = get_class($function[0]);
     304                        $fn_idx = $classname.$function[1];
     305                       
     306                        if(true === array_key_exists('wp_filter_id', get_object_vars($function[0])))
     307                        {
     308                                $fn_idx .= $function[0]->wp_filter_id;
     309                        }
     310                        else
     311                        {
     312                                if(isset($wp_filter[$tag]))
     313                                        $i = count($wp_filter[$tag][$priority]);
     314                                else
     315                                        $i = 0;
     316                                $function[0]->wp_filter_id = $i;
     317                                $fn_idx .= $function[0]->wp_filter_id;
     318                        }
     319                }
     320                // Must mean that it is using static calling.
     321                else
     322                        $fn_idx = $function[0].$function[1];
     323        }
     324        return $fn_idx;
     325}
     326
    283327?>