Changeset 6316
- Timestamp:
- 11/06/2007 06:31:43 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/plugin.php
r6276 r6316 73 73 global $wp_filter, $merged_filters; 74 74 75 $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority );75 $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority, 'filter'); 76 76 $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args); 77 77 unset( $merged_filters[ $tag ] ); … … 110 110 global $wp_filter, $merged_filters; 111 111 112 if ( !isset( $merged_filters[ $tag ] ) ) 113 merge_filters($tag); 112 // Do 'all' actions first 113 if ( isset($wp_filter['all']) ) { 114 reset( $wp_filter['all'] ); 115 do { 116 foreach ( (array) current($wp_filter['all']) as $the_ ) 117 if ( !is_null($the_['function']) ) 118 $value = call_user_func_array($the_['function'], $value); 119 120 } while ( next($wp_filter['all']) !== false ); 121 } 114 122 115 123 if ( !isset($wp_filter[$tag]) ) 116 124 return $value; 117 125 126 // Sort 127 if ( !isset( $merged_filters[ $tag ] ) ) { 128 reset($wp_filter[$tag]); 129 uksort($wp_filter[$tag], "strnatcasecmp"); 130 $merged_filters[ $tag ] = true; 131 } 132 118 133 reset( $wp_filter[ $tag ] ); 119 134 120 135 $args = func_get_args(); 121 136 122 do {137 do { 123 138 foreach( (array) current($wp_filter[$tag]) as $the_ ) 124 139 if ( !is_null($the_['function']) ){ … … 133 148 134 149 /** 135 * Merge the filter functions of a specific filter hook with generic filter functions.136 *137 * It is possible to defined generic filter functions using the filter hook138 * <em>all</e>. These functions are called for every filter tag. This function139 * merges the functions attached to the <em>all</em> hook with the functions140 * of a specific hook defined by <tt>$tag</tt>.141 *142 * Bugged if you hook into 'all' tag, then you <strong>will</strong> lose all priority143 * information. {@link http://trac.wordpress.org/ticket/4715 Bug #4715} for more information.144 *145 * @package WordPress146 * @subpackage Plugin147 * @since 1.5148 * @global array $wp_filter Stores all of the filters149 * @global array $merge_filters Merges the filter hooks using this function.150 *151 * @param string $tag The filter hook of which the functions should be merged.152 */153 function merge_filters($tag) {154 global $wp_filter, $merged_filters;155 156 if ( isset($wp_filter['all']) && is_array($wp_filter['all']) )157 $wp_filter[$tag] = array_merge($wp_filter['all'], (array) $wp_filter[$tag]);158 159 if ( isset($wp_filter[$tag]) ){160 reset($wp_filter[$tag]);161 uksort($wp_filter[$tag], "strnatcasecmp");162 }163 $merged_filters[ $tag ] = true;164 }165 166 /**167 150 * Removes a function from a specified filter hook. 168 151 * … … 186 169 */ 187 170 function remove_filter($tag, $function_to_remove, $priority = 10, $accepted_args = 1) { 188 $function_to_remove = _wp_filter_build_unique_id($tag, $function_to_remove, $priority );171 $function_to_remove = _wp_filter_build_unique_id($tag, $function_to_remove, $priority, 'filter'); 189 172 190 173 $r = isset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]); 191 174 192 unset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]); 193 unset($GLOBALS['merged_filters'][$tag]); 175 if ( true === $r) { 176 unset($GLOBALS['wp_filter'][$tag][$priority][$function_to_remove]); 177 unset($GLOBALS['merged_filters'][$tag]); 178 } 194 179 195 180 return $r; 196 181 } 182 197 183 198 184 /** … … 216 202 */ 217 203 function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) { 218 add_filter($tag, $function_to_add, $priority, $accepted_args); 219 } 204 global $wp_action, $merged_actions; 205 206 $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority, 'action'); 207 $wp_action[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args); 208 unset( $merged_actions[ $tag ] ); 209 return true; 210 } 211 220 212 221 213 /** … … 242 234 */ 243 235 function do_action($tag, $arg = '') { 244 global $wp_ filter, $wp_actions;236 global $wp_action, $wp_actions; 245 237 246 238 if ( is_array($wp_actions) ) … … 257 249 $args[] = func_get_arg($a); 258 250 259 merge_filters($tag); 260 261 if ( !isset($wp_filter[$tag]) ) 251 // Do 'all' actions first 252 if ( isset($wp_action['all']) ) { 253 do { 254 foreach( (array) current($wp_action['all']) as $the_ ) 255 if ( !is_null($the_['function']) ) 256 call_user_func_array($the_['function'], $args[0]); 257 258 } while ( next($wp_action['all']) !== false ); 259 } 260 261 if ( !isset($wp_action[$tag]) ) 262 262 return; 263 263 264 do{ 265 foreach( (array) current($wp_filter[$tag]) as $the_ ) 264 // Sort 265 if ( !isset( $merged_actions[ $tag ] ) ) { 266 reset($wp_action[$tag]); 267 uksort($wp_action[$tag], "strnatcasecmp"); 268 $merged_actions[ $tag ] = true; 269 } 270 271 reset( $wp_action[ $tag ] ); 272 273 do { 274 foreach ( (array) current($wp_action[$tag]) as $the_ ) 266 275 if ( !is_null($the_['function']) ) 267 276 call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args'])); 268 277 269 } while ( next($wp_ filter[$tag]) !== false );278 } while ( next($wp_action[$tag]) !== false ); 270 279 271 280 } … … 310 319 */ 311 320 function do_action_ref_array($tag, $args) { 312 global $wp_ filter, $wp_actions;321 global $wp_action, $wp_actions; 313 322 314 323 if ( !is_array($wp_actions) ) … … 317 326 $wp_actions[] = $tag; 318 327 319 merge_filters($tag); 320 321 if ( !isset($wp_filter[$tag]) ) 328 // Do 'all' actions first 329 if ( isset($wp_action['all']) ) { 330 do { 331 foreach( (array) current($wp_action['all']) as $the_ ) 332 if ( !is_null($the_['function']) ) 333 call_user_func_array($the_['function'], $args[0]); 334 335 } while ( next($wp_action['all']) !== false ); 336 } 337 338 if ( !isset($wp_action[$tag]) ) 322 339 return; 323 340 324 do{ 325 foreach( (array) current($wp_filter[$tag]) as $the_ ) 341 // Sort 342 if ( !isset( $merged_actions[ $tag ] ) ) { 343 reset($wp_action[$tag]); 344 uksort($wp_action[$tag], "strnatcasecmp"); 345 $merged_actions[ $tag ] = true; 346 } 347 348 reset( $wp_action[ $tag ] ); 349 350 do { 351 foreach( (array) current($wp_action[$tag]) as $the_ ) 326 352 if ( !is_null($the_['function']) ) 327 353 call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args'])); 328 354 329 } while ( next($wp_ filter[$tag]) !== false );355 } while ( next($wp_action[$tag]) !== false ); 330 356 331 357 } … … 351 377 */ 352 378 function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) { 353 return remove_filter($tag, $function_to_remove, $priority, $accepted_args); 379 $function_to_remove = _wp_filter_build_unique_id($tag, $function_to_remove, $priority); 380 381 $r = isset($GLOBALS['wp_action'][$tag][$priority][$function_to_remove]); 382 383 if ( true === $r) { 384 unset($GLOBALS['wp_action'][$tag][$priority][$function_to_remove]); 385 unset($GLOBALS['merged_actions'][$tag]); 386 } 387 388 return $r; 354 389 } 355 390 … … 460 495 * @param string|array $function Used for creating unique id 461 496 * @param int $priority Used in counting how many hooks were applied 497 * @param string $type filter or action 462 498 * @return string Unique ID for usage as array key 463 499 */ 464 function _wp_filter_build_unique_id($tag, $function, $priority = 10)500 function _wp_filter_build_unique_id($tag, $function, $priority, $type) 465 501 { 466 global $wp_filter ;502 global $wp_filter, $wp_action; 467 503 468 504 // If function then just skip all of the tests and not overwrite the following. 469 if ( is_string($function) )505 if ( is_string($function) ) 470 506 return $function; 471 507 // Object Class Calling 472 else if(is_object($function[0]) ) 473 { 508 else if (is_object($function[0]) ) { 474 509 $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 notice 476 $count = count((array)$wp_filter[$tag][$priority]); 510 if ( !isset($function[0]->wp_filter_id) ) { 511 if ( 'filter' == $type ) 512 $count = count((array)$wp_filter[$tag][$priority]); 513 else 514 $count = count((array)$wp_action[$tag][$priority]); 477 515 $function[0]->wp_filter_id = $count; 478 516 $obj_idx .= $count; … … 483 521 } 484 522 // Static Calling 485 else if ( is_string($function[0]) )523 else if ( is_string($function[0]) ) 486 524 return $function[0].$function[1]; 487 525 }
Note: See TracChangeset
for help on using the changeset viewer.