Changeset 42343 for trunk/src/wp-includes/plugin.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/plugin.php (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/plugin.php
r41751 r42343 34 34 } 35 35 36 if ( ! isset( $wp_actions ) ) 36 if ( ! isset( $wp_actions ) ) { 37 37 $wp_actions = array(); 38 39 if ( ! isset( $wp_current_filter ) ) 38 } 39 40 if ( ! isset( $wp_current_filter ) ) { 40 41 $wp_current_filter = array(); 42 } 41 43 42 44 /** … … 129 131 * return value. 130 132 */ 131 function has_filter( $tag, $function_to_check = false) {133 function has_filter( $tag, $function_to_check = false ) { 132 134 global $wp_filter; 133 135 … … 180 182 181 183 // Do 'all' actions first. 182 if ( isset( $wp_filter['all']) ) {184 if ( isset( $wp_filter['all'] ) ) { 183 185 $wp_current_filter[] = $tag; 186 $args = func_get_args(); 187 _wp_call_all_hook( $args ); 188 } 189 190 if ( ! isset( $wp_filter[ $tag ] ) ) { 191 if ( isset( $wp_filter['all'] ) ) { 192 array_pop( $wp_current_filter ); 193 } 194 return $value; 195 } 196 197 if ( ! isset( $wp_filter['all'] ) ) { 198 $wp_current_filter[] = $tag; 199 } 200 201 if ( empty( $args ) ) { 184 202 $args = func_get_args(); 185 _wp_call_all_hook($args); 186 } 187 188 if ( !isset($wp_filter[$tag]) ) { 189 if ( isset($wp_filter['all']) ) 190 array_pop($wp_current_filter); 191 return $value; 192 } 193 194 if ( !isset($wp_filter['all']) ) 195 $wp_current_filter[] = $tag; 196 197 if ( empty($args) ) 198 $args = func_get_args(); 203 } 199 204 200 205 // don't pass the tag name to WP_Hook … … 223 228 * @return mixed The filtered value after all hooked functions are applied to it. 224 229 */ 225 function apply_filters_ref_array( $tag, $args) {230 function apply_filters_ref_array( $tag, $args ) { 226 231 global $wp_filter, $wp_current_filter; 227 232 228 233 // Do 'all' actions first 229 if ( isset( $wp_filter['all']) ) {234 if ( isset( $wp_filter['all'] ) ) { 230 235 $wp_current_filter[] = $tag; 231 $all_args = func_get_args(); 232 _wp_call_all_hook($all_args); 233 } 234 235 if ( !isset($wp_filter[$tag]) ) { 236 if ( isset($wp_filter['all']) ) 237 array_pop($wp_current_filter); 236 $all_args = func_get_args(); 237 _wp_call_all_hook( $all_args ); 238 } 239 240 if ( ! isset( $wp_filter[ $tag ] ) ) { 241 if ( isset( $wp_filter['all'] ) ) { 242 array_pop( $wp_current_filter ); 243 } 238 244 return $args[0]; 239 245 } 240 246 241 if ( ! isset($wp_filter['all']) )247 if ( ! isset( $wp_filter['all'] ) ) { 242 248 $wp_current_filter[] = $tag; 249 } 243 250 244 251 $filtered = $wp_filter[ $tag ]->apply_filters( $args[0], $args ); … … 297 304 global $wp_filter; 298 305 299 if ( isset( $wp_filter[ $tag ] ) ) {306 if ( isset( $wp_filter[ $tag ] ) ) { 300 307 $wp_filter[ $tag ]->remove_all_filters( $priority ); 301 308 if ( ! $wp_filter[ $tag ]->has_filters() ) { … … 396 403 * @return true Will always return true. 397 404 */ 398 function add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1) {399 return add_filter( $tag, $function_to_add, $priority, $accepted_args);405 function add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) { 406 return add_filter( $tag, $function_to_add, $priority, $accepted_args ); 400 407 } 401 408 … … 419 426 * functions hooked to the action. Default empty. 420 427 */ 421 function do_action( $tag, $arg = '') {428 function do_action( $tag, $arg = '' ) { 422 429 global $wp_filter, $wp_actions, $wp_current_filter; 423 430 424 if ( ! isset($wp_actions[$tag]) ) 425 $wp_actions[$tag] = 1; 426 else 427 ++$wp_actions[$tag]; 431 if ( ! isset( $wp_actions[ $tag ] ) ) { 432 $wp_actions[ $tag ] = 1; 433 } else { 434 ++$wp_actions[ $tag ]; 435 } 428 436 429 437 // Do 'all' actions first 430 if ( isset( $wp_filter['all']) ) {438 if ( isset( $wp_filter['all'] ) ) { 431 439 $wp_current_filter[] = $tag; 432 $all_args = func_get_args(); 433 _wp_call_all_hook($all_args); 434 } 435 436 if ( !isset($wp_filter[$tag]) ) { 437 if ( isset($wp_filter['all']) ) 438 array_pop($wp_current_filter); 440 $all_args = func_get_args(); 441 _wp_call_all_hook( $all_args ); 442 } 443 444 if ( ! isset( $wp_filter[ $tag ] ) ) { 445 if ( isset( $wp_filter['all'] ) ) { 446 array_pop( $wp_current_filter ); 447 } 439 448 return; 440 449 } 441 450 442 if ( ! isset($wp_filter['all']) )451 if ( ! isset( $wp_filter['all'] ) ) { 443 452 $wp_current_filter[] = $tag; 453 } 444 454 445 455 $args = array(); 446 if ( is_array( $arg) && 1 == count($arg) && isset($arg[0]) && is_object($arg[0]) )// array(&$this)456 if ( is_array( $arg ) && 1 == count( $arg ) && isset( $arg[0] ) && is_object( $arg[0] ) ) { // array(&$this) 447 457 $args[] =& $arg[0]; 448 else458 } else { 449 459 $args[] = $arg; 450 for ( $a = 2, $num = func_num_args(); $a < $num; $a++ ) 451 $args[] = func_get_arg($a); 460 } 461 for ( $a = 2, $num = func_num_args(); $a < $num; $a++ ) { 462 $args[] = func_get_arg( $a ); 463 } 452 464 453 465 $wp_filter[ $tag ]->do_action( $args ); 454 466 455 array_pop( $wp_current_filter);467 array_pop( $wp_current_filter ); 456 468 } 457 469 … … 466 478 * @return int The number of times action hook $tag is fired. 467 479 */ 468 function did_action( $tag) {480 function did_action( $tag ) { 469 481 global $wp_actions; 470 482 471 if ( ! isset( $wp_actions[ $tag ] ) ) 483 if ( ! isset( $wp_actions[ $tag ] ) ) { 472 484 return 0; 473 474 return $wp_actions[$tag]; 485 } 486 487 return $wp_actions[ $tag ]; 475 488 } 476 489 … … 489 502 * @param array $args The arguments supplied to the functions hooked to `$tag`. 490 503 */ 491 function do_action_ref_array( $tag, $args) {504 function do_action_ref_array( $tag, $args ) { 492 505 global $wp_filter, $wp_actions, $wp_current_filter; 493 506 494 if ( ! isset($wp_actions[$tag]) ) 495 $wp_actions[$tag] = 1; 496 else 497 ++$wp_actions[$tag]; 507 if ( ! isset( $wp_actions[ $tag ] ) ) { 508 $wp_actions[ $tag ] = 1; 509 } else { 510 ++$wp_actions[ $tag ]; 511 } 498 512 499 513 // Do 'all' actions first 500 if ( isset( $wp_filter['all']) ) {514 if ( isset( $wp_filter['all'] ) ) { 501 515 $wp_current_filter[] = $tag; 502 $all_args = func_get_args(); 503 _wp_call_all_hook($all_args); 504 } 505 506 if ( !isset($wp_filter[$tag]) ) { 507 if ( isset($wp_filter['all']) ) 508 array_pop($wp_current_filter); 516 $all_args = func_get_args(); 517 _wp_call_all_hook( $all_args ); 518 } 519 520 if ( ! isset( $wp_filter[ $tag ] ) ) { 521 if ( isset( $wp_filter['all'] ) ) { 522 array_pop( $wp_current_filter ); 523 } 509 524 return; 510 525 } 511 526 512 if ( ! isset($wp_filter['all']) )527 if ( ! isset( $wp_filter['all'] ) ) { 513 528 $wp_current_filter[] = $tag; 529 } 514 530 515 531 $wp_filter[ $tag ]->do_action( $args ); 516 532 517 array_pop( $wp_current_filter);533 array_pop( $wp_current_filter ); 518 534 } 519 535 … … 534 550 * return value. 535 551 */ 536 function has_action( $tag, $function_to_check = false) {537 return has_filter( $tag, $function_to_check);552 function has_action( $tag, $function_to_check = false ) { 553 return has_filter( $tag, $function_to_check ); 538 554 } 539 555 … … 565 581 * @return true True when finished. 566 582 */ 567 function remove_all_actions( $tag, $priority = false) {568 return remove_all_filters( $tag, $priority);583 function remove_all_actions( $tag, $priority = false ) { 584 return remove_all_filters( $tag, $priority ); 569 585 } 570 586 … … 661 677 } 662 678 663 $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );679 $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR ); 664 680 $mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR ); 665 681 666 $file = preg_replace( '#^' . preg_quote($plugin_dir, '#') . '/|^' . preg_quote($mu_plugin_dir, '#') . '/#','',$file); // get relative path from plugins dir667 $file = trim( $file, '/');682 $file = preg_replace( '#^' . preg_quote( $plugin_dir, '#' ) . '/|^' . preg_quote( $mu_plugin_dir, '#' ) . '/#', '', $file ); // get relative path from plugins dir 683 $file = trim( $file, '/' ); 668 684 return $file; 669 685 } … … 692 708 static $wp_plugin_path = null, $wpmu_plugin_path = null; 693 709 if ( ! isset( $wp_plugin_path ) ) { 694 $wp_plugin_path = wp_normalize_path( WP_PLUGIN_DIR );710 $wp_plugin_path = wp_normalize_path( WP_PLUGIN_DIR ); 695 711 $wpmu_plugin_path = wp_normalize_path( WPMU_PLUGIN_DIR ); 696 712 } 697 713 698 $plugin_path = wp_normalize_path( dirname( $file ) );714 $plugin_path = wp_normalize_path( dirname( $file ) ); 699 715 $plugin_realpath = wp_normalize_path( dirname( realpath( $file ) ) ); 700 716 … … 752 768 * @param callable $function The function hooked to the 'activate_PLUGIN' action. 753 769 */ 754 function register_activation_hook( $file, $function) {755 $file = plugin_basename( $file);756 add_action( 'activate_' . $file, $function);770 function register_activation_hook( $file, $function ) { 771 $file = plugin_basename( $file ); 772 add_action( 'activate_' . $file, $function ); 757 773 } 758 774 … … 775 791 * @param callable $function The function hooked to the 'deactivate_PLUGIN' action. 776 792 */ 777 function register_deactivation_hook( $file, $function) {778 $file = plugin_basename( $file);779 add_action( 'deactivate_' . $file, $function);793 function register_deactivation_hook( $file, $function ) { 794 $file = plugin_basename( $file ); 795 add_action( 'deactivate_' . $file, $function ); 780 796 } 781 797 … … 817 833 * uninstalling the plugin. 818 834 */ 819 $uninstallable_plugins = (array) get_option('uninstall_plugins');820 $uninstallable_plugins[ plugin_basename($file)] = $callback;821 822 update_option( 'uninstall_plugins', $uninstallable_plugins);835 $uninstallable_plugins = (array) get_option( 'uninstall_plugins' ); 836 $uninstallable_plugins[ plugin_basename( $file ) ] = $callback; 837 838 update_option( 'uninstall_plugins', $uninstallable_plugins ); 823 839 } 824 840 … … 841 857 * @param array $args The collected parameters from the hook that was called. 842 858 */ 843 function _wp_call_all_hook( $args) {859 function _wp_call_all_hook( $args ) { 844 860 global $wp_filter; 845 861 … … 881 897 * a unique id. 882 898 */ 883 function _wp_filter_build_unique_id( $tag, $function, $priority) {899 function _wp_filter_build_unique_id( $tag, $function, $priority ) { 884 900 global $wp_filter; 885 901 static $filter_id_count = 0; 886 902 887 if ( is_string( $function) )903 if ( is_string( $function ) ) { 888 904 return $function; 889 890 if ( is_object($function) ) { 905 } 906 907 if ( is_object( $function ) ) { 891 908 // Closures are currently implemented as objects 892 909 $function = array( $function, '' ); … … 895 912 } 896 913 897 if ( is_object($function[0]) ) {914 if ( is_object( $function[0] ) ) { 898 915 // Object Class Calling 899 if ( function_exists( 'spl_object_hash') ) {900 return spl_object_hash( $function[0]) . $function[1];916 if ( function_exists( 'spl_object_hash' ) ) { 917 return spl_object_hash( $function[0] ) . $function[1]; 901 918 } else { 902 $obj_idx = get_class( $function[0]).$function[1];903 if ( ! isset($function[0]->wp_filter_id) ) {904 if ( false === $priority ) 919 $obj_idx = get_class( $function[0] ) . $function[1]; 920 if ( ! isset( $function[0]->wp_filter_id ) ) { 921 if ( false === $priority ) { 905 922 return false; 906 $obj_idx .= isset($wp_filter[$tag][$priority]) ? count((array)$wp_filter[$tag][$priority]) : $filter_id_count; 923 } 924 $obj_idx .= isset( $wp_filter[ $tag ][ $priority ] ) ? count( (array) $wp_filter[ $tag ][ $priority ] ) : $filter_id_count; 907 925 $function[0]->wp_filter_id = $filter_id_count; 908 926 ++$filter_id_count;
Note: See TracChangeset
for help on using the changeset viewer.