wp/wp-includes/plugin.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    31 	$wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
    31 	$wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter );
    32 } else {
    32 } else {
    33 	$wp_filter = array();
    33 	$wp_filter = array();
    34 }
    34 }
    35 
    35 
    36 if ( ! isset( $wp_actions ) )
    36 if ( ! isset( $wp_actions ) ) {
    37 	$wp_actions = array();
    37 	$wp_actions = array();
    38 
    38 }
    39 if ( ! isset( $wp_current_filter ) )
    39 
       
    40 if ( ! isset( $wp_current_filter ) ) {
    40 	$wp_current_filter = array();
    41 	$wp_current_filter = array();
       
    42 }
    41 
    43 
    42 /**
    44 /**
    43  * Hook a function or method to a specific filter action.
    45  * Hook a function or method to a specific filter action.
    44  *
    46  *
    45  * WordPress offers filter hooks to allow plugins to modify
    47  * WordPress offers filter hooks to allow plugins to modify
   126  *                   hook is returned, or false if the function is not attached. When using the
   128  *                   hook is returned, or false if the function is not attached. When using the
   127  *                   $function_to_check argument, this function may return a non-boolean value
   129  *                   $function_to_check argument, this function may return a non-boolean value
   128  *                   that evaluates to false (e.g.) 0, so use the === operator for testing the
   130  *                   that evaluates to false (e.g.) 0, so use the === operator for testing the
   129  *                   return value.
   131  *                   return value.
   130  */
   132  */
   131 function has_filter($tag, $function_to_check = false) {
   133 function has_filter( $tag, $function_to_check = false ) {
   132 	global $wp_filter;
   134 	global $wp_filter;
   133 
   135 
   134 	if ( ! isset( $wp_filter[ $tag ] ) ) {
   136 	if ( ! isset( $wp_filter[ $tag ] ) ) {
   135 		return false;
   137 		return false;
   136 	}
   138 	}
   177 	global $wp_filter, $wp_current_filter;
   179 	global $wp_filter, $wp_current_filter;
   178 
   180 
   179 	$args = array();
   181 	$args = array();
   180 
   182 
   181 	// Do 'all' actions first.
   183 	// Do 'all' actions first.
   182 	if ( isset($wp_filter['all']) ) {
   184 	if ( isset( $wp_filter['all'] ) ) {
   183 		$wp_current_filter[] = $tag;
   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 		$args = func_get_args();
   202 		$args = func_get_args();
   185 		_wp_call_all_hook($args);
   203 	}
   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();
       
   199 
   204 
   200 	// don't pass the tag name to WP_Hook
   205 	// don't pass the tag name to WP_Hook
   201 	array_shift( $args );
   206 	array_shift( $args );
   202 
   207 
   203 	$filtered = $wp_filter[ $tag ]->apply_filters( $value, $args );
   208 	$filtered = $wp_filter[ $tag ]->apply_filters( $value, $args );
   220  *
   225  *
   221  * @param string $tag  The name of the filter hook.
   226  * @param string $tag  The name of the filter hook.
   222  * @param array  $args The arguments supplied to the functions hooked to $tag.
   227  * @param array  $args The arguments supplied to the functions hooked to $tag.
   223  * @return mixed The filtered value after all hooked functions are applied to it.
   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 	global $wp_filter, $wp_current_filter;
   231 	global $wp_filter, $wp_current_filter;
   227 
   232 
   228 	// Do 'all' actions first
   233 	// Do 'all' actions first
   229 	if ( isset($wp_filter['all']) ) {
   234 	if ( isset( $wp_filter['all'] ) ) {
   230 		$wp_current_filter[] = $tag;
   235 		$wp_current_filter[] = $tag;
   231 		$all_args = func_get_args();
   236 		$all_args            = func_get_args();
   232 		_wp_call_all_hook($all_args);
   237 		_wp_call_all_hook( $all_args );
   233 	}
   238 	}
   234 
   239 
   235 	if ( !isset($wp_filter[$tag]) ) {
   240 	if ( ! isset( $wp_filter[ $tag ] ) ) {
   236 		if ( isset($wp_filter['all']) )
   241 		if ( isset( $wp_filter['all'] ) ) {
   237 			array_pop($wp_current_filter);
   242 			array_pop( $wp_current_filter );
       
   243 		}
   238 		return $args[0];
   244 		return $args[0];
   239 	}
   245 	}
   240 
   246 
   241 	if ( !isset($wp_filter['all']) )
   247 	if ( ! isset( $wp_filter['all'] ) ) {
   242 		$wp_current_filter[] = $tag;
   248 		$wp_current_filter[] = $tag;
       
   249 	}
   243 
   250 
   244 	$filtered = $wp_filter[ $tag ]->apply_filters( $args[0], $args );
   251 	$filtered = $wp_filter[ $tag ]->apply_filters( $args[0], $args );
   245 
   252 
   246 	array_pop( $wp_current_filter );
   253 	array_pop( $wp_current_filter );
   247 
   254 
   294  * @return true True when finished.
   301  * @return true True when finished.
   295  */
   302  */
   296 function remove_all_filters( $tag, $priority = false ) {
   303 function remove_all_filters( $tag, $priority = false ) {
   297 	global $wp_filter;
   304 	global $wp_filter;
   298 
   305 
   299 	if ( isset( $wp_filter[ $tag ]) ) {
   306 	if ( isset( $wp_filter[ $tag ] ) ) {
   300 		$wp_filter[ $tag ]->remove_all_filters( $priority );
   307 		$wp_filter[ $tag ]->remove_all_filters( $priority );
   301 		if ( ! $wp_filter[ $tag ]->has_filters() ) {
   308 		if ( ! $wp_filter[ $tag ]->has_filters() ) {
   302 			unset( $wp_filter[ $tag ] );
   309 			unset( $wp_filter[ $tag ] );
   303 		}
   310 		}
   304 	}
   311 	}
   393  *                                  and functions with the same priority are executed
   400  *                                  and functions with the same priority are executed
   394  *                                  in the order in which they were added to the action.
   401  *                                  in the order in which they were added to the action.
   395  * @param int      $accepted_args   Optional. The number of arguments the function accepts. Default 1.
   402  * @param int      $accepted_args   Optional. The number of arguments the function accepts. Default 1.
   396  * @return true Will always return true.
   403  * @return true Will always return true.
   397  */
   404  */
   398 function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
   405 function add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
   399 	return add_filter($tag, $function_to_add, $priority, $accepted_args);
   406 	return add_filter( $tag, $function_to_add, $priority, $accepted_args );
   400 }
   407 }
   401 
   408 
   402 /**
   409 /**
   403  * Execute functions hooked on a specific action hook.
   410  * Execute functions hooked on a specific action hook.
   404  *
   411  *
   416  *
   423  *
   417  * @param string $tag     The name of the action to be executed.
   424  * @param string $tag     The name of the action to be executed.
   418  * @param mixed  $arg,... Optional. Additional arguments which are passed on to the
   425  * @param mixed  $arg,... Optional. Additional arguments which are passed on to the
   419  *                        functions hooked to the action. Default empty.
   426  *                        functions hooked to the action. Default empty.
   420  */
   427  */
   421 function do_action($tag, $arg = '') {
   428 function do_action( $tag, $arg = '' ) {
   422 	global $wp_filter, $wp_actions, $wp_current_filter;
   429 	global $wp_filter, $wp_actions, $wp_current_filter;
   423 
   430 
   424 	if ( ! isset($wp_actions[$tag]) )
   431 	if ( ! isset( $wp_actions[ $tag ] ) ) {
   425 		$wp_actions[$tag] = 1;
   432 		$wp_actions[ $tag ] = 1;
   426 	else
   433 	} else {
   427 		++$wp_actions[$tag];
   434 		++$wp_actions[ $tag ];
       
   435 	}
   428 
   436 
   429 	// Do 'all' actions first
   437 	// Do 'all' actions first
   430 	if ( isset($wp_filter['all']) ) {
   438 	if ( isset( $wp_filter['all'] ) ) {
   431 		$wp_current_filter[] = $tag;
   439 		$wp_current_filter[] = $tag;
   432 		$all_args = func_get_args();
   440 		$all_args            = func_get_args();
   433 		_wp_call_all_hook($all_args);
   441 		_wp_call_all_hook( $all_args );
   434 	}
   442 	}
   435 
   443 
   436 	if ( !isset($wp_filter[$tag]) ) {
   444 	if ( ! isset( $wp_filter[ $tag ] ) ) {
   437 		if ( isset($wp_filter['all']) )
   445 		if ( isset( $wp_filter['all'] ) ) {
   438 			array_pop($wp_current_filter);
   446 			array_pop( $wp_current_filter );
       
   447 		}
   439 		return;
   448 		return;
   440 	}
   449 	}
   441 
   450 
   442 	if ( !isset($wp_filter['all']) )
   451 	if ( ! isset( $wp_filter['all'] ) ) {
   443 		$wp_current_filter[] = $tag;
   452 		$wp_current_filter[] = $tag;
       
   453 	}
   444 
   454 
   445 	$args = array();
   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 		$args[] =& $arg[0];
   457 		$args[] =& $arg[0];
   448 	else
   458 	} else {
   449 		$args[] = $arg;
   459 		$args[] = $arg;
   450 	for ( $a = 2, $num = func_num_args(); $a < $num; $a++ )
   460 	}
   451 		$args[] = func_get_arg($a);
   461 	for ( $a = 2, $num = func_num_args(); $a < $num; $a++ ) {
       
   462 		$args[] = func_get_arg( $a );
       
   463 	}
   452 
   464 
   453 	$wp_filter[ $tag ]->do_action( $args );
   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 
   458 /**
   470 /**
   459  * Retrieve the number of times an action is fired.
   471  * Retrieve the number of times an action is fired.
   460  *
   472  *
   463  * @global array $wp_actions Increments the amount of times action was triggered.
   475  * @global array $wp_actions Increments the amount of times action was triggered.
   464  *
   476  *
   465  * @param string $tag The name of the action hook.
   477  * @param string $tag The name of the action hook.
   466  * @return int The number of times action hook $tag is fired.
   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 	global $wp_actions;
   481 	global $wp_actions;
   470 
   482 
   471 	if ( ! isset( $wp_actions[ $tag ] ) )
   483 	if ( ! isset( $wp_actions[ $tag ] ) ) {
   472 		return 0;
   484 		return 0;
   473 
   485 	}
   474 	return $wp_actions[$tag];
   486 
       
   487 	return $wp_actions[ $tag ];
   475 }
   488 }
   476 
   489 
   477 /**
   490 /**
   478  * Execute functions hooked on a specific action hook, specifying arguments in an array.
   491  * Execute functions hooked on a specific action hook, specifying arguments in an array.
   479  *
   492  *
   486  * @global array $wp_current_filter Stores the list of current filters with the current one last
   499  * @global array $wp_current_filter Stores the list of current filters with the current one last
   487  *
   500  *
   488  * @param string $tag  The name of the action to be executed.
   501  * @param string $tag  The name of the action to be executed.
   489  * @param array  $args The arguments supplied to the functions hooked to `$tag`.
   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 	global $wp_filter, $wp_actions, $wp_current_filter;
   505 	global $wp_filter, $wp_actions, $wp_current_filter;
   493 
   506 
   494 	if ( ! isset($wp_actions[$tag]) )
   507 	if ( ! isset( $wp_actions[ $tag ] ) ) {
   495 		$wp_actions[$tag] = 1;
   508 		$wp_actions[ $tag ] = 1;
   496 	else
   509 	} else {
   497 		++$wp_actions[$tag];
   510 		++$wp_actions[ $tag ];
       
   511 	}
   498 
   512 
   499 	// Do 'all' actions first
   513 	// Do 'all' actions first
   500 	if ( isset($wp_filter['all']) ) {
   514 	if ( isset( $wp_filter['all'] ) ) {
   501 		$wp_current_filter[] = $tag;
   515 		$wp_current_filter[] = $tag;
   502 		$all_args = func_get_args();
   516 		$all_args            = func_get_args();
   503 		_wp_call_all_hook($all_args);
   517 		_wp_call_all_hook( $all_args );
   504 	}
   518 	}
   505 
   519 
   506 	if ( !isset($wp_filter[$tag]) ) {
   520 	if ( ! isset( $wp_filter[ $tag ] ) ) {
   507 		if ( isset($wp_filter['all']) )
   521 		if ( isset( $wp_filter['all'] ) ) {
   508 			array_pop($wp_current_filter);
   522 			array_pop( $wp_current_filter );
       
   523 		}
   509 		return;
   524 		return;
   510 	}
   525 	}
   511 
   526 
   512 	if ( !isset($wp_filter['all']) )
   527 	if ( ! isset( $wp_filter['all'] ) ) {
   513 		$wp_current_filter[] = $tag;
   528 		$wp_current_filter[] = $tag;
       
   529 	}
   514 
   530 
   515 	$wp_filter[ $tag ]->do_action( $args );
   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 
   520 /**
   536 /**
   521  * Check if any action has been registered for a hook.
   537  * Check if any action has been registered for a hook.
   522  *
   538  *
   531  *                  hook is returned, or false if the function is not attached. When using the
   547  *                  hook is returned, or false if the function is not attached. When using the
   532  *                  $function_to_check argument, this function may return a non-boolean value
   548  *                  $function_to_check argument, this function may return a non-boolean value
   533  *                  that evaluates to false (e.g.) 0, so use the === operator for testing the
   549  *                  that evaluates to false (e.g.) 0, so use the === operator for testing the
   534  *                  return value.
   550  *                  return value.
   535  */
   551  */
   536 function has_action($tag, $function_to_check = false) {
   552 function has_action( $tag, $function_to_check = false ) {
   537 	return has_filter($tag, $function_to_check);
   553 	return has_filter( $tag, $function_to_check );
   538 }
   554 }
   539 
   555 
   540 /**
   556 /**
   541  * Removes a function from a specified action hook.
   557  * Removes a function from a specified action hook.
   542  *
   558  *
   562  *
   578  *
   563  * @param string   $tag      The action to remove hooks from.
   579  * @param string   $tag      The action to remove hooks from.
   564  * @param int|bool $priority The priority number to remove them from. Default false.
   580  * @param int|bool $priority The priority number to remove them from. Default false.
   565  * @return true True when finished.
   581  * @return true True when finished.
   566  */
   582  */
   567 function remove_all_actions($tag, $priority = false) {
   583 function remove_all_actions( $tag, $priority = false ) {
   568 	return remove_all_filters($tag, $priority);
   584 	return remove_all_filters( $tag, $priority );
   569 }
   585 }
   570 
   586 
   571 /**
   587 /**
   572  * Fires functions attached to a deprecated filter hook.
   588  * Fires functions attached to a deprecated filter hook.
   573  *
   589  *
   658 		if ( strpos( $file, $realdir ) === 0 ) {
   674 		if ( strpos( $file, $realdir ) === 0 ) {
   659 			$file = $dir . substr( $file, strlen( $realdir ) );
   675 			$file = $dir . substr( $file, strlen( $realdir ) );
   660 		}
   676 		}
   661 	}
   677 	}
   662 
   678 
   663 	$plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
   679 	$plugin_dir    = wp_normalize_path( WP_PLUGIN_DIR );
   664 	$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
   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 dir
   682 	$file = preg_replace( '#^' . preg_quote( $plugin_dir, '#' ) . '/|^' . preg_quote( $mu_plugin_dir, '#' ) . '/#', '', $file ); // get relative path from plugins dir
   667 	$file = trim($file, '/');
   683 	$file = trim( $file, '/' );
   668 	return $file;
   684 	return $file;
   669 }
   685 }
   670 
   686 
   671 /**
   687 /**
   672  * Register a plugin's real path.
   688  * Register a plugin's real path.
   689 	global $wp_plugin_paths;
   705 	global $wp_plugin_paths;
   690 
   706 
   691 	// Normalize, but store as static to avoid recalculation of a constant value
   707 	// Normalize, but store as static to avoid recalculation of a constant value
   692 	static $wp_plugin_path = null, $wpmu_plugin_path = null;
   708 	static $wp_plugin_path = null, $wpmu_plugin_path = null;
   693 	if ( ! isset( $wp_plugin_path ) ) {
   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 		$wpmu_plugin_path = wp_normalize_path( WPMU_PLUGIN_DIR );
   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 	$plugin_realpath = wp_normalize_path( dirname( realpath( $file ) ) );
   715 	$plugin_realpath = wp_normalize_path( dirname( realpath( $file ) ) );
   700 
   716 
   701 	if ( $plugin_path === $wp_plugin_path || $plugin_path === $wpmu_plugin_path ) {
   717 	if ( $plugin_path === $wp_plugin_path || $plugin_path === $wpmu_plugin_path ) {
   702 		return false;
   718 		return false;
   703 	}
   719 	}
   749  * @since 2.0.0
   765  * @since 2.0.0
   750  *
   766  *
   751  * @param string   $file     The filename of the plugin including the path.
   767  * @param string   $file     The filename of the plugin including the path.
   752  * @param callable $function The function hooked to the 'activate_PLUGIN' action.
   768  * @param callable $function The function hooked to the 'activate_PLUGIN' action.
   753  */
   769  */
   754 function register_activation_hook($file, $function) {
   770 function register_activation_hook( $file, $function ) {
   755 	$file = plugin_basename($file);
   771 	$file = plugin_basename( $file );
   756 	add_action('activate_' . $file, $function);
   772 	add_action( 'activate_' . $file, $function );
   757 }
   773 }
   758 
   774 
   759 /**
   775 /**
   760  * Set the deactivation hook for a plugin.
   776  * Set the deactivation hook for a plugin.
   761  *
   777  *
   772  * @since 2.0.0
   788  * @since 2.0.0
   773  *
   789  *
   774  * @param string   $file     The filename of the plugin including the path.
   790  * @param string   $file     The filename of the plugin including the path.
   775  * @param callable $function The function hooked to the 'deactivate_PLUGIN' action.
   791  * @param callable $function The function hooked to the 'deactivate_PLUGIN' action.
   776  */
   792  */
   777 function register_deactivation_hook($file, $function) {
   793 function register_deactivation_hook( $file, $function ) {
   778 	$file = plugin_basename($file);
   794 	$file = plugin_basename( $file );
   779 	add_action('deactivate_' . $file, $function);
   795 	add_action( 'deactivate_' . $file, $function );
   780 }
   796 }
   781 
   797 
   782 /**
   798 /**
   783  * Set the uninstallation hook for a plugin.
   799  * Set the uninstallation hook for a plugin.
   784  *
   800  *
   814 	/*
   830 	/*
   815 	 * The option should not be autoloaded, because it is not needed in most
   831 	 * The option should not be autoloaded, because it is not needed in most
   816 	 * cases. Emphasis should be put on using the 'uninstall.php' way of
   832 	 * cases. Emphasis should be put on using the 'uninstall.php' way of
   817 	 * uninstalling the plugin.
   833 	 * uninstalling the plugin.
   818 	 */
   834 	 */
   819 	$uninstallable_plugins = (array) get_option('uninstall_plugins');
   835 	$uninstallable_plugins                             = (array) get_option( 'uninstall_plugins' );
   820 	$uninstallable_plugins[plugin_basename($file)] = $callback;
   836 	$uninstallable_plugins[ plugin_basename( $file ) ] = $callback;
   821 
   837 
   822 	update_option('uninstall_plugins', $uninstallable_plugins);
   838 	update_option( 'uninstall_plugins', $uninstallable_plugins );
   823 }
   839 }
   824 
   840 
   825 /**
   841 /**
   826  * Call the 'all' hook, which will process the functions hooked into it.
   842  * Call the 'all' hook, which will process the functions hooked into it.
   827  *
   843  *
   838  *
   854  *
   839  * @global array $wp_filter  Stores all of the filters
   855  * @global array $wp_filter  Stores all of the filters
   840  *
   856  *
   841  * @param array $args The collected parameters from the hook that was called.
   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 	global $wp_filter;
   860 	global $wp_filter;
   845 
   861 
   846 	$wp_filter['all']->do_all_hook( $args );
   862 	$wp_filter['all']->do_all_hook( $args );
   847 }
   863 }
   848 
   864 
   878  *                           id only if it already has one, false otherwise.
   894  *                           id only if it already has one, false otherwise.
   879  * @return string|false Unique ID for usage as array key or false if $priority === false
   895  * @return string|false Unique ID for usage as array key or false if $priority === false
   880  *                      and $function is an object reference, and it does not already have
   896  *                      and $function is an object reference, and it does not already have
   881  *                      a unique id.
   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 	global $wp_filter;
   900 	global $wp_filter;
   885 	static $filter_id_count = 0;
   901 	static $filter_id_count = 0;
   886 
   902 
   887 	if ( is_string($function) )
   903 	if ( is_string( $function ) ) {
   888 		return $function;
   904 		return $function;
   889 
   905 	}
   890 	if ( is_object($function) ) {
   906 
       
   907 	if ( is_object( $function ) ) {
   891 		// Closures are currently implemented as objects
   908 		// Closures are currently implemented as objects
   892 		$function = array( $function, '' );
   909 		$function = array( $function, '' );
   893 	} else {
   910 	} else {
   894 		$function = (array) $function;
   911 		$function = (array) $function;
   895 	}
   912 	}
   896 
   913 
   897 	if (is_object($function[0]) ) {
   914 	if ( is_object( $function[0] ) ) {
   898 		// Object Class Calling
   915 		// Object Class Calling
   899 		if ( function_exists('spl_object_hash') ) {
   916 		if ( function_exists( 'spl_object_hash' ) ) {
   900 			return spl_object_hash($function[0]) . $function[1];
   917 			return spl_object_hash( $function[0] ) . $function[1];
   901 		} else {
   918 		} else {
   902 			$obj_idx = get_class($function[0]).$function[1];
   919 			$obj_idx = get_class( $function[0] ) . $function[1];
   903 			if ( !isset($function[0]->wp_filter_id) ) {
   920 			if ( ! isset( $function[0]->wp_filter_id ) ) {
   904 				if ( false === $priority )
   921 				if ( false === $priority ) {
   905 					return false;
   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 				$function[0]->wp_filter_id = $filter_id_count;
   925 				$function[0]->wp_filter_id = $filter_id_count;
   908 				++$filter_id_count;
   926 				++$filter_id_count;
   909 			} else {
   927 			} else {
   910 				$obj_idx .= $function[0]->wp_filter_id;
   928 				$obj_idx .= $function[0]->wp_filter_id;
   911 			}
   929 			}