3 * The plugin API is located in this file, which allows for creating actions
4 * and filters and hooking functions, and methods. The functions or methods will
5 * then be run when the action or filter is called.
7 * The API callback examples reference functions, but can be methods of classes.
8 * To hook methods, you'll need to pass an array one of two ways.
10 * Any of the syntaxes explained in the PHP documentation for the
11 * {@link http://us2.php.net/manual/en/language.pseudo-types.php#language.types.callback 'callback'}
14 * Also see the {@link https://codex.wordpress.org/Plugin_API Plugin API} for
15 * more information and examples on how to use a lot of these functions.
22 // Initialize the filter globals.
23 global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter;
25 if ( ! isset( $wp_filter ) )
28 if ( ! isset( $wp_actions ) )
29 $wp_actions = array();
31 if ( ! isset( $merged_filters ) )
32 $merged_filters = array();
34 if ( ! isset( $wp_current_filter ) )
35 $wp_current_filter = array();
38 * Hook a function or method to a specific filter action.
40 * WordPress offers filter hooks to allow plugins to modify
41 * various types of internal data at runtime.
43 * A plugin can modify data by binding a callback to a filter hook. When the filter
44 * is later applied, each bound callback is run in order of priority, and given
45 * the opportunity to modify a value by returning a new value.
47 * The following example shows how a callback function is bound to a filter hook.
49 * Note that `$example` is passed to the callback, (maybe) modified, then returned:
51 * function example_callback( $example ) {
52 * // Maybe modify $example in some way.
55 * add_filter( 'example_filter', 'example_callback' );
57 * Bound callbacks can accept from none to the total number of arguments passed as parameters
58 * in the corresponding apply_filters() call.
60 * In other words, if an apply_filters() call passes four total arguments, callbacks bound to
61 * it can accept none (the same as 1) of the arguments or up to four. The important part is that
62 * the `$accepted_args` value must reflect the number of arguments the bound callback *actually*
63 * opted to accept. If no arguments were accepted by the callback that is considered to be the
64 * same as accepting 1 argument. For example:
67 * $value = apply_filters( 'hook', $value, $arg2, $arg3 );
69 * // Accepting zero/one arguments.
70 * function example_callback() {
72 * return 'some value';
74 * add_filter( 'hook', 'example_callback' ); // Where $priority is default 10, $accepted_args is default 1.
76 * // Accepting two arguments (three possible).
77 * function example_callback( $value, $arg2 ) {
79 * return $maybe_modified_value;
81 * add_filter( 'hook', 'example_callback', 10, 2 ); // Where $priority is 10, $accepted_args is 2.
83 * *Note:* The function will return true whether or not the callback is valid.
84 * It is up to you to take care. This is done for optimization purposes, so
85 * everything is as quick as possible.
89 * @global array $wp_filter A multidimensional array of all hooks and the callbacks hooked to them.
90 * @global array $merged_filters Tracks the tags that need to be merged for later. If the hook is added,
91 * it doesn't need to run through that process.
93 * @param string $tag The name of the filter to hook the $function_to_add callback to.
94 * @param callable $function_to_add The callback to be run when the filter is applied.
95 * @param int $priority Optional. Used to specify the order in which the functions
96 * associated with a particular action are executed. Default 10.
97 * Lower numbers correspond with earlier execution,
98 * and functions with the same priority are executed
99 * in the order in which they were added to the action.
100 * @param int $accepted_args Optional. The number of arguments the function accepts. Default 1.
103 function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
104 global $wp_filter, $merged_filters;
106 $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority);
107 $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
108 unset( $merged_filters[ $tag ] );
113 * Check if any filter has been registered for a hook.
117 * @global array $wp_filter Stores all of the filters.
119 * @param string $tag The name of the filter hook.
120 * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
121 * @return false|int If $function_to_check is omitted, returns boolean for whether the hook has
122 * anything registered. When checking a specific function, the priority of that
123 * hook is returned, or false if the function is not attached. When using the
124 * $function_to_check argument, this function may return a non-boolean value
125 * that evaluates to false (e.g.) 0, so use the === operator for testing the
128 function has_filter($tag, $function_to_check = false) {
129 // Don't reset the internal array pointer
130 $wp_filter = $GLOBALS['wp_filter'];
132 $has = ! empty( $wp_filter[ $tag ] );
134 // Make sure at least one priority has a filter callback
137 foreach ( $wp_filter[ $tag ] as $callbacks ) {
138 if ( ! empty( $callbacks ) ) {
149 if ( false === $function_to_check || false === $has )
152 if ( !$idx = _wp_filter_build_unique_id($tag, $function_to_check, false) )
155 foreach ( (array) array_keys($wp_filter[$tag]) as $priority ) {
156 if ( isset($wp_filter[$tag][$priority][$idx]) )
164 * Call the functions added to a filter hook.
166 * The callback functions attached to filter hook $tag are invoked by calling
167 * this function. This function can be used to create a new filter hook by
168 * simply calling this function with the name of the new hook specified using
169 * the $tag parameter.
171 * The function allows for additional arguments to be added and passed to hooks.
173 * // Our filter callback function
174 * function example_callback( $string, $arg1, $arg2 ) {
175 * // (maybe) modify $string
178 * add_filter( 'example_filter', 'example_callback', 10, 3 );
181 * * Apply the filters by calling the 'example_callback' function we
182 * * "hooked" to 'example_filter' using the add_filter() function above.
183 * * - 'example_filter' is the filter hook $tag
184 * * - 'filter me' is the value being filtered
185 * * - $arg1 and $arg2 are the additional arguments passed to the callback.
186 * $value = apply_filters( 'example_filter', 'filter me', $arg1, $arg2 );
190 * @global array $wp_filter Stores all of the filters.
191 * @global array $merged_filters Merges the filter hooks using this function.
192 * @global array $wp_current_filter Stores the list of current filters with the current one last.
194 * @param string $tag The name of the filter hook.
195 * @param mixed $value The value on which the filters hooked to `$tag` are applied on.
196 * @param mixed $var Additional variables passed to the functions hooked to `$tag`.
197 * @return mixed The filtered value after all hooked functions are applied to it.
199 function apply_filters( $tag, $value ) {
200 global $wp_filter, $merged_filters, $wp_current_filter;
204 // Do 'all' actions first.
205 if ( isset($wp_filter['all']) ) {
206 $wp_current_filter[] = $tag;
207 $args = func_get_args();
208 _wp_call_all_hook($args);
211 if ( !isset($wp_filter[$tag]) ) {
212 if ( isset($wp_filter['all']) )
213 array_pop($wp_current_filter);
217 if ( !isset($wp_filter['all']) )
218 $wp_current_filter[] = $tag;
221 if ( !isset( $merged_filters[ $tag ] ) ) {
222 ksort($wp_filter[$tag]);
223 $merged_filters[ $tag ] = true;
226 reset( $wp_filter[ $tag ] );
229 $args = func_get_args();
232 foreach ( (array) current($wp_filter[$tag]) as $the_ )
233 if ( !is_null($the_['function']) ){
235 $value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
238 } while ( next($wp_filter[$tag]) !== false );
240 array_pop( $wp_current_filter );
246 * Execute functions hooked on a specific filter hook, specifying arguments in an array.
250 * @see apply_filters() This function is identical, but the arguments passed to the
251 * functions hooked to `$tag` are supplied using an array.
253 * @global array $wp_filter Stores all of the filters
254 * @global array $merged_filters Merges the filter hooks using this function.
255 * @global array $wp_current_filter Stores the list of current filters with the current one last
257 * @param string $tag The name of the filter hook.
258 * @param array $args The arguments supplied to the functions hooked to $tag.
259 * @return mixed The filtered value after all hooked functions are applied to it.
261 function apply_filters_ref_array($tag, $args) {
262 global $wp_filter, $merged_filters, $wp_current_filter;
264 // Do 'all' actions first
265 if ( isset($wp_filter['all']) ) {
266 $wp_current_filter[] = $tag;
267 $all_args = func_get_args();
268 _wp_call_all_hook($all_args);
271 if ( !isset($wp_filter[$tag]) ) {
272 if ( isset($wp_filter['all']) )
273 array_pop($wp_current_filter);
277 if ( !isset($wp_filter['all']) )
278 $wp_current_filter[] = $tag;
281 if ( !isset( $merged_filters[ $tag ] ) ) {
282 ksort($wp_filter[$tag]);
283 $merged_filters[ $tag ] = true;
286 reset( $wp_filter[ $tag ] );
289 foreach ( (array) current($wp_filter[$tag]) as $the_ )
290 if ( !is_null($the_['function']) )
291 $args[0] = call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
293 } while ( next($wp_filter[$tag]) !== false );
295 array_pop( $wp_current_filter );
301 * Removes a function from a specified filter hook.
303 * This function removes a function attached to a specified filter hook. This
304 * method can be used to remove default functions attached to a specific filter
305 * hook and possibly replace them with a substitute.
307 * To remove a hook, the $function_to_remove and $priority arguments must match
308 * when the hook was added. This goes for both filters and actions. No warning
309 * will be given on removal failure.
313 * @global array $wp_filter Stores all of the filters
314 * @global array $merged_filters Merges the filter hooks using this function.
316 * @param string $tag The filter hook to which the function to be removed is hooked.
317 * @param callable $function_to_remove The name of the function which should be removed.
318 * @param int $priority Optional. The priority of the function. Default 10.
319 * @return bool Whether the function existed before it was removed.
321 function remove_filter( $tag, $function_to_remove, $priority = 10 ) {
322 $function_to_remove = _wp_filter_build_unique_id( $tag, $function_to_remove, $priority );
324 $r = isset( $GLOBALS['wp_filter'][ $tag ][ $priority ][ $function_to_remove ] );
327 unset( $GLOBALS['wp_filter'][ $tag ][ $priority ][ $function_to_remove ] );
328 if ( empty( $GLOBALS['wp_filter'][ $tag ][ $priority ] ) ) {
329 unset( $GLOBALS['wp_filter'][ $tag ][ $priority ] );
331 if ( empty( $GLOBALS['wp_filter'][ $tag ] ) ) {
332 $GLOBALS['wp_filter'][ $tag ] = array();
334 unset( $GLOBALS['merged_filters'][ $tag ] );
341 * Remove all of the hooks from a filter.
345 * @global array $wp_filter Stores all of the filters
346 * @global array $merged_filters Merges the filter hooks using this function.
348 * @param string $tag The filter to remove hooks from.
349 * @param int|bool $priority Optional. The priority number to remove. Default false.
350 * @return true True when finished.
352 function remove_all_filters( $tag, $priority = false ) {
353 global $wp_filter, $merged_filters;
355 if ( isset( $wp_filter[ $tag ]) ) {
356 if ( false === $priority ) {
357 $wp_filter[ $tag ] = array();
358 } elseif ( isset( $wp_filter[ $tag ][ $priority ] ) ) {
359 $wp_filter[ $tag ][ $priority ] = array();
363 unset( $merged_filters[ $tag ] );
369 * Retrieve the name of the current filter or action.
373 * @global array $wp_current_filter Stores the list of current filters with the current one last
375 * @return string Hook name of the current filter or action.
377 function current_filter() {
378 global $wp_current_filter;
379 return end( $wp_current_filter );
383 * Retrieve the name of the current action.
387 * @return string Hook name of the current action.
389 function current_action() {
390 return current_filter();
394 * Retrieve the name of a filter currently being processed.
396 * The function current_filter() only returns the most recent filter or action
397 * being executed. did_action() returns true once the action is initially
400 * This function allows detection for any filter currently being
401 * executed (despite not being the most recent filter to fire, in the case of
402 * hooks called from hook callbacks) to be verified.
406 * @see current_filter()
408 * @global array $wp_current_filter Current filter.
410 * @param null|string $filter Optional. Filter to check. Defaults to null, which
411 * checks if any filter is currently being run.
412 * @return bool Whether the filter is currently in the stack.
414 function doing_filter( $filter = null ) {
415 global $wp_current_filter;
417 if ( null === $filter ) {
418 return ! empty( $wp_current_filter );
421 return in_array( $filter, $wp_current_filter );
425 * Retrieve the name of an action currently being processed.
429 * @param string|null $action Optional. Action to check. Defaults to null, which checks
430 * if any action is currently being run.
431 * @return bool Whether the action is currently in the stack.
433 function doing_action( $action = null ) {
434 return doing_filter( $action );
438 * Hooks a function on to a specific action.
440 * Actions are the hooks that the WordPress core launches at specific points
441 * during execution, or when specific events occur. Plugins can specify that
442 * one or more of its PHP functions are executed at these points, using the
447 * @param string $tag The name of the action to which the $function_to_add is hooked.
448 * @param callable $function_to_add The name of the function you wish to be called.
449 * @param int $priority Optional. Used to specify the order in which the functions
450 * associated with a particular action are executed. Default 10.
451 * Lower numbers correspond with earlier execution,
452 * and functions with the same priority are executed
453 * in the order in which they were added to the action.
454 * @param int $accepted_args Optional. The number of arguments the function accepts. Default 1.
455 * @return true Will always return true.
457 function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
458 return add_filter($tag, $function_to_add, $priority, $accepted_args);
462 * Execute functions hooked on a specific action hook.
464 * This function invokes all functions attached to action hook `$tag`. It is
465 * possible to create new action hooks by simply calling this function,
466 * specifying the name of the new hook using the `$tag` parameter.
468 * You can pass extra arguments to the hooks, much like you can with
469 * {@see apply_filters()}.
473 * @global array $wp_filter Stores all of the filters
474 * @global array $wp_actions Increments the amount of times action was triggered.
475 * @global array $merged_filters Merges the filter hooks using this function.
476 * @global array $wp_current_filter Stores the list of current filters with the current one last
478 * @param string $tag The name of the action to be executed.
479 * @param mixed $arg Optional. Additional arguments which are passed on to the
480 * functions hooked to the action. Default empty.
482 function do_action($tag, $arg = '') {
483 global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter;
485 if ( ! isset($wp_actions[$tag]) )
486 $wp_actions[$tag] = 1;
490 // Do 'all' actions first
491 if ( isset($wp_filter['all']) ) {
492 $wp_current_filter[] = $tag;
493 $all_args = func_get_args();
494 _wp_call_all_hook($all_args);
497 if ( !isset($wp_filter[$tag]) ) {
498 if ( isset($wp_filter['all']) )
499 array_pop($wp_current_filter);
503 if ( !isset($wp_filter['all']) )
504 $wp_current_filter[] = $tag;
507 if ( is_array($arg) && 1 == count($arg) && isset($arg[0]) && is_object($arg[0]) ) // array(&$this)
511 for ( $a = 2, $num = func_num_args(); $a < $num; $a++ )
512 $args[] = func_get_arg($a);
515 if ( !isset( $merged_filters[ $tag ] ) ) {
516 ksort($wp_filter[$tag]);
517 $merged_filters[ $tag ] = true;
520 reset( $wp_filter[ $tag ] );
523 foreach ( (array) current($wp_filter[$tag]) as $the_ )
524 if ( !is_null($the_['function']) )
525 call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
527 } while ( next($wp_filter[$tag]) !== false );
529 array_pop($wp_current_filter);
533 * Retrieve the number of times an action is fired.
537 * @global array $wp_actions Increments the amount of times action was triggered.
539 * @param string $tag The name of the action hook.
540 * @return int The number of times action hook $tag is fired.
542 function did_action($tag) {
545 if ( ! isset( $wp_actions[ $tag ] ) )
548 return $wp_actions[$tag];
552 * Execute functions hooked on a specific action hook, specifying arguments in an array.
556 * @see do_action() This function is identical, but the arguments passed to the
557 * functions hooked to $tag< are supplied using an array.
558 * @global array $wp_filter Stores all of the filters
559 * @global array $wp_actions Increments the amount of times action was triggered.
560 * @global array $merged_filters Merges the filter hooks using this function.
561 * @global array $wp_current_filter Stores the list of current filters with the current one last
563 * @param string $tag The name of the action to be executed.
564 * @param array $args The arguments supplied to the functions hooked to `$tag`.
566 function do_action_ref_array($tag, $args) {
567 global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter;
569 if ( ! isset($wp_actions[$tag]) )
570 $wp_actions[$tag] = 1;
574 // Do 'all' actions first
575 if ( isset($wp_filter['all']) ) {
576 $wp_current_filter[] = $tag;
577 $all_args = func_get_args();
578 _wp_call_all_hook($all_args);
581 if ( !isset($wp_filter[$tag]) ) {
582 if ( isset($wp_filter['all']) )
583 array_pop($wp_current_filter);
587 if ( !isset($wp_filter['all']) )
588 $wp_current_filter[] = $tag;
591 if ( !isset( $merged_filters[ $tag ] ) ) {
592 ksort($wp_filter[$tag]);
593 $merged_filters[ $tag ] = true;
596 reset( $wp_filter[ $tag ] );
599 foreach ( (array) current($wp_filter[$tag]) as $the_ )
600 if ( !is_null($the_['function']) )
601 call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
603 } while ( next($wp_filter[$tag]) !== false );
605 array_pop($wp_current_filter);
609 * Check if any action has been registered for a hook.
613 * @see has_filter() has_action() is an alias of has_filter().
615 * @param string $tag The name of the action hook.
616 * @param callable|bool $function_to_check Optional. The callback to check for. Default false.
617 * @return bool|int If $function_to_check is omitted, returns boolean for whether the hook has
618 * anything registered. When checking a specific function, the priority of that
619 * hook is returned, or false if the function is not attached. When using the
620 * $function_to_check argument, this function may return a non-boolean value
621 * that evaluates to false (e.g.) 0, so use the === operator for testing the
624 function has_action($tag, $function_to_check = false) {
625 return has_filter($tag, $function_to_check);
629 * Removes a function from a specified action hook.
631 * This function removes a function attached to a specified action hook. This
632 * method can be used to remove default functions attached to a specific filter
633 * hook and possibly replace them with a substitute.
637 * @param string $tag The action hook to which the function to be removed is hooked.
638 * @param callable $function_to_remove The name of the function which should be removed.
639 * @param int $priority Optional. The priority of the function. Default 10.
640 * @return bool Whether the function is removed.
642 function remove_action( $tag, $function_to_remove, $priority = 10 ) {
643 return remove_filter( $tag, $function_to_remove, $priority );
647 * Remove all of the hooks from an action.
651 * @param string $tag The action to remove hooks from.
652 * @param int|bool $priority The priority number to remove them from. Default false.
653 * @return true True when finished.
655 function remove_all_actions($tag, $priority = false) {
656 return remove_all_filters($tag, $priority);
660 // Functions for handling plugins.
664 * Gets the basename of a plugin.
666 * This method extracts the name of a plugin from its filename.
670 * @global array $wp_plugin_paths
672 * @param string $file The filename of plugin.
673 * @return string The name of a plugin.
675 function plugin_basename( $file ) {
676 global $wp_plugin_paths;
678 foreach ( $wp_plugin_paths as $dir => $realdir ) {
679 if ( strpos( $file, $realdir ) === 0 ) {
680 $file = $dir . substr( $file, strlen( $realdir ) );
684 $file = wp_normalize_path( $file );
685 $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
686 $mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
688 $file = preg_replace('#^' . preg_quote($plugin_dir, '#') . '/|^' . preg_quote($mu_plugin_dir, '#') . '/#','',$file); // get relative path from plugins dir
689 $file = trim($file, '/');
694 * Register a plugin's real path.
696 * This is used in plugin_basename() to resolve symlinked paths.
700 * @see plugin_basename()
702 * @global array $wp_plugin_paths
704 * @staticvar string $wp_plugin_path
705 * @staticvar string $wpmu_plugin_path
707 * @param string $file Known path to the file.
708 * @return bool Whether the path was able to be registered.
710 function wp_register_plugin_realpath( $file ) {
711 global $wp_plugin_paths;
713 // Normalize, but store as static to avoid recalculation of a constant value
714 static $wp_plugin_path = null, $wpmu_plugin_path = null;
715 if ( ! isset( $wp_plugin_path ) ) {
716 $wp_plugin_path = wp_normalize_path( WP_PLUGIN_DIR );
717 $wpmu_plugin_path = wp_normalize_path( WPMU_PLUGIN_DIR );
720 $plugin_path = wp_normalize_path( dirname( $file ) );
721 $plugin_realpath = wp_normalize_path( dirname( realpath( $file ) ) );
723 if ( $plugin_path === $wp_plugin_path || $plugin_path === $wpmu_plugin_path ) {
727 if ( $plugin_path !== $plugin_realpath ) {
728 $wp_plugin_paths[ $plugin_path ] = $plugin_realpath;
735 * Get the filesystem directory path (with trailing slash) for the plugin __FILE__ passed in.
739 * @param string $file The filename of the plugin (__FILE__).
740 * @return string the filesystem path of the directory that contains the plugin.
742 function plugin_dir_path( $file ) {
743 return trailingslashit( dirname( $file ) );
747 * Get the URL directory path (with trailing slash) for the plugin __FILE__ passed in.
751 * @param string $file The filename of the plugin (__FILE__).
752 * @return string the URL path of the directory that contains the plugin.
754 function plugin_dir_url( $file ) {
755 return trailingslashit( plugins_url( '', $file ) );
759 * Set the activation hook for a plugin.
761 * When a plugin is activated, the action 'activate_PLUGINNAME' hook is
762 * called. In the name of this hook, PLUGINNAME is replaced with the name
763 * of the plugin, including the optional subdirectory. For example, when the
764 * plugin is located in wp-content/plugins/sampleplugin/sample.php, then
765 * the name of this hook will become 'activate_sampleplugin/sample.php'.
767 * When the plugin consists of only one file and is (as by default) located at
768 * wp-content/plugins/sample.php the name of this hook will be
769 * 'activate_sample.php'.
773 * @param string $file The filename of the plugin including the path.
774 * @param callable $function The function hooked to the 'activate_PLUGIN' action.
776 function register_activation_hook($file, $function) {
777 $file = plugin_basename($file);
778 add_action('activate_' . $file, $function);
782 * Set the deactivation hook for a plugin.
784 * When a plugin is deactivated, the action 'deactivate_PLUGINNAME' hook is
785 * called. In the name of this hook, PLUGINNAME is replaced with the name
786 * of the plugin, including the optional subdirectory. For example, when the
787 * plugin is located in wp-content/plugins/sampleplugin/sample.php, then
788 * the name of this hook will become 'deactivate_sampleplugin/sample.php'.
790 * When the plugin consists of only one file and is (as by default) located at
791 * wp-content/plugins/sample.php the name of this hook will be
792 * 'deactivate_sample.php'.
796 * @param string $file The filename of the plugin including the path.
797 * @param callable $function The function hooked to the 'deactivate_PLUGIN' action.
799 function register_deactivation_hook($file, $function) {
800 $file = plugin_basename($file);
801 add_action('deactivate_' . $file, $function);
805 * Set the uninstallation hook for a plugin.
807 * Registers the uninstall hook that will be called when the user clicks on the
808 * uninstall link that calls for the plugin to uninstall itself. The link won't
809 * be active unless the plugin hooks into the action.
811 * The plugin should not run arbitrary code outside of functions, when
812 * registering the uninstall hook. In order to run using the hook, the plugin
813 * will have to be included, which means that any code laying outside of a
814 * function will be run during the uninstall process. The plugin should not
815 * hinder the uninstall process.
817 * If the plugin can not be written without running code within the plugin, then
818 * the plugin should create a file named 'uninstall.php' in the base plugin
819 * folder. This file will be called, if it exists, during the uninstall process
820 * bypassing the uninstall hook. The plugin, when using the 'uninstall.php'
821 * should always check for the 'WP_UNINSTALL_PLUGIN' constant, before
826 * @param string $file Plugin file.
827 * @param callable $callback The callback to run when the hook is called. Must be
828 * a static method or function.
830 function register_uninstall_hook( $file, $callback ) {
831 if ( is_array( $callback ) && is_object( $callback[0] ) ) {
832 _doing_it_wrong( __FUNCTION__, __( 'Only a static class method or function can be used in an uninstall hook.' ), '3.1' );
837 * The option should not be autoloaded, because it is not needed in most
838 * cases. Emphasis should be put on using the 'uninstall.php' way of
839 * uninstalling the plugin.
841 $uninstallable_plugins = (array) get_option('uninstall_plugins');
842 $uninstallable_plugins[plugin_basename($file)] = $callback;
844 update_option('uninstall_plugins', $uninstallable_plugins);
848 * Call the 'all' hook, which will process the functions hooked into it.
850 * The 'all' hook passes all of the arguments or parameters that were used for
851 * the hook, which this function was called for.
853 * This function is used internally for apply_filters(), do_action(), and
854 * do_action_ref_array() and is not meant to be used from outside those
855 * functions. This function does not check for the existence of the all hook, so
856 * it will fail unless the all hook exists prior to this function call.
861 * @global array $wp_filter Stores all of the filters
863 * @param array $args The collected parameters from the hook that was called.
865 function _wp_call_all_hook($args) {
868 reset( $wp_filter['all'] );
870 foreach ( (array) current($wp_filter['all']) as $the_ )
871 if ( !is_null($the_['function']) )
872 call_user_func_array($the_['function'], $args);
874 } while ( next($wp_filter['all']) !== false );
878 * Build Unique ID for storage and retrieval.
880 * The old way to serialize the callback caused issues and this function is the
881 * solution. It works by checking for objects and creating a new property in
882 * the class to keep track of the object and new objects of the same class that
885 * It also allows for the removal of actions and filters for objects after they
886 * change class properties. It is possible to include the property $wp_filter_id
887 * in your class and set it to "null" or a number to bypass the workaround.
888 * However this will prevent you from adding new classes and any new classes
889 * will overwrite the previous hook by the same class.
891 * Functions and static method callbacks are just returned as strings and
892 * shouldn't have any speed penalty.
894 * @link https://core.trac.wordpress.org/ticket/3875
899 * @global array $wp_filter Storage for all of the filters and actions.
900 * @staticvar int $filter_id_count
902 * @param string $tag Used in counting how many hooks were applied
903 * @param callable $function Used for creating unique id
904 * @param int|bool $priority Used in counting how many hooks were applied. If === false
905 * and $function is an object reference, we return the unique
906 * id only if it already has one, false otherwise.
907 * @return string|false Unique ID for usage as array key or false if $priority === false
908 * and $function is an object reference, and it does not already have
911 function _wp_filter_build_unique_id($tag, $function, $priority) {
913 static $filter_id_count = 0;
915 if ( is_string($function) )
918 if ( is_object($function) ) {
919 // Closures are currently implemented as objects
920 $function = array( $function, '' );
922 $function = (array) $function;
925 if (is_object($function[0]) ) {
926 // Object Class Calling
927 if ( function_exists('spl_object_hash') ) {
928 return spl_object_hash($function[0]) . $function[1];
930 $obj_idx = get_class($function[0]).$function[1];
931 if ( !isset($function[0]->wp_filter_id) ) {
932 if ( false === $priority )
934 $obj_idx .= isset($wp_filter[$tag][$priority]) ? count((array)$wp_filter[$tag][$priority]) : $filter_id_count;
935 $function[0]->wp_filter_id = $filter_id_count;
938 $obj_idx .= $function[0]->wp_filter_id;
943 } elseif ( is_string( $function[0] ) ) {
945 return $function[0] . '::' . $function[1];