author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
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. |
|
6 |
* |
|
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. |
|
9 |
* |
|
10 |
* Any of the syntaxes explained in the PHP documentation for the |
|
16 | 11 |
* {@link https://www.php.net/manual/en/language.pseudo-types.php#language.types.callback 'callback'} |
0 | 12 |
* type are valid. |
13 |
* |
|
16 | 14 |
* Also see the {@link https://developer.wordpress.org/plugins/ Plugin API} for |
0 | 15 |
* more information and examples on how to use a lot of these functions. |
16 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
* This file should have no external dependencies. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
* |
0 | 19 |
* @package WordPress |
20 |
* @subpackage Plugin |
|
5 | 21 |
* @since 1.5.0 |
0 | 22 |
*/ |
23 |
||
24 |
// Initialize the filter globals. |
|
16 | 25 |
require __DIR__ . '/class-wp-hook.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
/** @var WP_Hook[] $wp_filter */ |
18 | 28 |
global $wp_filter; |
29 |
||
30 |
/** @var int[] $wp_actions */ |
|
31 |
global $wp_actions; |
|
32 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
33 |
/** @var int[] $wp_filters */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
34 |
global $wp_filters; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
35 |
|
18 | 36 |
/** @var string[] $wp_current_filter */ |
37 |
global $wp_current_filter; |
|
0 | 38 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
if ( $wp_filter ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
$wp_filter = WP_Hook::build_preinitialized_hooks( $wp_filter ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
} else { |
0 | 42 |
$wp_filter = array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
} |
0 | 44 |
|
9 | 45 |
if ( ! isset( $wp_actions ) ) { |
0 | 46 |
$wp_actions = array(); |
9 | 47 |
} |
0 | 48 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
49 |
if ( ! isset( $wp_filters ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
50 |
$wp_filters = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
51 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
52 |
|
9 | 53 |
if ( ! isset( $wp_current_filter ) ) { |
0 | 54 |
$wp_current_filter = array(); |
9 | 55 |
} |
0 | 56 |
|
57 |
/** |
|
18 | 58 |
* Adds a callback function to a filter hook. |
0 | 59 |
* |
60 |
* WordPress offers filter hooks to allow plugins to modify |
|
61 |
* various types of internal data at runtime. |
|
62 |
* |
|
63 |
* A plugin can modify data by binding a callback to a filter hook. When the filter |
|
64 |
* is later applied, each bound callback is run in order of priority, and given |
|
65 |
* the opportunity to modify a value by returning a new value. |
|
66 |
* |
|
67 |
* The following example shows how a callback function is bound to a filter hook. |
|
5 | 68 |
* |
69 |
* Note that `$example` is passed to the callback, (maybe) modified, then returned: |
|
0 | 70 |
* |
5 | 71 |
* function example_callback( $example ) { |
72 |
* // Maybe modify $example in some way. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
* return $example; |
5 | 74 |
* } |
75 |
* add_filter( 'example_filter', 'example_callback' ); |
|
0 | 76 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
77 |
* Bound callbacks can accept from none to the total number of arguments passed as parameters |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
78 |
* in the corresponding apply_filters() call. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
79 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
* In other words, if an apply_filters() call passes four total arguments, callbacks bound to |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
81 |
* it can accept none (the same as 1) of the arguments or up to four. The important part is that |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
* the `$accepted_args` value must reflect the number of arguments the bound callback *actually* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
* opted to accept. If no arguments were accepted by the callback that is considered to be the |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
* same as accepting 1 argument. For example: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
* // Filter call. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
87 |
* $value = apply_filters( 'hook', $value, $arg2, $arg3 ); |
0 | 88 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
* // Accepting zero/one arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
* function example_callback() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
91 |
* ... |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
* return 'some value'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
94 |
* add_filter( 'hook', 'example_callback' ); // Where $priority is default 10, $accepted_args is default 1. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
95 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
96 |
* // Accepting two arguments (three possible). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
97 |
* function example_callback( $value, $arg2 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
98 |
* ... |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
99 |
* return $maybe_modified_value; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
100 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
* add_filter( 'hook', 'example_callback', 10, 2 ); // Where $priority is 10, $accepted_args is 2. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
* *Note:* The function will return true whether or not the callback is valid. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
* It is up to you to take care. This is done for optimization purposes, so |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
* everything is as quick as possible. |
0 | 106 |
* |
107 |
* @since 0.71 |
|
108 |
* |
|
18 | 109 |
* @global WP_Hook[] $wp_filter A multidimensional array of all hooks and the callbacks hooked to them. |
5 | 110 |
* |
18 | 111 |
* @param string $hook_name The name of the filter to add the callback to. |
112 |
* @param callable $callback The callback to be run when the filter is applied. |
|
113 |
* @param int $priority Optional. Used to specify the order in which the functions |
|
114 |
* associated with a particular filter are executed. |
|
115 |
* Lower numbers correspond with earlier execution, |
|
116 |
* and functions with the same priority are executed |
|
117 |
* in the order in which they were added to the filter. Default 10. |
|
118 |
* @param int $accepted_args Optional. The number of arguments the function accepts. Default 1. |
|
119 |
* @return true Always returns true. |
|
0 | 120 |
*/ |
18 | 121 |
function add_filter( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
global $wp_filter; |
0 | 123 |
|
18 | 124 |
if ( ! isset( $wp_filter[ $hook_name ] ) ) { |
125 |
$wp_filter[ $hook_name ] = new WP_Hook(); |
|
5 | 126 |
} |
127 |
||
18 | 128 |
$wp_filter[ $hook_name ]->add_filter( $hook_name, $callback, $priority, $accepted_args ); |
129 |
||
130 |
return true; |
|
0 | 131 |
} |
132 |
||
133 |
/** |
|
16 | 134 |
* Calls the callback functions that have been added to a filter hook. |
0 | 135 |
* |
18 | 136 |
* This function invokes all functions attached to filter hook `$hook_name`. |
137 |
* It is possible to create new filter hooks by simply calling this function, |
|
138 |
* specifying the name of the new hook using the `$hook_name` parameter. |
|
0 | 139 |
* |
16 | 140 |
* The function also allows for multiple additional arguments to be passed to hooks. |
5 | 141 |
* |
16 | 142 |
* Example usage: |
143 |
* |
|
144 |
* // The filter callback function. |
|
5 | 145 |
* function example_callback( $string, $arg1, $arg2 ) { |
16 | 146 |
* // (maybe) modify $string. |
5 | 147 |
* return $string; |
148 |
* } |
|
149 |
* add_filter( 'example_filter', 'example_callback', 10, 3 ); |
|
0 | 150 |
* |
5 | 151 |
* /* |
16 | 152 |
* * Apply the filters by calling the 'example_callback()' function |
153 |
* * that's hooked onto `example_filter` above. |
|
154 |
* * |
|
155 |
* * - 'example_filter' is the filter hook. |
|
156 |
* * - 'filter me' is the value being filtered. |
|
5 | 157 |
* * - $arg1 and $arg2 are the additional arguments passed to the callback. |
158 |
* $value = apply_filters( 'example_filter', 'filter me', $arg1, $arg2 ); |
|
0 | 159 |
* |
160 |
* @since 0.71 |
|
19 | 161 |
* @since 6.0.0 Formalized the existing and already documented `...$args` parameter |
162 |
* by adding it to the function signature. |
|
0 | 163 |
* |
18 | 164 |
* @global WP_Hook[] $wp_filter Stores all of the filters and actions. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
165 |
* @global int[] $wp_filters Stores the number of times each filter was triggered. |
18 | 166 |
* @global string[] $wp_current_filter Stores the list of current filters with the current one last. |
5 | 167 |
* |
18 | 168 |
* @param string $hook_name The name of the filter hook. |
169 |
* @param mixed $value The value to filter. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
170 |
* @param mixed ...$args Optional. Additional parameters to pass to the callback functions. |
0 | 171 |
* @return mixed The filtered value after all hooked functions are applied to it. |
172 |
*/ |
|
19 | 173 |
function apply_filters( $hook_name, $value, ...$args ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
174 |
global $wp_filter, $wp_filters, $wp_current_filter; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
175 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
176 |
if ( ! isset( $wp_filters[ $hook_name ] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
177 |
$wp_filters[ $hook_name ] = 1; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
178 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
179 |
++$wp_filters[ $hook_name ]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
180 |
} |
0 | 181 |
|
5 | 182 |
// Do 'all' actions first. |
9 | 183 |
if ( isset( $wp_filter['all'] ) ) { |
18 | 184 |
$wp_current_filter[] = $hook_name; |
19 | 185 |
|
186 |
$all_args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection |
|
187 |
_wp_call_all_hook( $all_args ); |
|
0 | 188 |
} |
189 |
||
18 | 190 |
if ( ! isset( $wp_filter[ $hook_name ] ) ) { |
9 | 191 |
if ( isset( $wp_filter['all'] ) ) { |
192 |
array_pop( $wp_current_filter ); |
|
193 |
} |
|
18 | 194 |
|
0 | 195 |
return $value; |
196 |
} |
|
197 |
||
9 | 198 |
if ( ! isset( $wp_filter['all'] ) ) { |
18 | 199 |
$wp_current_filter[] = $hook_name; |
9 | 200 |
} |
0 | 201 |
|
19 | 202 |
// Pass the value to WP_Hook. |
203 |
array_unshift( $args, $value ); |
|
0 | 204 |
|
18 | 205 |
$filtered = $wp_filter[ $hook_name ]->apply_filters( $value, $args ); |
0 | 206 |
|
207 |
array_pop( $wp_current_filter ); |
|
208 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
209 |
return $filtered; |
0 | 210 |
} |
211 |
||
212 |
/** |
|
16 | 213 |
* Calls the callback functions that have been added to a filter hook, specifying arguments in an array. |
0 | 214 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
215 |
* @since 3.0.0 |
5 | 216 |
* |
0 | 217 |
* @see apply_filters() This function is identical, but the arguments passed to the |
18 | 218 |
* functions hooked to `$hook_name` are supplied using an array. |
0 | 219 |
* |
18 | 220 |
* @global WP_Hook[] $wp_filter Stores all of the filters and actions. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
221 |
* @global int[] $wp_filters Stores the number of times each filter was triggered. |
18 | 222 |
* @global string[] $wp_current_filter Stores the list of current filters with the current one last. |
0 | 223 |
* |
18 | 224 |
* @param string $hook_name The name of the filter hook. |
225 |
* @param array $args The arguments supplied to the functions hooked to `$hook_name`. |
|
0 | 226 |
* @return mixed The filtered value after all hooked functions are applied to it. |
227 |
*/ |
|
18 | 228 |
function apply_filters_ref_array( $hook_name, $args ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
229 |
global $wp_filter, $wp_filters, $wp_current_filter; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
230 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
231 |
if ( ! isset( $wp_filters[ $hook_name ] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
232 |
$wp_filters[ $hook_name ] = 1; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
233 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
234 |
++$wp_filters[ $hook_name ]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
235 |
} |
0 | 236 |
|
16 | 237 |
// Do 'all' actions first. |
9 | 238 |
if ( isset( $wp_filter['all'] ) ) { |
18 | 239 |
$wp_current_filter[] = $hook_name; |
16 | 240 |
$all_args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection |
9 | 241 |
_wp_call_all_hook( $all_args ); |
0 | 242 |
} |
243 |
||
18 | 244 |
if ( ! isset( $wp_filter[ $hook_name ] ) ) { |
9 | 245 |
if ( isset( $wp_filter['all'] ) ) { |
246 |
array_pop( $wp_current_filter ); |
|
247 |
} |
|
18 | 248 |
|
0 | 249 |
return $args[0]; |
250 |
} |
|
251 |
||
9 | 252 |
if ( ! isset( $wp_filter['all'] ) ) { |
18 | 253 |
$wp_current_filter[] = $hook_name; |
9 | 254 |
} |
0 | 255 |
|
18 | 256 |
$filtered = $wp_filter[ $hook_name ]->apply_filters( $args[0], $args ); |
0 | 257 |
|
258 |
array_pop( $wp_current_filter ); |
|
259 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
260 |
return $filtered; |
0 | 261 |
} |
262 |
||
263 |
/** |
|
18 | 264 |
* Checks if any filter has been registered for a hook. |
265 |
* |
|
266 |
* When using the `$callback` argument, this function may return a non-boolean value |
|
267 |
* that evaluates to false (e.g. 0), so use the `===` operator for testing the return value. |
|
268 |
* |
|
269 |
* @since 2.5.0 |
|
270 |
* |
|
271 |
* @global WP_Hook[] $wp_filter Stores all of the filters and actions. |
|
0 | 272 |
* |
19 | 273 |
* @param string $hook_name The name of the filter hook. |
274 |
* @param callable|string|array|false $callback Optional. The callback to check for. |
|
275 |
* This function can be called unconditionally to speculatively check |
|
276 |
* a callback that may or may not exist. Default false. |
|
18 | 277 |
* @return bool|int If `$callback` is omitted, returns boolean for whether the hook has |
278 |
* anything registered. When checking a specific function, the priority |
|
279 |
* of that hook is returned, or false if the function is not attached. |
|
280 |
*/ |
|
281 |
function has_filter( $hook_name, $callback = false ) { |
|
282 |
global $wp_filter; |
|
283 |
||
284 |
if ( ! isset( $wp_filter[ $hook_name ] ) ) { |
|
285 |
return false; |
|
286 |
} |
|
287 |
||
288 |
return $wp_filter[ $hook_name ]->has_filter( $hook_name, $callback ); |
|
289 |
} |
|
290 |
||
291 |
/** |
|
292 |
* Removes a callback function from a filter hook. |
|
293 |
* |
|
294 |
* This can be used to remove default functions attached to a specific filter |
|
0 | 295 |
* hook and possibly replace them with a substitute. |
296 |
* |
|
18 | 297 |
* To remove a hook, the `$callback` and `$priority` arguments must match |
0 | 298 |
* when the hook was added. This goes for both filters and actions. No warning |
299 |
* will be given on removal failure. |
|
300 |
* |
|
5 | 301 |
* @since 1.2.0 |
0 | 302 |
* |
18 | 303 |
* @global WP_Hook[] $wp_filter Stores all of the filters and actions. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
304 |
* |
19 | 305 |
* @param string $hook_name The filter hook to which the function to be removed is hooked. |
306 |
* @param callable|string|array $callback The callback to be removed from running when the filter is applied. |
|
307 |
* This function can be called unconditionally to speculatively remove |
|
308 |
* a callback that may or may not exist. |
|
309 |
* @param int $priority Optional. The exact priority used when adding the original |
|
310 |
* filter callback. Default 10. |
|
18 | 311 |
* @return bool Whether the function existed before it was removed. |
0 | 312 |
*/ |
18 | 313 |
function remove_filter( $hook_name, $callback, $priority = 10 ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
314 |
global $wp_filter; |
0 | 315 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
$r = false; |
18 | 317 |
|
318 |
if ( isset( $wp_filter[ $hook_name ] ) ) { |
|
319 |
$r = $wp_filter[ $hook_name ]->remove_filter( $hook_name, $callback, $priority ); |
|
320 |
||
321 |
if ( ! $wp_filter[ $hook_name ]->callbacks ) { |
|
322 |
unset( $wp_filter[ $hook_name ] ); |
|
5 | 323 |
} |
0 | 324 |
} |
325 |
||
326 |
return $r; |
|
327 |
} |
|
328 |
||
329 |
/** |
|
18 | 330 |
* Removes all of the callback functions from a filter hook. |
0 | 331 |
* |
5 | 332 |
* @since 2.7.0 |
0 | 333 |
* |
18 | 334 |
* @global WP_Hook[] $wp_filter Stores all of the filters and actions. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
335 |
* |
18 | 336 |
* @param string $hook_name The filter to remove callbacks from. |
337 |
* @param int|false $priority Optional. The priority number to remove them from. |
|
338 |
* Default false. |
|
339 |
* @return true Always returns true. |
|
0 | 340 |
*/ |
18 | 341 |
function remove_all_filters( $hook_name, $priority = false ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
342 |
global $wp_filter; |
0 | 343 |
|
18 | 344 |
if ( isset( $wp_filter[ $hook_name ] ) ) { |
345 |
$wp_filter[ $hook_name ]->remove_all_filters( $priority ); |
|
346 |
||
347 |
if ( ! $wp_filter[ $hook_name ]->has_filters() ) { |
|
348 |
unset( $wp_filter[ $hook_name ] ); |
|
5 | 349 |
} |
0 | 350 |
} |
351 |
||
352 |
return true; |
|
353 |
} |
|
354 |
||
355 |
/** |
|
18 | 356 |
* Retrieves the name of the current filter hook. |
0 | 357 |
* |
5 | 358 |
* @since 2.5.0 |
0 | 359 |
* |
18 | 360 |
* @global string[] $wp_current_filter Stores the list of current filters with the current one last |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
361 |
* |
18 | 362 |
* @return string Hook name of the current filter. |
0 | 363 |
*/ |
364 |
function current_filter() { |
|
365 |
global $wp_current_filter; |
|
18 | 366 |
|
0 | 367 |
return end( $wp_current_filter ); |
368 |
} |
|
369 |
||
370 |
/** |
|
18 | 371 |
* Returns whether or not a filter hook is currently being processed. |
5 | 372 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
373 |
* The function current_filter() only returns the most recent filter being executed. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
374 |
* did_filter() returns the number of times a filter has been applied during |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
375 |
* the current request. |
5 | 376 |
* |
18 | 377 |
* This function allows detection for any filter currently being executed |
378 |
* (regardless of whether it's the most recent filter to fire, in the case of |
|
5 | 379 |
* hooks called from hook callbacks) to be verified. |
380 |
* |
|
381 |
* @since 3.9.0 |
|
382 |
* |
|
383 |
* @see current_filter() |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
384 |
* @see did_filter() |
18 | 385 |
* @global string[] $wp_current_filter Current filter. |
5 | 386 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
387 |
* @param string|null $hook_name Optional. Filter hook to check. Defaults to null, |
18 | 388 |
* which checks if any filter is currently being run. |
5 | 389 |
* @return bool Whether the filter is currently in the stack. |
390 |
*/ |
|
18 | 391 |
function doing_filter( $hook_name = null ) { |
5 | 392 |
global $wp_current_filter; |
393 |
||
18 | 394 |
if ( null === $hook_name ) { |
5 | 395 |
return ! empty( $wp_current_filter ); |
396 |
} |
|
397 |
||
18 | 398 |
return in_array( $hook_name, $wp_current_filter, true ); |
5 | 399 |
} |
400 |
||
401 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
402 |
* Retrieves the number of times a filter has been applied during the current request. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
403 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
404 |
* @since 6.1.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
405 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
406 |
* @global int[] $wp_filters Stores the number of times each filter was triggered. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
407 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
408 |
* @param string $hook_name The name of the filter hook. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
409 |
* @return int The number of times the filter hook has been applied. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
410 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
411 |
function did_filter( $hook_name ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
412 |
global $wp_filters; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
413 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
414 |
if ( ! isset( $wp_filters[ $hook_name ] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
415 |
return 0; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
416 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
417 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
418 |
return $wp_filters[ $hook_name ]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
419 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
420 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
421 |
/** |
18 | 422 |
* Adds a callback function to an action hook. |
0 | 423 |
* |
424 |
* Actions are the hooks that the WordPress core launches at specific points |
|
425 |
* during execution, or when specific events occur. Plugins can specify that |
|
426 |
* one or more of its PHP functions are executed at these points, using the |
|
427 |
* Action API. |
|
428 |
* |
|
5 | 429 |
* @since 1.2.0 |
0 | 430 |
* |
18 | 431 |
* @param string $hook_name The name of the action to add the callback to. |
432 |
* @param callable $callback The callback to be run when the action is called. |
|
5 | 433 |
* @param int $priority Optional. Used to specify the order in which the functions |
18 | 434 |
* associated with a particular action are executed. |
5 | 435 |
* Lower numbers correspond with earlier execution, |
436 |
* and functions with the same priority are executed |
|
18 | 437 |
* in the order in which they were added to the action. Default 10. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
438 |
* @param int $accepted_args Optional. The number of arguments the function accepts. Default 1. |
18 | 439 |
* @return true Always returns true. |
0 | 440 |
*/ |
18 | 441 |
function add_action( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) { |
442 |
return add_filter( $hook_name, $callback, $priority, $accepted_args ); |
|
0 | 443 |
} |
444 |
||
445 |
/** |
|
18 | 446 |
* Calls the callback functions that have been added to an action hook. |
0 | 447 |
* |
18 | 448 |
* This function invokes all functions attached to action hook `$hook_name`. |
449 |
* It is possible to create new action hooks by simply calling this function, |
|
450 |
* specifying the name of the new hook using the `$hook_name` parameter. |
|
0 | 451 |
* |
16 | 452 |
* You can pass extra arguments to the hooks, much like you can with `apply_filters()`. |
453 |
* |
|
454 |
* Example usage: |
|
455 |
* |
|
456 |
* // The action callback function. |
|
457 |
* function example_callback( $arg1, $arg2 ) { |
|
458 |
* // (maybe) do something with the args. |
|
459 |
* } |
|
460 |
* add_action( 'example_action', 'example_callback', 10, 2 ); |
|
461 |
* |
|
462 |
* /* |
|
463 |
* * Trigger the actions by calling the 'example_callback()' function |
|
464 |
* * that's hooked onto `example_action` above. |
|
465 |
* * |
|
466 |
* * - 'example_action' is the action hook. |
|
467 |
* * - $arg1 and $arg2 are the additional arguments passed to the callback. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
468 |
* do_action( 'example_action', $arg1, $arg2 ); |
0 | 469 |
* |
5 | 470 |
* @since 1.2.0 |
16 | 471 |
* @since 5.3.0 Formalized the existing and already documented `...$arg` parameter |
472 |
* by adding it to the function signature. |
|
0 | 473 |
* |
18 | 474 |
* @global WP_Hook[] $wp_filter Stores all of the filters and actions. |
475 |
* @global int[] $wp_actions Stores the number of times each action was triggered. |
|
476 |
* @global string[] $wp_current_filter Stores the list of current filters with the current one last. |
|
16 | 477 |
* |
18 | 478 |
* @param string $hook_name 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. |
|
0 | 481 |
*/ |
18 | 482 |
function do_action( $hook_name, ...$arg ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
483 |
global $wp_filter, $wp_actions, $wp_current_filter; |
0 | 484 |
|
18 | 485 |
if ( ! isset( $wp_actions[ $hook_name ] ) ) { |
486 |
$wp_actions[ $hook_name ] = 1; |
|
9 | 487 |
} else { |
18 | 488 |
++$wp_actions[ $hook_name ]; |
9 | 489 |
} |
0 | 490 |
|
16 | 491 |
// Do 'all' actions first. |
9 | 492 |
if ( isset( $wp_filter['all'] ) ) { |
18 | 493 |
$wp_current_filter[] = $hook_name; |
16 | 494 |
$all_args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection |
9 | 495 |
_wp_call_all_hook( $all_args ); |
0 | 496 |
} |
497 |
||
18 | 498 |
if ( ! isset( $wp_filter[ $hook_name ] ) ) { |
9 | 499 |
if ( isset( $wp_filter['all'] ) ) { |
500 |
array_pop( $wp_current_filter ); |
|
501 |
} |
|
18 | 502 |
|
0 | 503 |
return; |
504 |
} |
|
505 |
||
9 | 506 |
if ( ! isset( $wp_filter['all'] ) ) { |
18 | 507 |
$wp_current_filter[] = $hook_name; |
9 | 508 |
} |
0 | 509 |
|
16 | 510 |
if ( empty( $arg ) ) { |
511 |
$arg[] = ''; |
|
512 |
} elseif ( is_array( $arg[0] ) && 1 === count( $arg[0] ) && isset( $arg[0][0] ) && is_object( $arg[0][0] ) ) { |
|
513 |
// Backward compatibility for PHP4-style passing of `array( &$this )` as action `$arg`. |
|
514 |
$arg[0] = $arg[0][0]; |
|
9 | 515 |
} |
0 | 516 |
|
18 | 517 |
$wp_filter[ $hook_name ]->do_action( $arg ); |
0 | 518 |
|
9 | 519 |
array_pop( $wp_current_filter ); |
0 | 520 |
} |
521 |
||
522 |
/** |
|
16 | 523 |
* Calls the callback functions that have been added to an action hook, specifying arguments in an array. |
0 | 524 |
* |
5 | 525 |
* @since 2.1.0 |
0 | 526 |
* |
5 | 527 |
* @see do_action() This function is identical, but the arguments passed to the |
18 | 528 |
* functions hooked to `$hook_name` are supplied using an array. |
0 | 529 |
* |
18 | 530 |
* @global WP_Hook[] $wp_filter Stores all of the filters and actions. |
531 |
* @global int[] $wp_actions Stores the number of times each action was triggered. |
|
532 |
* @global string[] $wp_current_filter Stores the list of current filters with the current one last. |
|
533 |
* |
|
534 |
* @param string $hook_name The name of the action to be executed. |
|
535 |
* @param array $args The arguments supplied to the functions hooked to `$hook_name`. |
|
0 | 536 |
*/ |
18 | 537 |
function do_action_ref_array( $hook_name, $args ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
538 |
global $wp_filter, $wp_actions, $wp_current_filter; |
0 | 539 |
|
18 | 540 |
if ( ! isset( $wp_actions[ $hook_name ] ) ) { |
541 |
$wp_actions[ $hook_name ] = 1; |
|
9 | 542 |
} else { |
18 | 543 |
++$wp_actions[ $hook_name ]; |
9 | 544 |
} |
0 | 545 |
|
16 | 546 |
// Do 'all' actions first. |
9 | 547 |
if ( isset( $wp_filter['all'] ) ) { |
18 | 548 |
$wp_current_filter[] = $hook_name; |
16 | 549 |
$all_args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection |
9 | 550 |
_wp_call_all_hook( $all_args ); |
0 | 551 |
} |
552 |
||
18 | 553 |
if ( ! isset( $wp_filter[ $hook_name ] ) ) { |
9 | 554 |
if ( isset( $wp_filter['all'] ) ) { |
555 |
array_pop( $wp_current_filter ); |
|
556 |
} |
|
18 | 557 |
|
0 | 558 |
return; |
559 |
} |
|
560 |
||
9 | 561 |
if ( ! isset( $wp_filter['all'] ) ) { |
18 | 562 |
$wp_current_filter[] = $hook_name; |
9 | 563 |
} |
0 | 564 |
|
18 | 565 |
$wp_filter[ $hook_name ]->do_action( $args ); |
0 | 566 |
|
9 | 567 |
array_pop( $wp_current_filter ); |
0 | 568 |
} |
569 |
||
570 |
/** |
|
18 | 571 |
* Checks if any action has been registered for a hook. |
572 |
* |
|
573 |
* When using the `$callback` argument, this function may return a non-boolean value |
|
574 |
* that evaluates to false (e.g. 0), so use the `===` operator for testing the return value. |
|
0 | 575 |
* |
5 | 576 |
* @since 2.5.0 |
577 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
578 |
* @see has_filter() This function is an alias of has_filter(). |
0 | 579 |
* |
19 | 580 |
* @param string $hook_name The name of the action hook. |
581 |
* @param callable|string|array|false $callback Optional. The callback to check for. |
|
582 |
* This function can be called unconditionally to speculatively check |
|
583 |
* a callback that may or may not exist. Default false. |
|
18 | 584 |
* @return bool|int If `$callback` is omitted, returns boolean for whether the hook has |
585 |
* anything registered. When checking a specific function, the priority |
|
586 |
* of that hook is returned, or false if the function is not attached. |
|
0 | 587 |
*/ |
18 | 588 |
function has_action( $hook_name, $callback = false ) { |
589 |
return has_filter( $hook_name, $callback ); |
|
590 |
} |
|
591 |
||
592 |
/** |
|
593 |
* Removes a callback function from an action hook. |
|
594 |
* |
|
595 |
* This can be used to remove default functions attached to a specific action |
|
596 |
* hook and possibly replace them with a substitute. |
|
597 |
* |
|
598 |
* To remove a hook, the `$callback` and `$priority` arguments must match |
|
599 |
* when the hook was added. This goes for both filters and actions. No warning |
|
600 |
* will be given on removal failure. |
|
601 |
* |
|
602 |
* @since 1.2.0 |
|
603 |
* |
|
19 | 604 |
* @param string $hook_name The action hook to which the function to be removed is hooked. |
605 |
* @param callable|string|array $callback The name of the function which should be removed. |
|
606 |
* This function can be called unconditionally to speculatively remove |
|
607 |
* a callback that may or may not exist. |
|
608 |
* @param int $priority Optional. The exact priority used when adding the original |
|
609 |
* action callback. Default 10. |
|
18 | 610 |
* @return bool Whether the function is removed. |
611 |
*/ |
|
612 |
function remove_action( $hook_name, $callback, $priority = 10 ) { |
|
613 |
return remove_filter( $hook_name, $callback, $priority ); |
|
0 | 614 |
} |
615 |
||
616 |
/** |
|
18 | 617 |
* Removes all of the callback functions from an action hook. |
0 | 618 |
* |
18 | 619 |
* @since 2.7.0 |
0 | 620 |
* |
18 | 621 |
* @param string $hook_name The action to remove callbacks from. |
622 |
* @param int|false $priority Optional. The priority number to remove them from. |
|
623 |
* Default false. |
|
624 |
* @return true Always returns true. |
|
0 | 625 |
*/ |
18 | 626 |
function remove_all_actions( $hook_name, $priority = false ) { |
627 |
return remove_all_filters( $hook_name, $priority ); |
|
628 |
} |
|
629 |
||
630 |
/** |
|
631 |
* Retrieves the name of the current action hook. |
|
632 |
* |
|
633 |
* @since 3.9.0 |
|
634 |
* |
|
635 |
* @return string Hook name of the current action. |
|
636 |
*/ |
|
637 |
function current_action() { |
|
638 |
return current_filter(); |
|
0 | 639 |
} |
640 |
||
641 |
/** |
|
18 | 642 |
* Returns whether or not an action hook is currently being processed. |
643 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
644 |
* The function current_action() only returns the most recent action being executed. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
645 |
* did_action() returns the number of times an action has been fired during |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
646 |
* the current request. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
647 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
648 |
* This function allows detection for any action currently being executed |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
649 |
* (regardless of whether it's the most recent action to fire, in the case of |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
650 |
* hooks called from hook callbacks) to be verified. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
651 |
* |
18 | 652 |
* @since 3.9.0 |
0 | 653 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
654 |
* @see current_action() |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
655 |
* @see did_action() |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
656 |
* |
18 | 657 |
* @param string|null $hook_name Optional. Action hook to check. Defaults to null, |
658 |
* which checks if any action is currently being run. |
|
659 |
* @return bool Whether the action is currently in the stack. |
|
660 |
*/ |
|
661 |
function doing_action( $hook_name = null ) { |
|
662 |
return doing_filter( $hook_name ); |
|
663 |
} |
|
664 |
||
665 |
/** |
|
666 |
* Retrieves the number of times an action has been fired during the current request. |
|
0 | 667 |
* |
18 | 668 |
* @since 2.1.0 |
669 |
* |
|
670 |
* @global int[] $wp_actions Stores the number of times each action was triggered. |
|
671 |
* |
|
672 |
* @param string $hook_name The name of the action hook. |
|
673 |
* @return int The number of times the action hook has been fired. |
|
0 | 674 |
*/ |
18 | 675 |
function did_action( $hook_name ) { |
676 |
global $wp_actions; |
|
677 |
||
678 |
if ( ! isset( $wp_actions[ $hook_name ] ) ) { |
|
679 |
return 0; |
|
680 |
} |
|
681 |
||
682 |
return $wp_actions[ $hook_name ]; |
|
0 | 683 |
} |
684 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
685 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
686 |
* Fires functions attached to a deprecated filter hook. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
687 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
688 |
* When a filter hook is deprecated, the apply_filters() call is replaced with |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
689 |
* apply_filters_deprecated(), which triggers a deprecation notice and then fires |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
* the original filter hook. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
691 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
692 |
* Note: the value and extra arguments passed to the original apply_filters() call |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
693 |
* must be passed here to `$args` as an array. For example: |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
694 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
695 |
* // Old filter. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
696 |
* return apply_filters( 'wpdocs_filter', $value, $extra_arg ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
697 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
698 |
* // Deprecated. |
16 | 699 |
* return apply_filters_deprecated( 'wpdocs_filter', array( $value, $extra_arg ), '4.9.0', 'wpdocs_new_filter' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
700 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
701 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
702 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
703 |
* @see _deprecated_hook() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
704 |
* |
18 | 705 |
* @param string $hook_name The name of the filter hook. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
706 |
* @param array $args Array of additional function arguments to be passed to apply_filters(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
707 |
* @param string $version The version of WordPress that deprecated the hook. |
16 | 708 |
* @param string $replacement Optional. The hook that should have been used. Default empty. |
709 |
* @param string $message Optional. A message regarding the change. Default empty. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
710 |
* @return mixed The filtered value after all hooked functions are applied to it. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
711 |
*/ |
18 | 712 |
function apply_filters_deprecated( $hook_name, $args, $version, $replacement = '', $message = '' ) { |
713 |
if ( ! has_filter( $hook_name ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
714 |
return $args[0]; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
715 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
716 |
|
18 | 717 |
_deprecated_hook( $hook_name, $version, $replacement, $message ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
718 |
|
18 | 719 |
return apply_filters_ref_array( $hook_name, $args ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
720 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
721 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
722 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
723 |
* Fires functions attached to a deprecated action hook. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
724 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
725 |
* When an action hook is deprecated, the do_action() call is replaced with |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
726 |
* do_action_deprecated(), which triggers a deprecation notice and then fires |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
727 |
* the original hook. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
728 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
729 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
730 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
731 |
* @see _deprecated_hook() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
732 |
* |
18 | 733 |
* @param string $hook_name The name of the action hook. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
734 |
* @param array $args Array of additional function arguments to be passed to do_action(). |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
735 |
* @param string $version The version of WordPress that deprecated the hook. |
16 | 736 |
* @param string $replacement Optional. The hook that should have been used. Default empty. |
737 |
* @param string $message Optional. A message regarding the change. Default empty. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
738 |
*/ |
18 | 739 |
function do_action_deprecated( $hook_name, $args, $version, $replacement = '', $message = '' ) { |
740 |
if ( ! has_action( $hook_name ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
741 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
742 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
743 |
|
18 | 744 |
_deprecated_hook( $hook_name, $version, $replacement, $message ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
745 |
|
18 | 746 |
do_action_ref_array( $hook_name, $args ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
747 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
748 |
|
0 | 749 |
// |
750 |
// Functions for handling plugins. |
|
751 |
// |
|
752 |
||
753 |
/** |
|
754 |
* Gets the basename of a plugin. |
|
755 |
* |
|
756 |
* This method extracts the name of a plugin from its filename. |
|
757 |
* |
|
5 | 758 |
* @since 1.5.0 |
0 | 759 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
760 |
* @global array $wp_plugin_paths |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
761 |
* |
0 | 762 |
* @param string $file The filename of plugin. |
763 |
* @return string The name of a plugin. |
|
764 |
*/ |
|
5 | 765 |
function plugin_basename( $file ) { |
766 |
global $wp_plugin_paths; |
|
767 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
768 |
// $wp_plugin_paths contains normalized paths. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
769 |
$file = wp_normalize_path( $file ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
770 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
771 |
arsort( $wp_plugin_paths ); |
18 | 772 |
|
5 | 773 |
foreach ( $wp_plugin_paths as $dir => $realdir ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
774 |
if ( str_starts_with( $file, $realdir ) ) { |
5 | 775 |
$file = $dir . substr( $file, strlen( $realdir ) ); |
776 |
} |
|
777 |
} |
|
778 |
||
9 | 779 |
$plugin_dir = wp_normalize_path( WP_PLUGIN_DIR ); |
5 | 780 |
$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR ); |
781 |
||
16 | 782 |
// Get relative path from plugins directory. |
783 |
$file = preg_replace( '#^' . preg_quote( $plugin_dir, '#' ) . '/|^' . preg_quote( $mu_plugin_dir, '#' ) . '/#', '', $file ); |
|
9 | 784 |
$file = trim( $file, '/' ); |
0 | 785 |
return $file; |
786 |
} |
|
787 |
||
788 |
/** |
|
5 | 789 |
* Register a plugin's real path. |
790 |
* |
|
791 |
* This is used in plugin_basename() to resolve symlinked paths. |
|
792 |
* |
|
793 |
* @since 3.9.0 |
|
794 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
795 |
* @see wp_normalize_path() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
796 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
797 |
* @global array $wp_plugin_paths |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
798 |
* |
5 | 799 |
* @param string $file Known path to the file. |
800 |
* @return bool Whether the path was able to be registered. |
|
801 |
*/ |
|
802 |
function wp_register_plugin_realpath( $file ) { |
|
803 |
global $wp_plugin_paths; |
|
804 |
||
16 | 805 |
// Normalize, but store as static to avoid recalculation of a constant value. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
806 |
static $wp_plugin_path = null, $wpmu_plugin_path = null; |
18 | 807 |
|
5 | 808 |
if ( ! isset( $wp_plugin_path ) ) { |
9 | 809 |
$wp_plugin_path = wp_normalize_path( WP_PLUGIN_DIR ); |
5 | 810 |
$wpmu_plugin_path = wp_normalize_path( WPMU_PLUGIN_DIR ); |
811 |
} |
|
812 |
||
9 | 813 |
$plugin_path = wp_normalize_path( dirname( $file ) ); |
5 | 814 |
$plugin_realpath = wp_normalize_path( dirname( realpath( $file ) ) ); |
815 |
||
816 |
if ( $plugin_path === $wp_plugin_path || $plugin_path === $wpmu_plugin_path ) { |
|
817 |
return false; |
|
818 |
} |
|
819 |
||
820 |
if ( $plugin_path !== $plugin_realpath ) { |
|
821 |
$wp_plugin_paths[ $plugin_path ] = $plugin_realpath; |
|
822 |
} |
|
823 |
||
824 |
return true; |
|
825 |
} |
|
826 |
||
827 |
/** |
|
828 |
* Get the filesystem directory path (with trailing slash) for the plugin __FILE__ passed in. |
|
829 |
* |
|
830 |
* @since 2.8.0 |
|
831 |
* |
|
832 |
* @param string $file The filename of the plugin (__FILE__). |
|
833 |
* @return string the filesystem path of the directory that contains the plugin. |
|
0 | 834 |
*/ |
835 |
function plugin_dir_path( $file ) { |
|
836 |
return trailingslashit( dirname( $file ) ); |
|
837 |
} |
|
838 |
||
839 |
/** |
|
5 | 840 |
* Get the URL directory path (with trailing slash) for the plugin __FILE__ passed in. |
0 | 841 |
* |
5 | 842 |
* @since 2.8.0 |
843 |
* |
|
844 |
* @param string $file The filename of the plugin (__FILE__). |
|
845 |
* @return string the URL path of the directory that contains the plugin. |
|
0 | 846 |
*/ |
847 |
function plugin_dir_url( $file ) { |
|
848 |
return trailingslashit( plugins_url( '', $file ) ); |
|
849 |
} |
|
850 |
||
851 |
/** |
|
852 |
* Set the activation hook for a plugin. |
|
853 |
* |
|
854 |
* When a plugin is activated, the action 'activate_PLUGINNAME' hook is |
|
855 |
* called. In the name of this hook, PLUGINNAME is replaced with the name |
|
856 |
* of the plugin, including the optional subdirectory. For example, when the |
|
857 |
* plugin is located in wp-content/plugins/sampleplugin/sample.php, then |
|
858 |
* the name of this hook will become 'activate_sampleplugin/sample.php'. |
|
859 |
* |
|
860 |
* When the plugin consists of only one file and is (as by default) located at |
|
861 |
* wp-content/plugins/sample.php the name of this hook will be |
|
862 |
* 'activate_sample.php'. |
|
863 |
* |
|
5 | 864 |
* @since 2.0.0 |
0 | 865 |
* |
5 | 866 |
* @param string $file The filename of the plugin including the path. |
18 | 867 |
* @param callable $callback The function hooked to the 'activate_PLUGIN' action. |
0 | 868 |
*/ |
18 | 869 |
function register_activation_hook( $file, $callback ) { |
9 | 870 |
$file = plugin_basename( $file ); |
18 | 871 |
add_action( 'activate_' . $file, $callback ); |
0 | 872 |
} |
873 |
||
874 |
/** |
|
18 | 875 |
* Sets the deactivation hook for a plugin. |
0 | 876 |
* |
877 |
* When a plugin is deactivated, the action 'deactivate_PLUGINNAME' hook is |
|
878 |
* called. In the name of this hook, PLUGINNAME is replaced with the name |
|
879 |
* of the plugin, including the optional subdirectory. For example, when the |
|
880 |
* plugin is located in wp-content/plugins/sampleplugin/sample.php, then |
|
881 |
* the name of this hook will become 'deactivate_sampleplugin/sample.php'. |
|
882 |
* |
|
883 |
* When the plugin consists of only one file and is (as by default) located at |
|
884 |
* wp-content/plugins/sample.php the name of this hook will be |
|
885 |
* 'deactivate_sample.php'. |
|
886 |
* |
|
5 | 887 |
* @since 2.0.0 |
0 | 888 |
* |
5 | 889 |
* @param string $file The filename of the plugin including the path. |
18 | 890 |
* @param callable $callback The function hooked to the 'deactivate_PLUGIN' action. |
0 | 891 |
*/ |
18 | 892 |
function register_deactivation_hook( $file, $callback ) { |
9 | 893 |
$file = plugin_basename( $file ); |
18 | 894 |
add_action( 'deactivate_' . $file, $callback ); |
0 | 895 |
} |
896 |
||
897 |
/** |
|
18 | 898 |
* Sets the uninstallation hook for a plugin. |
0 | 899 |
* |
900 |
* Registers the uninstall hook that will be called when the user clicks on the |
|
901 |
* uninstall link that calls for the plugin to uninstall itself. The link won't |
|
902 |
* be active unless the plugin hooks into the action. |
|
903 |
* |
|
904 |
* The plugin should not run arbitrary code outside of functions, when |
|
905 |
* registering the uninstall hook. In order to run using the hook, the plugin |
|
906 |
* will have to be included, which means that any code laying outside of a |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
907 |
* function will be run during the uninstallation process. The plugin should not |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
908 |
* hinder the uninstallation process. |
0 | 909 |
* |
910 |
* If the plugin can not be written without running code within the plugin, then |
|
911 |
* the plugin should create a file named 'uninstall.php' in the base plugin |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
912 |
* folder. This file will be called, if it exists, during the uninstallation process |
0 | 913 |
* bypassing the uninstall hook. The plugin, when using the 'uninstall.php' |
914 |
* should always check for the 'WP_UNINSTALL_PLUGIN' constant, before |
|
915 |
* executing. |
|
916 |
* |
|
5 | 917 |
* @since 2.7.0 |
0 | 918 |
* |
5 | 919 |
* @param string $file Plugin file. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
920 |
* @param callable $callback The callback to run when the hook is called. Must be |
5 | 921 |
* a static method or function. |
0 | 922 |
*/ |
923 |
function register_uninstall_hook( $file, $callback ) { |
|
924 |
if ( is_array( $callback ) && is_object( $callback[0] ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
925 |
_doing_it_wrong( __FUNCTION__, __( 'Only a static class method or function can be used in an uninstall hook.' ), '3.1.0' ); |
0 | 926 |
return; |
927 |
} |
|
928 |
||
5 | 929 |
/* |
930 |
* The option should not be autoloaded, because it is not needed in most |
|
931 |
* cases. Emphasis should be put on using the 'uninstall.php' way of |
|
932 |
* uninstalling the plugin. |
|
933 |
*/ |
|
16 | 934 |
$uninstallable_plugins = (array) get_option( 'uninstall_plugins' ); |
935 |
$plugin_basename = plugin_basename( $file ); |
|
18 | 936 |
|
16 | 937 |
if ( ! isset( $uninstallable_plugins[ $plugin_basename ] ) || $uninstallable_plugins[ $plugin_basename ] !== $callback ) { |
938 |
$uninstallable_plugins[ $plugin_basename ] = $callback; |
|
939 |
update_option( 'uninstall_plugins', $uninstallable_plugins ); |
|
940 |
} |
|
0 | 941 |
} |
942 |
||
943 |
/** |
|
18 | 944 |
* Calls the 'all' hook, which will process the functions hooked into it. |
0 | 945 |
* |
946 |
* The 'all' hook passes all of the arguments or parameters that were used for |
|
947 |
* the hook, which this function was called for. |
|
948 |
* |
|
949 |
* This function is used internally for apply_filters(), do_action(), and |
|
950 |
* do_action_ref_array() and is not meant to be used from outside those |
|
951 |
* functions. This function does not check for the existence of the all hook, so |
|
952 |
* it will fail unless the all hook exists prior to this function call. |
|
953 |
* |
|
5 | 954 |
* @since 2.5.0 |
0 | 955 |
* @access private |
956 |
* |
|
18 | 957 |
* @global WP_Hook[] $wp_filter Stores all of the filters and actions. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
958 |
* |
0 | 959 |
* @param array $args The collected parameters from the hook that was called. |
960 |
*/ |
|
9 | 961 |
function _wp_call_all_hook( $args ) { |
0 | 962 |
global $wp_filter; |
963 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
964 |
$wp_filter['all']->do_all_hook( $args ); |
0 | 965 |
} |
966 |
||
967 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
968 |
* Builds a unique string ID for a hook callback function. |
0 | 969 |
* |
970 |
* Functions and static method callbacks are just returned as strings and |
|
971 |
* shouldn't have any speed penalty. |
|
972 |
* |
|
5 | 973 |
* @link https://core.trac.wordpress.org/ticket/3875 |
974 |
* |
|
975 |
* @since 2.2.3 |
|
16 | 976 |
* @since 5.3.0 Removed workarounds for spl_object_hash(). |
18 | 977 |
* `$hook_name` and `$priority` are no longer used, |
16 | 978 |
* and the function always returns a string. |
19 | 979 |
* |
0 | 980 |
* @access private |
5 | 981 |
* |
19 | 982 |
* @param string $hook_name Unused. The name of the filter to build ID for. |
983 |
* @param callable|string|array $callback The callback to generate ID for. The callback may |
|
984 |
* or may not exist. |
|
985 |
* @param int $priority Unused. The order in which the functions |
|
986 |
* associated with a particular action are executed. |
|
16 | 987 |
* @return string Unique function ID for usage as array key. |
0 | 988 |
*/ |
18 | 989 |
function _wp_filter_build_unique_id( $hook_name, $callback, $priority ) { |
990 |
if ( is_string( $callback ) ) { |
|
991 |
return $callback; |
|
9 | 992 |
} |
0 | 993 |
|
18 | 994 |
if ( is_object( $callback ) ) { |
16 | 995 |
// Closures are currently implemented as objects. |
18 | 996 |
$callback = array( $callback, '' ); |
0 | 997 |
} else { |
18 | 998 |
$callback = (array) $callback; |
0 | 999 |
} |
1000 |
||
18 | 1001 |
if ( is_object( $callback[0] ) ) { |
16 | 1002 |
// Object class calling. |
18 | 1003 |
return spl_object_hash( $callback[0] ) . $callback[1]; |
1004 |
} elseif ( is_string( $callback[0] ) ) { |
|
16 | 1005 |
// Static calling. |
18 | 1006 |
return $callback[0] . '::' . $callback[1]; |
0 | 1007 |
} |
1008 |
} |