Ticket #5231: plugin.#5231.r6311.diff
File plugin.#5231.r6311.diff, 3.9 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 merge_filters($tag, 'action'); 260 274 261 275 if ( !isset($wp_filter[$tag]) ) 262 276 return; … … 316 330 else 317 331 $wp_actions[] = $tag; 318 332 319 merge_filters($tag );333 merge_filters($tag, 'action'); 320 334 321 335 if ( !isset($wp_filter[$tag]) ) 322 336 return; … … 350 364 * @return boolean Whether the function is removed. 351 365 */ 352 366 function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) { 367 if($tag == 'all') 368 $tag = 'all_action'; 369 353 370 return remove_filter($tag, $function_to_remove, $priority, $accepted_args); 354 371 } 355 372 … … 461 478 * @param int $priority Used in counting how many hooks were applied 462 479 * @return string Unique ID for usage as array key 463 480 */ 464 function _wp_filter_build_unique_id($tag, $function, $priority = 10) 465 { 481 function _wp_filter_build_unique_id($tag, $function, $priority = 10) { 466 482 global $wp_filter; 467 483 468 484 // If function then just skip all of the tests and not overwrite the following. … … 472 488 else if(is_object($function[0]) ) 473 489 { 474 490 $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 notice491 if( !isset($function[0]->wp_filter_id) ) { 476 492 $count = count((array)$wp_filter[$tag][$priority]); 477 493 $function[0]->wp_filter_id = $count; 478 494 $obj_idx .= $count;