Ticket #5231: plugin.#5231.r6312.diff
File plugin.#5231.r6312.diff, 4.0 KB (added by , 17 years ago) |
---|
-
plugin.php
72 72 function add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1) { 73 73 global $wp_filter, $merged_filters; 74 74 75 // If all tag was added by action, this won't match. 76 if($tag == 'all') 77 $tag = 'all_filter'; 78 75 79 $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority); 76 80 $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args); 77 81 unset( $merged_filters[ $tag ] ); … … 110 114 global $wp_filter, $merged_filters; 111 115 112 116 if ( !isset( $merged_filters[ $tag ] ) ) 113 merge_filters($tag );117 merge_filters($tag, 'filter'); 114 118 115 119 if ( !isset($wp_filter[$tag]) ) 116 120 return $value; … … 149 153 * @global array $merge_filters Merges the filter hooks using this function. 150 154 * 151 155 * @param string $tag The filter hook of which the functions should be merged. 156 * @param string $caller Whether the caller is a 'filter' or 'action' 152 157 */ 153 function merge_filters($tag ) {158 function merge_filters($tag, $caller='filter') { 154 159 global $wp_filter, $merged_filters; 155 160 156 if ( isset($wp_filter['all']) && is_array($wp_filter['all']) ) 157 $wp_filter[$tag] = array_merge($wp_filter['all'], (array) $wp_filter[$tag]); 161 $all = 'all_'.$caller; 162 if ( isset($wp_filter[$all]) && is_array($wp_filter[$all]) ) 163 $wp_filter[$tag] = $wp_filter[$all] + (array) $wp_filter[$tag]; 158 164 159 165 if ( isset($wp_filter[$tag]) ){ 160 166 reset($wp_filter[$tag]); … … 185 191 * @return boolean Whether the function existed before it was removed. 186 192 */ 187 193 function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) { 194 if($tag == 'all') 195 $tag = 'all_filter'; 196 188 197 $function_to_remove = _wp_filter_build_unique_id($tag, $function_to_remove, $priority); 189 198 190 199 $r = isset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]); 191 200 201 $GLOBALS['wp_filter'][$tag][$priority][$function_to_remove] = array(); 192 202 unset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]); 203 $GLOBALS['merged_filters'][$tag] = array(); 193 204 unset($GLOBALS['merged_filters'][$tag]); 194 205 195 206 return $r; … … 215 226 * @param int $accepted_args optional. The number of arguments the function accept (default 1). 216 227 */ 217 228 function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) { 229 if($tag == 'all') 230 $tag = 'all_action'; 231 218 232 add_filter($tag, $function_to_add, $priority, $accepted_args); 219 233 } 220 234 … … 256 270 for ( $a = 2; $a < func_num_args(); $a++ ) 257 271 $args[] = func_get_arg($a); 258 272 259 merge_filters($tag); 273 if ( !isset( $merged_filters[ $tag ] ) ) 274 merge_filters($tag, 'action'); 260 275 261 276 if ( !isset($wp_filter[$tag]) ) 262 277 return; … … 316 331 else 317 332 $wp_actions[] = $tag; 318 333 319 merge_filters($tag); 334 if ( !isset( $merged_filters[ $tag ] ) ) 335 merge_filters($tag, 'action'); 320 336 321 337 if ( !isset($wp_filter[$tag]) ) 322 338 return; … … 350 366 * @return boolean Whether the function is removed. 351 367 */ 352 368 function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) { 369 if($tag == 'all') 370 $tag = 'all_action'; 371 353 372 return remove_filter($tag, $function_to_remove, $priority, $accepted_args); 354 373 } 355 374 … … 461 480 * @param int $priority Used in counting how many hooks were applied 462 481 * @return string Unique ID for usage as array key 463 482 */ 464 function _wp_filter_build_unique_id($tag, $function, $priority = 10) 465 { 483 function _wp_filter_build_unique_id($tag, $function, $priority = 10) { 466 484 global $wp_filter; 467 485 468 486 // If function then just skip all of the tests and not overwrite the following. … … 472 490 else if(is_object($function[0]) ) 473 491 { 474 492 $obj_idx = get_class($function[0]).$function[1]; 475 if( is_null($function[0]->wp_filter_id) ) { // This should be instead of is_null() change to !isset() to fix notice493 if( !isset($function[0]->wp_filter_id) ) { 476 494 $count = count((array)$wp_filter[$tag][$priority]); 477 495 $function[0]->wp_filter_id = $count; 478 496 $obj_idx .= $count;