Skip to content

Commit fe79588

Browse files
committed
Docs: Improve and correct documentation for hook-related variadic functions.
See #37402 git-svn-id: https://develop.svn.wordpress.org/trunk@45420 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 51ab0b5 commit fe79588

2 files changed

Lines changed: 38 additions & 19 deletions

File tree

src/wp-includes/class-wp-hook.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,12 @@ public function remove_all_filters( $priority = false ) {
253253
}
254254

255255
/**
256-
* Calls the callback functions added to a filter hook.
256+
* Calls the callback functions that have been added to a filter hook.
257257
*
258258
* @since 4.7.0
259259
*
260260
* @param mixed $value The value to filter.
261-
* @param array $args Arguments to pass to callbacks.
261+
* @param array $args Additional parameters to pass to the callback functions.
262262
* @return mixed The filtered value after all hooked functions are applied to it.
263263
*/
264264
public function apply_filters( $value, $args ) {
@@ -299,11 +299,11 @@ public function apply_filters( $value, $args ) {
299299
}
300300

301301
/**
302-
* Executes the callback functions hooked on a specific action hook.
302+
* Calls the callback functions that have been added to an action hook.
303303
*
304304
* @since 4.7.0
305305
*
306-
* @param mixed $args Arguments to pass to the hook callbacks.
306+
* @param array $args Parameters to pass to the callback functions.
307307
*/
308308
public function do_action( $args ) {
309309
$this->doing_action = true;

src/wp-includes/plugin.php

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,26 +141,29 @@ function has_filter( $tag, $function_to_check = false ) {
141141
}
142142

143143
/**
144-
* Call the functions added to a filter hook.
144+
* Calls the callback functions that have been added to a filter hook.
145145
*
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
147147
* this function. This function can be used to create a new filter hook by
148148
* simply calling this function with the name of the new hook specified using
149-
* the $tag parameter.
149+
* the `$tag` parameter.
150150
*
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.
152152
*
153-
* // Our filter callback function
153+
* Example usage:
154+
*
155+
* // The filter callback function
154156
* function example_callback( $string, $arg1, $arg2 ) {
155157
* // (maybe) modify $string
156158
* return $string;
157159
* }
158160
* add_filter( 'example_filter', 'example_callback', 10, 3 );
159161
*
160162
* /*
161-
* * Apply the filters by calling the 'example_callback' function we
162-
* * "hooked" to 'example_filter' using the add_filter() function above.
163-
* * - 'example_filter' is the filter hook $tag
163+
* * Apply the filters by calling the 'example_callback()' function that's
164+
* * hooked onto `example_filter` above.
165+
* *
166+
* * - 'example_filter' is the filter hook
164167
* * - 'filter me' is the value being filtered
165168
* * - $arg1 and $arg2 are the additional arguments passed to the callback.
166169
* $value = apply_filters( 'example_filter', 'filter me', $arg1, $arg2 );
@@ -170,9 +173,9 @@ function has_filter( $tag, $function_to_check = false ) {
170173
* @global array $wp_filter Stores all of the filters.
171174
* @global array $wp_current_filter Stores the list of current filters with the current one last.
172175
*
173-
* @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.
175-
* @param mixed ...$var Additional variables passed to the functions hooked to `$tag`.
176+
* @param string $tag The name of the filter hook.
177+
* @param mixed $value The value to filter.
178+
* @param mixed ...$args Additional parameters to pass to the callback functions.
176179
* @return mixed The filtered value after all hooked functions are applied to it.
177180
*/
178181
function apply_filters( $tag, $value ) {
@@ -213,7 +216,7 @@ function apply_filters( $tag, $value ) {
213216
}
214217

215218
/**
216-
* Execute functions hooked on a specific filter hook, specifying arguments in an array.
219+
* Calls the callback functions that have been added to a filter hook, specifying arguments in an array.
217220
*
218221
* @since 3.0.0
219222
*
@@ -413,7 +416,23 @@ function add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1
413416
* possible to create new action hooks by simply calling this function,
414417
* specifying the name of the new hook using the `$tag` parameter.
415418
*
416-
* You can pass extra arguments to the hooks, much like you can with apply_filters().
419+
* You can pass extra arguments to the hooks, much like you can with `apply_filters()`.
420+
*
421+
* Example usage:
422+
*
423+
* // The action callback function
424+
* function example_callback( $arg1, $arg2 ) {
425+
* // (maybe) do something with the args
426+
* }
427+
* add_action( 'example_action', 'example_callback', 10, 2 );
428+
*
429+
* /*
430+
* * Trigger the actions by calling the 'example_callback()' function that's
431+
* * hooked onto `example_action` above.
432+
* *
433+
* * - 'example_action' is the action hook
434+
* * - $arg1 and $arg2 are the additional arguments passed to the callback.
435+
* $value = apply_actions( 'example_action', $arg1, $arg2 );
417436
*
418437
* @since 1.2.0
419438
*
@@ -488,12 +507,12 @@ function did_action( $tag ) {
488507
}
489508

490509
/**
491-
* Execute functions hooked on a specific action hook, specifying arguments in an array.
510+
* Calls the callback functions that have been added to an action hook, specifying arguments in an array.
492511
*
493512
* @since 2.1.0
494513
*
495514
* @see do_action() This function is identical, but the arguments passed to the
496-
* functions hooked to $tag< are supplied using an array.
515+
* functions hooked to `$tag` are supplied using an array.
497516
* @global array $wp_filter Stores all of the filters
498517
* @global array $wp_actions Increments the amount of times action was triggered.
499518
* @global array $wp_current_filter Stores the list of current filters with the current one last

0 commit comments

Comments
 (0)