6 * |
6 * |
7 * The API callback examples reference functions, but can be methods of classes. |
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. |
8 * To hook methods, you'll need to pass an array one of two ways. |
9 * |
9 * |
10 * Any of the syntaxes explained in the PHP documentation for the |
10 * Any of the syntaxes explained in the PHP documentation for the |
11 * {@link https://secure.php.net/manual/en/language.pseudo-types.php#language.types.callback 'callback'} |
11 * {@link https://www.php.net/manual/en/language.pseudo-types.php#language.types.callback 'callback'} |
12 * type are valid. |
12 * type are valid. |
13 * |
13 * |
14 * Also see the {@link https://codex.wordpress.org/Plugin_API Plugin API} for |
14 * Also see the {@link https://developer.wordpress.org/plugins/ Plugin API} for |
15 * more information and examples on how to use a lot of these functions. |
15 * more information and examples on how to use a lot of these functions. |
16 * |
16 * |
17 * This file should have no external dependencies. |
17 * This file should have no external dependencies. |
18 * |
18 * |
19 * @package WordPress |
19 * @package WordPress |
20 * @subpackage Plugin |
20 * @subpackage Plugin |
21 * @since 1.5.0 |
21 * @since 1.5.0 |
22 */ |
22 */ |
23 |
23 |
24 // Initialize the filter globals. |
24 // Initialize the filter globals. |
25 require( dirname( __FILE__ ) . '/class-wp-hook.php' ); |
25 require __DIR__ . '/class-wp-hook.php'; |
26 |
26 |
27 /** @var WP_Hook[] $wp_filter */ |
27 /** @var WP_Hook[] $wp_filter */ |
28 global $wp_filter, $wp_actions, $wp_current_filter; |
28 global $wp_filter, $wp_actions, $wp_current_filter; |
29 |
29 |
30 if ( $wp_filter ) { |
30 if ( $wp_filter ) { |
91 * It is up to you to take care. This is done for optimization purposes, so |
91 * It is up to you to take care. This is done for optimization purposes, so |
92 * everything is as quick as possible. |
92 * everything is as quick as possible. |
93 * |
93 * |
94 * @since 0.71 |
94 * @since 0.71 |
95 * |
95 * |
96 * @global array $wp_filter A multidimensional array of all hooks and the callbacks hooked to them. |
96 * @global array $wp_filter A multidimensional array of all hooks and the callbacks hooked to them. |
97 * |
97 * |
98 * @param string $tag The name of the filter to hook the $function_to_add callback to. |
98 * @param string $tag The name of the filter to hook the $function_to_add callback to. |
99 * @param callable $function_to_add The callback to be run when the filter is applied. |
99 * @param callable $function_to_add The callback to be run when the filter is applied. |
100 * @param int $priority Optional. Used to specify the order in which the functions |
100 * @param int $priority Optional. Used to specify the order in which the functions |
101 * associated with a particular action are executed. Default 10. |
101 * associated with a particular action are executed. |
102 * Lower numbers correspond with earlier execution, |
102 * Lower numbers correspond with earlier execution, |
103 * and functions with the same priority are executed |
103 * and functions with the same priority are executed |
104 * in the order in which they were added to the action. |
104 * in the order in which they were added to the action. Default 10. |
105 * @param int $accepted_args Optional. The number of arguments the function accepts. Default 1. |
105 * @param int $accepted_args Optional. The number of arguments the function accepts. Default 1. |
106 * @return true |
106 * @return true |
107 */ |
107 */ |
108 function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) { |
108 function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) { |
109 global $wp_filter; |
109 global $wp_filter; |
117 /** |
117 /** |
118 * Check if any filter has been registered for a hook. |
118 * Check if any filter has been registered for a hook. |
119 * |
119 * |
120 * @since 2.5.0 |
120 * @since 2.5.0 |
121 * |
121 * |
122 * @global array $wp_filter Stores all of the filters. |
122 * @global array $wp_filter Stores all of the filters and actions. |
123 * |
123 * |
124 * @param string $tag The name of the filter hook. |
124 * @param string $tag The name of the filter hook. |
125 * @param callable|bool $function_to_check Optional. The callback to check for. Default false. |
125 * @param callable|bool $function_to_check Optional. The callback to check for. Default false. |
126 * @return false|int If $function_to_check is omitted, returns boolean for whether the hook has |
126 * @return false|int If $function_to_check is omitted, returns boolean for whether the hook has |
127 * anything registered. When checking a specific function, the priority of that |
127 * anything registered. When checking a specific function, the priority of that |
139 |
139 |
140 return $wp_filter[ $tag ]->has_filter( $tag, $function_to_check ); |
140 return $wp_filter[ $tag ]->has_filter( $tag, $function_to_check ); |
141 } |
141 } |
142 |
142 |
143 /** |
143 /** |
144 * Call the functions added to a filter hook. |
144 * Calls the callback functions that have been added to a filter hook. |
145 * |
145 * |
146 * The callback functions attached to filter hook $tag are invoked by calling |
146 * The callback functions attached to the filter hook are invoked by calling |
147 * this function. This function can be used to create a new filter hook by |
147 * this function. This function can be used to create a new filter hook by |
148 * simply calling this function with the name of the new hook specified using |
148 * simply calling this function with the name of the new hook specified using |
149 * the $tag parameter. |
149 * the `$tag` parameter. |
150 * |
150 * |
151 * The function allows for additional arguments to be added and passed to hooks. |
151 * The function also allows for multiple additional arguments to be passed to hooks. |
152 * |
152 * |
153 * // Our filter callback function |
153 * Example usage: |
|
154 * |
|
155 * // The filter callback function. |
154 * function example_callback( $string, $arg1, $arg2 ) { |
156 * function example_callback( $string, $arg1, $arg2 ) { |
155 * // (maybe) modify $string |
157 * // (maybe) modify $string. |
156 * return $string; |
158 * return $string; |
157 * } |
159 * } |
158 * add_filter( 'example_filter', 'example_callback', 10, 3 ); |
160 * add_filter( 'example_filter', 'example_callback', 10, 3 ); |
159 * |
161 * |
160 * /* |
162 * /* |
161 * * Apply the filters by calling the 'example_callback' function we |
163 * * Apply the filters by calling the 'example_callback()' function |
162 * * "hooked" to 'example_filter' using the add_filter() function above. |
164 * * that's hooked onto `example_filter` above. |
163 * * - 'example_filter' is the filter hook $tag |
165 * * |
164 * * - 'filter me' is the value being filtered |
166 * * - 'example_filter' is the filter hook. |
|
167 * * - 'filter me' is the value being filtered. |
165 * * - $arg1 and $arg2 are the additional arguments passed to the callback. |
168 * * - $arg1 and $arg2 are the additional arguments passed to the callback. |
166 * $value = apply_filters( 'example_filter', 'filter me', $arg1, $arg2 ); |
169 * $value = apply_filters( 'example_filter', 'filter me', $arg1, $arg2 ); |
167 * |
170 * |
168 * @since 0.71 |
171 * @since 0.71 |
169 * |
172 * |
170 * @global array $wp_filter Stores all of the filters. |
173 * @global array $wp_filter Stores all of the filters and actions. |
171 * @global array $wp_current_filter Stores the list of current filters with the current one last. |
174 * @global array $wp_current_filter Stores the list of current filters with the current one last. |
172 * |
175 * |
173 * @param string $tag The name of the filter hook. |
176 * @param string $tag The name of the filter hook. |
174 * @param mixed $value The value on which the filters hooked to `$tag` are applied on. |
177 * @param mixed $value The value to filter. |
175 * @param mixed $var,... Additional variables passed to the functions hooked to `$tag`. |
178 * @param mixed ...$args Additional parameters to pass to the callback functions. |
176 * @return mixed The filtered value after all hooked functions are applied to it. |
179 * @return mixed The filtered value after all hooked functions are applied to it. |
177 */ |
180 */ |
178 function apply_filters( $tag, $value ) { |
181 function apply_filters( $tag, $value ) { |
179 global $wp_filter, $wp_current_filter; |
182 global $wp_filter, $wp_current_filter; |
180 |
183 |
181 $args = array(); |
184 $args = func_get_args(); |
182 |
185 |
183 // Do 'all' actions first. |
186 // Do 'all' actions first. |
184 if ( isset( $wp_filter['all'] ) ) { |
187 if ( isset( $wp_filter['all'] ) ) { |
185 $wp_current_filter[] = $tag; |
188 $wp_current_filter[] = $tag; |
186 $args = func_get_args(); |
|
187 _wp_call_all_hook( $args ); |
189 _wp_call_all_hook( $args ); |
188 } |
190 } |
189 |
191 |
190 if ( ! isset( $wp_filter[ $tag ] ) ) { |
192 if ( ! isset( $wp_filter[ $tag ] ) ) { |
191 if ( isset( $wp_filter['all'] ) ) { |
193 if ( isset( $wp_filter['all'] ) ) { |
196 |
198 |
197 if ( ! isset( $wp_filter['all'] ) ) { |
199 if ( ! isset( $wp_filter['all'] ) ) { |
198 $wp_current_filter[] = $tag; |
200 $wp_current_filter[] = $tag; |
199 } |
201 } |
200 |
202 |
201 if ( empty( $args ) ) { |
203 // Don't pass the tag name to WP_Hook. |
202 $args = func_get_args(); |
|
203 } |
|
204 |
|
205 // don't pass the tag name to WP_Hook |
|
206 array_shift( $args ); |
204 array_shift( $args ); |
207 |
205 |
208 $filtered = $wp_filter[ $tag ]->apply_filters( $value, $args ); |
206 $filtered = $wp_filter[ $tag ]->apply_filters( $value, $args ); |
209 |
207 |
210 array_pop( $wp_current_filter ); |
208 array_pop( $wp_current_filter ); |
211 |
209 |
212 return $filtered; |
210 return $filtered; |
213 } |
211 } |
214 |
212 |
215 /** |
213 /** |
216 * Execute functions hooked on a specific filter hook, specifying arguments in an array. |
214 * Calls the callback functions that have been added to a filter hook, specifying arguments in an array. |
217 * |
215 * |
218 * @since 3.0.0 |
216 * @since 3.0.0 |
219 * |
217 * |
220 * @see apply_filters() This function is identical, but the arguments passed to the |
218 * @see apply_filters() This function is identical, but the arguments passed to the |
221 * functions hooked to `$tag` are supplied using an array. |
219 * functions hooked to `$tag` are supplied using an array. |
222 * |
220 * |
223 * @global array $wp_filter Stores all of the filters |
221 * @global array $wp_filter Stores all of the filters and actions. |
224 * @global array $wp_current_filter Stores the list of current filters with the current one last |
222 * @global array $wp_current_filter Stores the list of current filters with the current one last. |
225 * |
223 * |
226 * @param string $tag The name of the filter hook. |
224 * @param string $tag The name of the filter hook. |
227 * @param array $args The arguments supplied to the functions hooked to $tag. |
225 * @param array $args The arguments supplied to the functions hooked to $tag. |
228 * @return mixed The filtered value after all hooked functions are applied to it. |
226 * @return mixed The filtered value after all hooked functions are applied to it. |
229 */ |
227 */ |
230 function apply_filters_ref_array( $tag, $args ) { |
228 function apply_filters_ref_array( $tag, $args ) { |
231 global $wp_filter, $wp_current_filter; |
229 global $wp_filter, $wp_current_filter; |
232 |
230 |
233 // Do 'all' actions first |
231 // Do 'all' actions first. |
234 if ( isset( $wp_filter['all'] ) ) { |
232 if ( isset( $wp_filter['all'] ) ) { |
235 $wp_current_filter[] = $tag; |
233 $wp_current_filter[] = $tag; |
236 $all_args = func_get_args(); |
234 $all_args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection |
237 _wp_call_all_hook( $all_args ); |
235 _wp_call_all_hook( $all_args ); |
238 } |
236 } |
239 |
237 |
240 if ( ! isset( $wp_filter[ $tag ] ) ) { |
238 if ( ! isset( $wp_filter[ $tag ] ) ) { |
241 if ( isset( $wp_filter['all'] ) ) { |
239 if ( isset( $wp_filter['all'] ) ) { |
266 * when the hook was added. This goes for both filters and actions. No warning |
264 * when the hook was added. This goes for both filters and actions. No warning |
267 * will be given on removal failure. |
265 * will be given on removal failure. |
268 * |
266 * |
269 * @since 1.2.0 |
267 * @since 1.2.0 |
270 * |
268 * |
271 * @global array $wp_filter Stores all of the filters |
269 * @global array $wp_filter Stores all of the filters and actions. |
272 * |
270 * |
273 * @param string $tag The filter hook to which the function to be removed is hooked. |
271 * @param string $tag The filter hook to which the function to be removed is hooked. |
274 * @param callable $function_to_remove The name of the function which should be removed. |
272 * @param callable $function_to_remove The name of the function which should be removed. |
275 * @param int $priority Optional. The priority of the function. Default 10. |
273 * @param int $priority Optional. The priority of the function. Default 10. |
276 * @return bool Whether the function existed before it was removed. |
274 * @return bool Whether the function existed before it was removed. |
411 * |
409 * |
412 * This function invokes all functions attached to action hook `$tag`. It is |
410 * This function invokes all functions attached to action hook `$tag`. It is |
413 * possible to create new action hooks by simply calling this function, |
411 * possible to create new action hooks by simply calling this function, |
414 * specifying the name of the new hook using the `$tag` parameter. |
412 * specifying the name of the new hook using the `$tag` parameter. |
415 * |
413 * |
416 * You can pass extra arguments to the hooks, much like you can with apply_filters(). |
414 * You can pass extra arguments to the hooks, much like you can with `apply_filters()`. |
|
415 * |
|
416 * Example usage: |
|
417 * |
|
418 * // The action callback function. |
|
419 * function example_callback( $arg1, $arg2 ) { |
|
420 * // (maybe) do something with the args. |
|
421 * } |
|
422 * add_action( 'example_action', 'example_callback', 10, 2 ); |
|
423 * |
|
424 * /* |
|
425 * * Trigger the actions by calling the 'example_callback()' function |
|
426 * * that's hooked onto `example_action` above. |
|
427 * * |
|
428 * * - 'example_action' is the action hook. |
|
429 * * - $arg1 and $arg2 are the additional arguments passed to the callback. |
|
430 * $value = do_action( 'example_action', $arg1, $arg2 ); |
417 * |
431 * |
418 * @since 1.2.0 |
432 * @since 1.2.0 |
419 * |
433 * @since 5.3.0 Formalized the existing and already documented `...$arg` parameter |
420 * @global array $wp_filter Stores all of the filters |
434 * by adding it to the function signature. |
|
435 * |
|
436 * @global array $wp_filter Stores all of the filters and actions. |
421 * @global array $wp_actions Increments the amount of times action was triggered. |
437 * @global array $wp_actions Increments the amount of times action was triggered. |
422 * @global array $wp_current_filter Stores the list of current filters with the current one last |
438 * @global array $wp_current_filter Stores the list of current filters with the current one last. |
423 * |
439 * |
424 * @param string $tag The name of the action to be executed. |
440 * @param string $tag The name of the action to be executed. |
425 * @param mixed $arg,... Optional. Additional arguments which are passed on to the |
441 * @param mixed ...$arg Optional. Additional arguments which are passed on to the |
426 * functions hooked to the action. Default empty. |
442 * functions hooked to the action. Default empty. |
427 */ |
443 */ |
428 function do_action( $tag, $arg = '' ) { |
444 function do_action( $tag, ...$arg ) { |
429 global $wp_filter, $wp_actions, $wp_current_filter; |
445 global $wp_filter, $wp_actions, $wp_current_filter; |
430 |
446 |
431 if ( ! isset( $wp_actions[ $tag ] ) ) { |
447 if ( ! isset( $wp_actions[ $tag ] ) ) { |
432 $wp_actions[ $tag ] = 1; |
448 $wp_actions[ $tag ] = 1; |
433 } else { |
449 } else { |
434 ++$wp_actions[ $tag ]; |
450 ++$wp_actions[ $tag ]; |
435 } |
451 } |
436 |
452 |
437 // Do 'all' actions first |
453 // Do 'all' actions first. |
438 if ( isset( $wp_filter['all'] ) ) { |
454 if ( isset( $wp_filter['all'] ) ) { |
439 $wp_current_filter[] = $tag; |
455 $wp_current_filter[] = $tag; |
440 $all_args = func_get_args(); |
456 $all_args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection |
441 _wp_call_all_hook( $all_args ); |
457 _wp_call_all_hook( $all_args ); |
442 } |
458 } |
443 |
459 |
444 if ( ! isset( $wp_filter[ $tag ] ) ) { |
460 if ( ! isset( $wp_filter[ $tag ] ) ) { |
445 if ( isset( $wp_filter['all'] ) ) { |
461 if ( isset( $wp_filter['all'] ) ) { |
486 |
499 |
487 return $wp_actions[ $tag ]; |
500 return $wp_actions[ $tag ]; |
488 } |
501 } |
489 |
502 |
490 /** |
503 /** |
491 * Execute functions hooked on a specific action hook, specifying arguments in an array. |
504 * Calls the callback functions that have been added to an action hook, specifying arguments in an array. |
492 * |
505 * |
493 * @since 2.1.0 |
506 * @since 2.1.0 |
494 * |
507 * |
495 * @see do_action() This function is identical, but the arguments passed to the |
508 * @see do_action() This function is identical, but the arguments passed to the |
496 * functions hooked to $tag< are supplied using an array. |
509 * functions hooked to `$tag` are supplied using an array. |
497 * @global array $wp_filter Stores all of the filters |
510 * @global array $wp_filter Stores all of the filters and actions. |
498 * @global array $wp_actions Increments the amount of times action was triggered. |
511 * @global array $wp_actions Increments the amount of times action was triggered. |
499 * @global array $wp_current_filter Stores the list of current filters with the current one last |
512 * @global array $wp_current_filter Stores the list of current filters with the current one last. |
500 * |
513 * |
501 * @param string $tag The name of the action to be executed. |
514 * @param string $tag The name of the action to be executed. |
502 * @param array $args The arguments supplied to the functions hooked to `$tag`. |
515 * @param array $args The arguments supplied to the functions hooked to `$tag`. |
503 */ |
516 */ |
504 function do_action_ref_array( $tag, $args ) { |
517 function do_action_ref_array( $tag, $args ) { |
508 $wp_actions[ $tag ] = 1; |
521 $wp_actions[ $tag ] = 1; |
509 } else { |
522 } else { |
510 ++$wp_actions[ $tag ]; |
523 ++$wp_actions[ $tag ]; |
511 } |
524 } |
512 |
525 |
513 // Do 'all' actions first |
526 // Do 'all' actions first. |
514 if ( isset( $wp_filter['all'] ) ) { |
527 if ( isset( $wp_filter['all'] ) ) { |
515 $wp_current_filter[] = $tag; |
528 $wp_current_filter[] = $tag; |
516 $all_args = func_get_args(); |
529 $all_args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection |
517 _wp_call_all_hook( $all_args ); |
530 _wp_call_all_hook( $all_args ); |
518 } |
531 } |
519 |
532 |
520 if ( ! isset( $wp_filter[ $tag ] ) ) { |
533 if ( ! isset( $wp_filter[ $tag ] ) ) { |
521 if ( isset( $wp_filter['all'] ) ) { |
534 if ( isset( $wp_filter['all'] ) ) { |
596 * |
609 * |
597 * // Old filter. |
610 * // Old filter. |
598 * return apply_filters( 'wpdocs_filter', $value, $extra_arg ); |
611 * return apply_filters( 'wpdocs_filter', $value, $extra_arg ); |
599 * |
612 * |
600 * // Deprecated. |
613 * // Deprecated. |
601 * return apply_filters_deprecated( 'wpdocs_filter', array( $value, $extra_arg ), '4.9', 'wpdocs_new_filter' ); |
614 * return apply_filters_deprecated( 'wpdocs_filter', array( $value, $extra_arg ), '4.9.0', 'wpdocs_new_filter' ); |
602 * |
615 * |
603 * @since 4.6.0 |
616 * @since 4.6.0 |
604 * |
617 * |
605 * @see _deprecated_hook() |
618 * @see _deprecated_hook() |
606 * |
619 * |
607 * @param string $tag The name of the filter hook. |
620 * @param string $tag The name of the filter hook. |
608 * @param array $args Array of additional function arguments to be passed to apply_filters(). |
621 * @param array $args Array of additional function arguments to be passed to apply_filters(). |
609 * @param string $version The version of WordPress that deprecated the hook. |
622 * @param string $version The version of WordPress that deprecated the hook. |
610 * @param string $replacement Optional. The hook that should have been used. Default false. |
623 * @param string $replacement Optional. The hook that should have been used. Default empty. |
611 * @param string $message Optional. A message regarding the change. Default null. |
624 * @param string $message Optional. A message regarding the change. Default empty. |
612 */ |
625 */ |
613 function apply_filters_deprecated( $tag, $args, $version, $replacement = false, $message = null ) { |
626 function apply_filters_deprecated( $tag, $args, $version, $replacement = '', $message = '' ) { |
614 if ( ! has_filter( $tag ) ) { |
627 if ( ! has_filter( $tag ) ) { |
615 return $args[0]; |
628 return $args[0]; |
616 } |
629 } |
617 |
630 |
618 _deprecated_hook( $tag, $version, $replacement, $message ); |
631 _deprecated_hook( $tag, $version, $replacement, $message ); |
632 * @see _deprecated_hook() |
645 * @see _deprecated_hook() |
633 * |
646 * |
634 * @param string $tag The name of the action hook. |
647 * @param string $tag The name of the action hook. |
635 * @param array $args Array of additional function arguments to be passed to do_action(). |
648 * @param array $args Array of additional function arguments to be passed to do_action(). |
636 * @param string $version The version of WordPress that deprecated the hook. |
649 * @param string $version The version of WordPress that deprecated the hook. |
637 * @param string $replacement Optional. The hook that should have been used. |
650 * @param string $replacement Optional. The hook that should have been used. Default empty. |
638 * @param string $message Optional. A message regarding the change. |
651 * @param string $message Optional. A message regarding the change. Default empty. |
639 */ |
652 */ |
640 function do_action_deprecated( $tag, $args, $version, $replacement = false, $message = null ) { |
653 function do_action_deprecated( $tag, $args, $version, $replacement = '', $message = '' ) { |
641 if ( ! has_action( $tag ) ) { |
654 if ( ! has_action( $tag ) ) { |
642 return; |
655 return; |
643 } |
656 } |
644 |
657 |
645 _deprecated_hook( $tag, $version, $replacement, $message ); |
658 _deprecated_hook( $tag, $version, $replacement, $message ); |
693 * |
707 * |
694 * @see wp_normalize_path() |
708 * @see wp_normalize_path() |
695 * |
709 * |
696 * @global array $wp_plugin_paths |
710 * @global array $wp_plugin_paths |
697 * |
711 * |
698 * @staticvar string $wp_plugin_path |
|
699 * @staticvar string $wpmu_plugin_path |
|
700 * |
|
701 * @param string $file Known path to the file. |
712 * @param string $file Known path to the file. |
702 * @return bool Whether the path was able to be registered. |
713 * @return bool Whether the path was able to be registered. |
703 */ |
714 */ |
704 function wp_register_plugin_realpath( $file ) { |
715 function wp_register_plugin_realpath( $file ) { |
705 global $wp_plugin_paths; |
716 global $wp_plugin_paths; |
706 |
717 |
707 // Normalize, but store as static to avoid recalculation of a constant value |
718 // Normalize, but store as static to avoid recalculation of a constant value. |
708 static $wp_plugin_path = null, $wpmu_plugin_path = null; |
719 static $wp_plugin_path = null, $wpmu_plugin_path = null; |
709 if ( ! isset( $wp_plugin_path ) ) { |
720 if ( ! isset( $wp_plugin_path ) ) { |
710 $wp_plugin_path = wp_normalize_path( WP_PLUGIN_DIR ); |
721 $wp_plugin_path = wp_normalize_path( WP_PLUGIN_DIR ); |
711 $wpmu_plugin_path = wp_normalize_path( WPMU_PLUGIN_DIR ); |
722 $wpmu_plugin_path = wp_normalize_path( WPMU_PLUGIN_DIR ); |
712 } |
723 } |
830 /* |
841 /* |
831 * The option should not be autoloaded, because it is not needed in most |
842 * The option should not be autoloaded, because it is not needed in most |
832 * cases. Emphasis should be put on using the 'uninstall.php' way of |
843 * cases. Emphasis should be put on using the 'uninstall.php' way of |
833 * uninstalling the plugin. |
844 * uninstalling the plugin. |
834 */ |
845 */ |
835 $uninstallable_plugins = (array) get_option( 'uninstall_plugins' ); |
846 $uninstallable_plugins = (array) get_option( 'uninstall_plugins' ); |
836 $uninstallable_plugins[ plugin_basename( $file ) ] = $callback; |
847 $plugin_basename = plugin_basename( $file ); |
837 |
848 if ( ! isset( $uninstallable_plugins[ $plugin_basename ] ) || $uninstallable_plugins[ $plugin_basename ] !== $callback ) { |
838 update_option( 'uninstall_plugins', $uninstallable_plugins ); |
849 $uninstallable_plugins[ $plugin_basename ] = $callback; |
|
850 update_option( 'uninstall_plugins', $uninstallable_plugins ); |
|
851 } |
839 } |
852 } |
840 |
853 |
841 /** |
854 /** |
842 * Call the 'all' hook, which will process the functions hooked into it. |
855 * Call the 'all' hook, which will process the functions hooked into it. |
843 * |
856 * |
880 * shouldn't have any speed penalty. |
893 * shouldn't have any speed penalty. |
881 * |
894 * |
882 * @link https://core.trac.wordpress.org/ticket/3875 |
895 * @link https://core.trac.wordpress.org/ticket/3875 |
883 * |
896 * |
884 * @since 2.2.3 |
897 * @since 2.2.3 |
|
898 * @since 5.3.0 Removed workarounds for spl_object_hash(). |
|
899 * `$tag` and `$priority` are no longer used, |
|
900 * and the function always returns a string. |
885 * @access private |
901 * @access private |
886 * |
902 * |
887 * @global array $wp_filter Storage for all of the filters and actions. |
903 * @param string $tag Unused. The name of the filter to build ID for. |
888 * @staticvar int $filter_id_count |
904 * @param callable $function The function to generate ID for. |
889 * |
905 * @param int $priority Unused. The order in which the functions |
890 * @param string $tag Used in counting how many hooks were applied |
906 * associated with a particular action are executed. |
891 * @param callable $function Used for creating unique id |
907 * @return string Unique function ID for usage as array key. |
892 * @param int|bool $priority Used in counting how many hooks were applied. If === false |
|
893 * and $function is an object reference, we return the unique |
|
894 * id only if it already has one, false otherwise. |
|
895 * @return string|false Unique ID for usage as array key or false if $priority === false |
|
896 * and $function is an object reference, and it does not already have |
|
897 * a unique id. |
|
898 */ |
908 */ |
899 function _wp_filter_build_unique_id( $tag, $function, $priority ) { |
909 function _wp_filter_build_unique_id( $tag, $function, $priority ) { |
900 global $wp_filter; |
|
901 static $filter_id_count = 0; |
|
902 |
|
903 if ( is_string( $function ) ) { |
910 if ( is_string( $function ) ) { |
904 return $function; |
911 return $function; |
905 } |
912 } |
906 |
913 |
907 if ( is_object( $function ) ) { |
914 if ( is_object( $function ) ) { |
908 // Closures are currently implemented as objects |
915 // Closures are currently implemented as objects. |
909 $function = array( $function, '' ); |
916 $function = array( $function, '' ); |
910 } else { |
917 } else { |
911 $function = (array) $function; |
918 $function = (array) $function; |
912 } |
919 } |
913 |
920 |
914 if ( is_object( $function[0] ) ) { |
921 if ( is_object( $function[0] ) ) { |
915 // Object Class Calling |
922 // Object class calling. |
916 if ( function_exists( 'spl_object_hash' ) ) { |
923 return spl_object_hash( $function[0] ) . $function[1]; |
917 return spl_object_hash( $function[0] ) . $function[1]; |
|
918 } else { |
|
919 $obj_idx = get_class( $function[0] ) . $function[1]; |
|
920 if ( ! isset( $function[0]->wp_filter_id ) ) { |
|
921 if ( false === $priority ) { |
|
922 return false; |
|
923 } |
|
924 $obj_idx .= isset( $wp_filter[ $tag ][ $priority ] ) ? count( (array) $wp_filter[ $tag ][ $priority ] ) : $filter_id_count; |
|
925 $function[0]->wp_filter_id = $filter_id_count; |
|
926 ++$filter_id_count; |
|
927 } else { |
|
928 $obj_idx .= $function[0]->wp_filter_id; |
|
929 } |
|
930 |
|
931 return $obj_idx; |
|
932 } |
|
933 } elseif ( is_string( $function[0] ) ) { |
924 } elseif ( is_string( $function[0] ) ) { |
934 // Static Calling |
925 // Static calling. |
935 return $function[0] . '::' . $function[1]; |
926 return $function[0] . '::' . $function[1]; |
936 } |
927 } |
937 } |
928 } |