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 http://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.
48
* 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' );
58
* Since WordPress 1.5.1, bound callbacks can take as many arguments as are
59
* passed as parameters in the corresponding apply_filters() call. The $accepted_args
60
* parameter allows for calling functions only when the number of args match.
62
* <strong>Note:</strong> the function will return true whether or not the callback
63
* is valid. It is up to you to take care. This is done for optimization purposes,
64
* so everything is as quick as possible.
68
* @global array $wp_filter A multidimensional array of all hooks and the callbacks hooked to them.
69
* @global array $merged_filters Tracks the tags that need to be merged for later. If the hook is added,
70
* it doesn't need to run through that process.
72
* @param string $tag The name of the filter to hook the $function_to_add callback to.
73
* @param callback $function_to_add The callback to be run when the filter is applied.
74
* @param int $priority Optional. Used to specify the order in which the functions
75
* associated with a particular action are executed. Default 10.
76
* Lower numbers correspond with earlier execution,
77
* and functions with the same priority are executed
78
* in the order in which they were added to the action.
79
* @param int $accepted_args Optional. The number of arguments the function accepts. Default 1.
80
* @return boolean true
82
function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
83
global $wp_filter, $merged_filters;
85
$idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority);
86
$wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args);
87
unset( $merged_filters[ $tag ] );
92
* Check if any filter has been registered for a hook.
96
* @global array $wp_filter Stores all of the filters.
98
* @param string $tag The name of the filter hook.
99
* @param callback|bool $function_to_check Optional. The callback to check for. Default false.
100
* @return bool|int If $function_to_check is omitted, returns boolean for whether the hook has
101
* anything registered. When checking a specific function, the priority of that
102
* hook is returned, or false if the function is not attached. When using the
103
* $function_to_check argument, this function may return a non-boolean value
104
* that evaluates to false (e.g.) 0, so use the === operator for testing the
107
function has_filter($tag, $function_to_check = false) {
108
// Don't reset the internal array pointer
109
$wp_filter = $GLOBALS['wp_filter'];
111
$has = ! empty( $wp_filter[ $tag ] );
113
// Make sure at least one priority has a filter callback
116
foreach ( $wp_filter[ $tag ] as $callbacks ) {
117
if ( ! empty( $callbacks ) ) {
128
if ( false === $function_to_check || false == $has )
131
if ( !$idx = _wp_filter_build_unique_id($tag, $function_to_check, false) )
134
foreach ( (array) array_keys($wp_filter[$tag]) as $priority ) {
135
if ( isset($wp_filter[$tag][$priority][$idx]) )
143
* Call the functions added to a filter hook.
145
* The callback functions attached to filter hook $tag are invoked by calling
146
* this function. This function can be used to create a new filter hook by
147
* simply calling this function with the name of the new hook specified using
148
* the $tag parameter.
150
* The function allows for additional arguments to be added and passed to hooks.
152
* // Our filter callback function
153
* function example_callback( $string, $arg1, $arg2 ) {
154
* // (maybe) modify $string
157
* add_filter( 'example_filter', 'example_callback', 10, 3 );
159
* // Apply the filters by calling the 'example_callback' function we
160
* // "hooked" to 'example_filter' using the add_filter() function above.
161
* // - 'example_filter' is the filter hook $tag
162
* // - 'filter me' is the value being filtered
163
* // - $arg1 and $arg2 are the additional arguments passed to the callback.
164
* $value = apply_filters( 'example_filter', 'filter me', $arg1, $arg2 );
169
* @global array $wp_filter Stores all of the filters.
170
* @global array $merged_filters Merges the filter hooks using this function.
171
* @global array $wp_current_filter Stores the list of current filters with the current one last.
173
* @param string $tag The name of the filter hook.
174
* @param mixed $value The value on which the filters hooked to <tt>$tag</tt> are applied on.
175
* @param mixed $var Additional variables passed to the functions hooked to <tt>$tag</tt>.
176
* @return mixed The filtered value after all hooked functions are applied to it.
178
function apply_filters( $tag, $value ) {
179
global $wp_filter, $merged_filters, $wp_current_filter;
183
// Do 'all' actions first.
184
if ( isset($wp_filter['all']) ) {
185
$wp_current_filter[] = $tag;
186
$args = func_get_args();
187
_wp_call_all_hook($args);
190
if ( !isset($wp_filter[$tag]) ) {
191
if ( isset($wp_filter['all']) )
192
array_pop($wp_current_filter);
196
if ( !isset($wp_filter['all']) )
197
$wp_current_filter[] = $tag;
200
if ( !isset( $merged_filters[ $tag ] ) ) {
201
ksort($wp_filter[$tag]);
202
$merged_filters[ $tag ] = true;
205
reset( $wp_filter[ $tag ] );
208
$args = func_get_args();
211
foreach( (array) current($wp_filter[$tag]) as $the_ )
212
if ( !is_null($the_['function']) ){
214
$value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
217
} while ( next($wp_filter[$tag]) !== false );
219
array_pop( $wp_current_filter );
225
* Execute functions hooked on a specific filter hook, specifying arguments in an array.
227
* @see apply_filters() This function is identical, but the arguments passed to the
228
* functions hooked to <tt>$tag</tt> are supplied using an array.
232
* @global array $wp_filter Stores all of the filters
233
* @global array $merged_filters Merges the filter hooks using this function.
234
* @global array $wp_current_filter Stores the list of current filters with the current one last
236
* @param string $tag The name of the filter hook.
237
* @param array $args The arguments supplied to the functions hooked to $tag.
238
* @return mixed The filtered value after all hooked functions are applied to it.
240
function apply_filters_ref_array($tag, $args) {
241
global $wp_filter, $merged_filters, $wp_current_filter;
243
// Do 'all' actions first
244
if ( isset($wp_filter['all']) ) {
245
$wp_current_filter[] = $tag;
246
$all_args = func_get_args();
247
_wp_call_all_hook($all_args);
250
if ( !isset($wp_filter[$tag]) ) {
251
if ( isset($wp_filter['all']) )
252
array_pop($wp_current_filter);
256
if ( !isset($wp_filter['all']) )
257
$wp_current_filter[] = $tag;
260
if ( !isset( $merged_filters[ $tag ] ) ) {
261
ksort($wp_filter[$tag]);
262
$merged_filters[ $tag ] = true;
265
reset( $wp_filter[ $tag ] );
268
foreach( (array) current($wp_filter[$tag]) as $the_ )
269
if ( !is_null($the_['function']) )
270
$args[0] = call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
272
} while ( next($wp_filter[$tag]) !== false );
274
array_pop( $wp_current_filter );
280
* Removes a function from a specified filter hook.
282
* This function removes a function attached to a specified filter hook. This
283
* method can be used to remove default functions attached to a specific filter
284
* hook and possibly replace them with a substitute.
286
* To remove a hook, the $function_to_remove and $priority arguments must match
287
* when the hook was added. This goes for both filters and actions. No warning
288
* will be given on removal failure.
292
* @param string $tag The filter hook to which the function to be removed is hooked.
293
* @param callback $function_to_remove The name of the function which should be removed.
294
* @param int $priority Optional. The priority of the function. Default 10.
295
* @return boolean Whether the function existed before it was removed.
297
function remove_filter( $tag, $function_to_remove, $priority = 10 ) {
298
$function_to_remove = _wp_filter_build_unique_id( $tag, $function_to_remove, $priority );
300
$r = isset( $GLOBALS['wp_filter'][ $tag ][ $priority ][ $function_to_remove ] );
303
unset( $GLOBALS['wp_filter'][ $tag ][ $priority ][ $function_to_remove ] );
304
if ( empty( $GLOBALS['wp_filter'][ $tag ][ $priority ] ) ) {
305
unset( $GLOBALS['wp_filter'][ $tag ][ $priority ] );
307
if ( empty( $GLOBALS['wp_filter'][ $tag ] ) ) {
308
$GLOBALS['wp_filter'][ $tag ] = array();
310
unset( $GLOBALS['merged_filters'][ $tag ] );
317
* Remove all of the hooks from a filter.
321
* @param string $tag The filter to remove hooks from.
322
* @param int|bool $priority Optional. The priority number to remove. Default false.
323
* @return bool True when finished.
325
function remove_all_filters( $tag, $priority = false ) {
326
global $wp_filter, $merged_filters;
328
if ( isset( $wp_filter[ $tag ]) ) {
329
if ( false !== $priority && isset( $wp_filter[ $tag ][ $priority ] ) ) {
330
$wp_filter[ $tag ][ $priority ] = array();
332
$wp_filter[ $tag ] = array();
336
if ( isset( $merged_filters[ $tag ] ) ) {
337
unset( $merged_filters[ $tag ] );
344
* Retrieve the name of the current filter or action.
348
* @return string Hook name of the current filter or action.
350
function current_filter() {
351
global $wp_current_filter;
352
return end( $wp_current_filter );
356
* Retrieve the name of the current action.
360
* @uses current_filter()
362
* @return string Hook name of the current action.
364
function current_action() {
365
return current_filter();
369
* Retrieve the name of a filter currently being processed.
371
* The function current_filter() only returns the most recent filter or action
372
* being executed. did_action() returns true once the action is initially
375
* This function allows detection for any filter currently being
376
* executed (despite not being the most recent filter to fire, in the case of
377
* hooks called from hook callbacks) to be verified.
381
* @see current_filter()
383
* @global array $wp_current_filter Current filter.
385
* @param null|string $filter Optional. Filter to check. Defaults to null, which
386
* checks if any filter is currently being run.
387
* @return bool Whether the filter is currently in the stack.
389
function doing_filter( $filter = null ) {
390
global $wp_current_filter;
392
if ( null === $filter ) {
393
return ! empty( $wp_current_filter );
396
return in_array( $filter, $wp_current_filter );
400
* Retrieve the name of an action currently being processed.
404
* @uses doing_filter()
406
* @param string|null $action Optional. Action to check. Defaults to null, which checks
407
* if any action is currently being run.
408
* @return bool Whether the action is currently in the stack.
410
function doing_action( $action = null ) {
411
return doing_filter( $action );
415
* Hooks a function on to a specific action.
417
* Actions are the hooks that the WordPress core launches at specific points
418
* during execution, or when specific events occur. Plugins can specify that
419
* one or more of its PHP functions are executed at these points, using the
424
* @uses add_filter() Adds an action. Parameter list and functionality are the same.
426
* @param string $tag The name of the action to which the $function_to_add is hooked.
427
* @param callback $function_to_add The name of the function you wish to be called.
428
* @param int $priority Optional. Used to specify the order in which the functions
429
* associated with a particular action are executed. Default 10.
430
* Lower numbers correspond with earlier execution,
431
* and functions with the same priority are executed
432
* in the order in which they were added to the action.
433
* @param int $accepted_args Optional. The number of arguments the function accept. Default 1.
434
* @return bool Will always return true.
436
function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
437
return add_filter($tag, $function_to_add, $priority, $accepted_args);
441
* Execute functions hooked on a specific action hook.
443
* This function invokes all functions attached to action hook $tag. It is
444
* possible to create new action hooks by simply calling this function,
445
* specifying the name of the new hook using the <tt>$tag</tt> parameter.
447
* You can pass extra arguments to the hooks, much like you can with
452
* @see apply_filters() This function works similar with the exception that nothing
453
* is returned and only the functions or methods are called.
454
* @global array $wp_filter Stores all of the filters
455
* @global array $wp_actions Increments the amount of times action was triggered.
457
* @param string $tag The name of the action to be executed.
458
* @param mixed $arg Optional. Additional arguments which are passed on to the
459
* functions hooked to the action. Default empty.
460
* @return null Will return null if $tag does not exist in $wp_filter array.
462
function do_action($tag, $arg = '') {
463
global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter;
465
if ( ! isset($wp_actions[$tag]) )
466
$wp_actions[$tag] = 1;
470
// Do 'all' actions first
471
if ( isset($wp_filter['all']) ) {
472
$wp_current_filter[] = $tag;
473
$all_args = func_get_args();
474
_wp_call_all_hook($all_args);
477
if ( !isset($wp_filter[$tag]) ) {
478
if ( isset($wp_filter['all']) )
479
array_pop($wp_current_filter);
483
if ( !isset($wp_filter['all']) )
484
$wp_current_filter[] = $tag;
487
if ( is_array($arg) && 1 == count($arg) && isset($arg[0]) && is_object($arg[0]) ) // array(&$this)
491
for ( $a = 2; $a < func_num_args(); $a++ )
492
$args[] = func_get_arg($a);
495
if ( !isset( $merged_filters[ $tag ] ) ) {
496
ksort($wp_filter[$tag]);
497
$merged_filters[ $tag ] = true;
500
reset( $wp_filter[ $tag ] );
503
foreach ( (array) current($wp_filter[$tag]) as $the_ )
504
if ( !is_null($the_['function']) )
505
call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
507
} while ( next($wp_filter[$tag]) !== false );
509
array_pop($wp_current_filter);
513
* Retrieve the number of times an action is fired.
517
* @global array $wp_actions Increments the amount of times action was triggered.
519
* @param string $tag The name of the action hook.
520
* @return int The number of times action hook $tag is fired.
522
function did_action($tag) {
525
if ( ! isset( $wp_actions[ $tag ] ) )
528
return $wp_actions[$tag];
532
* Execute functions hooked on a specific action hook, specifying arguments in an array.
536
* @see do_action() This function is identical, but the arguments passed to the
537
* functions hooked to $tag< are supplied using an array.
538
* @global array $wp_filter Stores all of the filters
539
* @global array $wp_actions Increments the amount of times action was triggered.
541
* @param string $tag The name of the action to be executed.
542
* @param array $args The arguments supplied to the functions hooked to <tt>$tag</tt>
543
* @return null Will return null if $tag does not exist in $wp_filter array
545
function do_action_ref_array($tag, $args) {
546
global $wp_filter, $wp_actions, $merged_filters, $wp_current_filter;
548
if ( ! isset($wp_actions[$tag]) )
549
$wp_actions[$tag] = 1;
553
// Do 'all' actions first
554
if ( isset($wp_filter['all']) ) {
555
$wp_current_filter[] = $tag;
556
$all_args = func_get_args();
557
_wp_call_all_hook($all_args);
560
if ( !isset($wp_filter[$tag]) ) {
561
if ( isset($wp_filter['all']) )
562
array_pop($wp_current_filter);
566
if ( !isset($wp_filter['all']) )
567
$wp_current_filter[] = $tag;
570
if ( !isset( $merged_filters[ $tag ] ) ) {
571
ksort($wp_filter[$tag]);
572
$merged_filters[ $tag ] = true;
575
reset( $wp_filter[ $tag ] );
578
foreach( (array) current($wp_filter[$tag]) as $the_ )
579
if ( !is_null($the_['function']) )
580
call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));
582
} while ( next($wp_filter[$tag]) !== false );
584
array_pop($wp_current_filter);
588
* Check if any action has been registered for a hook.
592
* @see has_filter() has_action() is an alias of has_filter().
594
* @param string $tag The name of the action hook.
595
* @param callback|bool $function_to_check Optional. The callback to check for. Default false.
596
* @return bool|int If $function_to_check is omitted, returns boolean for whether the hook has
597
* anything registered. When checking a specific function, the priority of that
598
* hook is returned, or false if the function is not attached. When using the
599
* $function_to_check argument, this function may return a non-boolean value
600
* that evaluates to false (e.g.) 0, so use the === operator for testing the
603
function has_action($tag, $function_to_check = false) {
604
return has_filter($tag, $function_to_check);
608
* Removes a function from a specified action hook.
610
* This function removes a function attached to a specified action hook. This
611
* method can be used to remove default functions attached to a specific filter
612
* hook and possibly replace them with a substitute.
616
* @param string $tag The action hook to which the function to be removed is hooked.
617
* @param callback $function_to_remove The name of the function which should be removed.
618
* @param int $priority Optional. The priority of the function. Default 10.
619
* @return boolean Whether the function is removed.
621
function remove_action( $tag, $function_to_remove, $priority = 10 ) {
622
return remove_filter( $tag, $function_to_remove, $priority );
626
* Remove all of the hooks from an action.
630
* @param string $tag The action to remove hooks from.
631
* @param int|bool $priority The priority number to remove them from. Default false.
632
* @return bool True when finished.
634
function remove_all_actions($tag, $priority = false) {
635
return remove_all_filters($tag, $priority);
639
// Functions for handling plugins.
643
* Gets the basename of a plugin.
645
* This method extracts the name of a plugin from its filename.
649
* @uses WP_PLUGIN_DIR, WPMU_PLUGIN_DIR
651
* @param string $file The filename of plugin.
652
* @return string The name of a plugin.
654
function plugin_basename( $file ) {
655
global $wp_plugin_paths;
657
foreach ( $wp_plugin_paths as $dir => $realdir ) {
658
if ( strpos( $file, $realdir ) === 0 ) {
659
$file = $dir . substr( $file, strlen( $realdir ) );
663
$file = wp_normalize_path( $file );
664
$plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
665
$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
667
$file = preg_replace('#^' . preg_quote($plugin_dir, '#') . '/|^' . preg_quote($mu_plugin_dir, '#') . '/#','',$file); // get relative path from plugins dir
668
$file = trim($file, '/');
673
* Register a plugin's real path.
675
* This is used in plugin_basename() to resolve symlinked paths.
679
* @see plugin_basename()
681
* @param string $file Known path to the file.
682
* @return bool Whether the path was able to be registered.
684
function wp_register_plugin_realpath( $file ) {
685
global $wp_plugin_paths;
687
// Normalize, but store as static to avoid recalculation of a constant value
688
static $wp_plugin_path, $wpmu_plugin_path;
689
if ( ! isset( $wp_plugin_path ) ) {
690
$wp_plugin_path = wp_normalize_path( WP_PLUGIN_DIR );
691
$wpmu_plugin_path = wp_normalize_path( WPMU_PLUGIN_DIR );
694
$plugin_path = wp_normalize_path( dirname( $file ) );
695
$plugin_realpath = wp_normalize_path( dirname( realpath( $file ) ) );
697
if ( $plugin_path === $wp_plugin_path || $plugin_path === $wpmu_plugin_path ) {
701
if ( $plugin_path !== $plugin_realpath ) {
702
$wp_plugin_paths[ $plugin_path ] = $plugin_realpath;
709
* Get the filesystem directory path (with trailing slash) for the plugin __FILE__ passed in.
713
* @param string $file The filename of the plugin (__FILE__).
714
* @return string the filesystem path of the directory that contains the plugin.
716
function plugin_dir_path( $file ) {
717
return trailingslashit( dirname( $file ) );
721
* Get the URL directory path (with trailing slash) for the plugin __FILE__ passed in.
725
* @param string $file The filename of the plugin (__FILE__).
726
* @return string the URL path of the directory that contains the plugin.
728
function plugin_dir_url( $file ) {
729
return trailingslashit( plugins_url( '', $file ) );
733
* Set the activation hook for a plugin.
735
* When a plugin is activated, the action 'activate_PLUGINNAME' hook is
736
* called. In the name of this hook, PLUGINNAME is replaced with the name
737
* of the plugin, including the optional subdirectory. For example, when the
738
* plugin is located in wp-content/plugins/sampleplugin/sample.php, then
739
* the name of this hook will become 'activate_sampleplugin/sample.php'.
741
* When the plugin consists of only one file and is (as by default) located at
742
* wp-content/plugins/sample.php the name of this hook will be
743
* 'activate_sample.php'.
747
* @param string $file The filename of the plugin including the path.
748
* @param callback $function The function hooked to the 'activate_PLUGIN' action.
750
function register_activation_hook($file, $function) {
751
$file = plugin_basename($file);
752
add_action('activate_' . $file, $function);
756
* Set the deactivation hook for a plugin.
758
* When a plugin is deactivated, the action 'deactivate_PLUGINNAME' hook is
759
* called. In the name of this hook, PLUGINNAME is replaced with the name
760
* of the plugin, including the optional subdirectory. For example, when the
761
* plugin is located in wp-content/plugins/sampleplugin/sample.php, then
762
* the name of this hook will become 'deactivate_sampleplugin/sample.php'.
764
* When the plugin consists of only one file and is (as by default) located at
765
* wp-content/plugins/sample.php the name of this hook will be
766
* 'deactivate_sample.php'.
770
* @param string $file The filename of the plugin including the path.
771
* @param callback $function The function hooked to the 'deactivate_PLUGIN' action.
773
function register_deactivation_hook($file, $function) {
774
$file = plugin_basename($file);
775
add_action('deactivate_' . $file, $function);
779
* Set the uninstallation hook for a plugin.
781
* Registers the uninstall hook that will be called when the user clicks on the
782
* uninstall link that calls for the plugin to uninstall itself. The link won't
783
* be active unless the plugin hooks into the action.
785
* The plugin should not run arbitrary code outside of functions, when
786
* registering the uninstall hook. In order to run using the hook, the plugin
787
* will have to be included, which means that any code laying outside of a
788
* function will be run during the uninstall process. The plugin should not
789
* hinder the uninstall process.
791
* If the plugin can not be written without running code within the plugin, then
792
* the plugin should create a file named 'uninstall.php' in the base plugin
793
* folder. This file will be called, if it exists, during the uninstall process
794
* bypassing the uninstall hook. The plugin, when using the 'uninstall.php'
795
* should always check for the 'WP_UNINSTALL_PLUGIN' constant, before
800
* @param string $file Plugin file.
801
* @param callback $callback The callback to run when the hook is called. Must be
802
* a static method or function.
804
function register_uninstall_hook( $file, $callback ) {
805
if ( is_array( $callback ) && is_object( $callback[0] ) ) {
806
_doing_it_wrong( __FUNCTION__, __( 'Only a static class method or function can be used in an uninstall hook.' ), '3.1' );
811
* The option should not be autoloaded, because it is not needed in most
812
* cases. Emphasis should be put on using the 'uninstall.php' way of
813
* uninstalling the plugin.
815
$uninstallable_plugins = (array) get_option('uninstall_plugins');
816
$uninstallable_plugins[plugin_basename($file)] = $callback;
818
update_option('uninstall_plugins', $uninstallable_plugins);
822
* Call the 'all' hook, which will process the functions hooked into it.
824
* The 'all' hook passes all of the arguments or parameters that were used for
825
* the hook, which this function was called for.
827
* This function is used internally for apply_filters(), do_action(), and
828
* do_action_ref_array() and is not meant to be used from outside those
829
* functions. This function does not check for the existence of the all hook, so
830
* it will fail unless the all hook exists prior to this function call.
835
* @uses $wp_filter Used to process all of the functions in the 'all' hook.
837
* @param array $args The collected parameters from the hook that was called.
839
function _wp_call_all_hook($args) {
842
reset( $wp_filter['all'] );
844
foreach( (array) current($wp_filter['all']) as $the_ )
845
if ( !is_null($the_['function']) )
846
call_user_func_array($the_['function'], $args);
848
} while ( next($wp_filter['all']) !== false );
852
* Build Unique ID for storage and retrieval.
854
* The old way to serialize the callback caused issues and this function is the
855
* solution. It works by checking for objects and creating an a new property in
856
* the class to keep track of the object and new objects of the same class that
859
* It also allows for the removal of actions and filters for objects after they
860
* change class properties. It is possible to include the property $wp_filter_id
861
* in your class and set it to "null" or a number to bypass the workaround.
862
* However this will prevent you from adding new classes and any new classes
863
* will overwrite the previous hook by the same class.
865
* Functions and static method callbacks are just returned as strings and
866
* shouldn't have any speed penalty.
868
* @link http://trac.wordpress.org/ticket/3875
873
* @global array $wp_filter Storage for all of the filters and actions.
875
* @param string $tag Used in counting how many hooks were applied
876
* @param callback $function Used for creating unique id
877
* @param int|bool $priority Used in counting how many hooks were applied. If === false
878
* and $function is an object reference, we return the unique
879
* id only if it already has one, false otherwise.
880
* @return string|bool Unique ID for usage as array key or false if $priority === false
881
* and $function is an object reference, and it does not already have
884
function _wp_filter_build_unique_id($tag, $function, $priority) {
886
static $filter_id_count = 0;
888
if ( is_string($function) )
891
if ( is_object($function) ) {
892
// Closures are currently implemented as objects
893
$function = array( $function, '' );
895
$function = (array) $function;
898
if (is_object($function[0]) ) {
899
// Object Class Calling
900
if ( function_exists('spl_object_hash') ) {
901
return spl_object_hash($function[0]) . $function[1];
903
$obj_idx = get_class($function[0]).$function[1];
904
if ( !isset($function[0]->wp_filter_id) ) {
905
if ( false === $priority )
907
$obj_idx .= isset($wp_filter[$tag][$priority]) ? count((array)$wp_filter[$tag][$priority]) : $filter_id_count;
908
$function[0]->wp_filter_id = $filter_id_count;
911
$obj_idx .= $function[0]->wp_filter_id;
916
} else if ( is_string($function[0]) ) {
918
return $function[0] . '::' . $function[1];