Ticket #3875: wp-includes.plugin.php.diff
File wp-includes.plugin.php.diff, 3.8 KB (added by , 16 years ago) |
---|
-
plugin.php
15 15 * @param int $accepted_args optional. The number of arguments the function accept (default 1). In WordPress 1.5.1+, hooked functions can take extra arguments that are set when the matching do_action() or apply_filters() call is run. 16 16 * @return boolean true if the <tt>$function_to_add</tt> is added succesfully to filter <tt>$tag</tt>. How many arguments your function takes. In WordPress 1.5.1+, hooked functions can take extra arguments that are set when the matching <tt>do_action()</tt> or <tt>apply_filters()</tt> call is run. For example, the action <tt>comment_id_not_found</tt> will pass any functions that hook onto it the ID of the requested comment. 17 17 */ 18 function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) {18 function add_filter($tag, &$function_to_add, $priority = 10, $accepted_args = 1) { 19 19 global $wp_filter, $merged_filters; 20 20 21 21 // 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 $fn_idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority); 23 24 $wp_filter[$tag][$priority][$fn_idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args); 25 //$wp_filter[$tag][$priority][serialize($function_to_add)] = array('function' => $function_to_add, 'accepted_args' => $accepted_args); 23 26 unset( $merged_filters[ $tag ] ); 24 27 return true; 25 28 } … … 97 100 * @return boolean Whether the function is removed. 98 101 */ 99 102 function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) { 100 $function_to_remove = serialize($function_to_remove);103 $function_to_remove = _wp_filter_build_unique_id($tag, &$function_to_remove, $priority); 101 104 102 105 $r = isset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]); 103 106 … … 280 283 add_action('deactivate_' . $file, $function); 281 284 } 282 285 286 function _wp_filter_build_unique_id($tag, &$function_to_add, $priority = 10) 287 { 288 global $wp_filter; 289 // If function then just skip all of the tests and not overwrite the following. 290 $fn_idx = $function_to_add; 291 292 // Only test if using an array to call a class and method. 293 // Else bypass all of the following checks. 294 if(is_array($function_to_add)) 295 { 296 list($obj,$fn) = $function_to_add; 297 298 // Expect most use cases for $obj to be objects and not strings 299 if(is_object($obj)) 300 { 301 // We are going to use $classname more than once, store it 302 $classname = get_class($obj); 303 $fn_idx = $classname.$fn; 304 305 if(!is_null($function_to_add[0]->wp_filter_id)) 306 { 307 $fn_idx .= $function_to_add[0]->wp_filter_id; 308 } 309 310 // Compare the two object references to see if they are the same object. 311 // This is slow however as it will check each property and method for similar, much 312 // like an array comparsion. Should work similar to PHP 4 and PHP 5. 313 if($function_to_add[0] == $wp_filter[$tag][$priority][$fn_idx]['function'][0]) { 314 return $fn_idx; // Do not add 315 } else { 316 $i = count($wp_filter[$tag][$priority]); 317 $function_to_add[0]->wp_filter_id = $i; 318 $fn_idx .= $function_to_add[0]->wp_filter_id; 319 } 320 } 321 // Must mean that it is using static calling. 322 // We can also assume that if they are using static calling 323 // it doesn't matter if they have two or more variables that they are trying 324 // to add to the same hooks. The bug would be theirs, we can only assume 325 // that they know enough when doing static method call binding to know what 326 // to expect. 327 else 328 $fn_idx = $obj.fn; 329 } 330 return $fn_idx; 331 } 332 283 333 ?>