From 7819ca4e3e3d2c0b3dbfec0ec83f52c304ef69bd Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 1 Dec 2021 13:20:36 +0000 Subject: [PATCH] Plugins: Correct the documented allowable types for to the `$callback` parameter of various hook related functions. These functions don't require the callback to be a valid callable, therefore `array` and `string` are also valid types for this parameter. Props malthert Fixes #54440 git-svn-id: https://develop.svn.wordpress.org/trunk@52300 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-hook.php | 14 +++++++---- src/wp-includes/plugin.php | 42 +++++++++++++++++++------------ 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/wp-includes/class-wp-hook.php b/src/wp-includes/class-wp-hook.php index cb49271ba4..018db1c967 100644 --- a/src/wp-includes/class-wp-hook.php +++ b/src/wp-includes/class-wp-hook.php @@ -168,9 +168,11 @@ final class WP_Hook implements Iterator, ArrayAccess { * * @since 4.7.0 * - * @param string $hook_name The filter hook to which the function to be removed is hooked. - * @param callable $callback The callback to be removed from running when the filter is applied. - * @param int $priority The exact priority used when adding the original filter callback. + * @param string $hook_name The filter hook to which the function to be removed is hooked. + * @param callable|string|array $callback The callback to be removed from running when the filter is applied. + * This method can be called unconditionally to speculatively remove + * a callback that may or may not exist. + * @param int $priority The exact priority used when adding the original filter callback. * @return bool Whether the callback existed before it was removed. */ public function remove_filter( $hook_name, $callback, $priority ) { @@ -201,8 +203,10 @@ final class WP_Hook implements Iterator, ArrayAccess { * * @since 4.7.0 * - * @param string $hook_name Optional. The name of the filter hook. Default empty. - * @param callable|false $callback Optional. The callback to check for. Default false. + * @param string $hook_name Optional. The name of the filter hook. Default empty. + * @param callable|string|array|false $callback Optional. The callback to check for. + * This method can be called unconditionally to speculatively check + * a callback that may or may not exist. Default false. * @return bool|int If `$callback` is omitted, returns boolean for whether the hook has * anything registered. When checking a specific function, the priority * of that hook is returned, or false if the function is not attached. diff --git a/src/wp-includes/plugin.php b/src/wp-includes/plugin.php index 5f4fa15986..81e0aa952d 100644 --- a/src/wp-includes/plugin.php +++ b/src/wp-includes/plugin.php @@ -247,8 +247,10 @@ function apply_filters_ref_array( $hook_name, $args ) { * * @global WP_Hook[] $wp_filter Stores all of the filters and actions. * - * @param string $hook_name The name of the filter hook. - * @param callable|false $callback Optional. The callback to check for. Default false. + * @param string $hook_name The name of the filter hook. + * @param callable|string|array|false $callback Optional. The callback to check for. + * This function can be called unconditionally to speculatively check + * a callback that may or may not exist. Default false. * @return bool|int If `$callback` is omitted, returns boolean for whether the hook has * anything registered. When checking a specific function, the priority * of that hook is returned, or false if the function is not attached. @@ -277,10 +279,12 @@ function has_filter( $hook_name, $callback = false ) { * * @global WP_Hook[] $wp_filter Stores all of the filters and actions. * - * @param string $hook_name The filter hook to which the function to be removed is hooked. - * @param callable $callback The name of the function which should be removed. - * @param int $priority Optional. The exact priority used when adding the original - * filter callback. Default 10. + * @param string $hook_name The filter hook to which the function to be removed is hooked. + * @param callable|string|array $callback The callback to be removed from running when the filter is applied. + * This function can be called unconditionally to speculatively remove + * a callback that may or may not exist. + * @param int $priority Optional. The exact priority used when adding the original + * filter callback. Default 10. * @return bool Whether the function existed before it was removed. */ function remove_filter( $hook_name, $callback, $priority = 10 ) { @@ -530,8 +534,10 @@ function do_action_ref_array( $hook_name, $args ) { * * @see has_filter() has_action() is an alias of has_filter(). * - * @param string $hook_name The name of the action hook. - * @param callable|false $callback Optional. The callback to check for. Default false. + * @param string $hook_name The name of the action hook. + * @param callable|string|array|false $callback Optional. The callback to check for. + * This function can be called unconditionally to speculatively check + * a callback that may or may not exist. Default false. * @return bool|int If `$callback` is omitted, returns boolean for whether the hook has * anything registered. When checking a specific function, the priority * of that hook is returned, or false if the function is not attached. @@ -552,10 +558,12 @@ function has_action( $hook_name, $callback = false ) { * * @since 1.2.0 * - * @param string $hook_name The action hook to which the function to be removed is hooked. - * @param callable $callback The name of the function which should be removed. - * @param int $priority Optional. The exact priority used when adding the original - * action callback. Default 10. + * @param string $hook_name The action hook to which the function to be removed is hooked. + * @param callable|string|array $callback The name of the function which should be removed. + * This function can be called unconditionally to speculatively remove + * a callback that may or may not exist. + * @param int $priority Optional. The exact priority used when adding the original + * action callback. Default 10. * @return bool Whether the function is removed. */ function remove_action( $hook_name, $callback, $priority = 10 ) { @@ -924,12 +932,14 @@ function _wp_call_all_hook( $args ) { * @since 5.3.0 Removed workarounds for spl_object_hash(). * `$hook_name` and `$priority` are no longer used, * and the function always returns a string. + * * @access private * - * @param string $hook_name Unused. The name of the filter to build ID for. - * @param callable $callback The function to generate ID for. - * @param int $priority Unused. The order in which the functions - * associated with a particular action are executed. + * @param string $hook_name Unused. The name of the filter to build ID for. + * @param callable|string|array $callback The callback to generate ID for. The callback may + * or may not exist. + * @param int $priority Unused. The order in which the functions + * associated with a particular action are executed. * @return string Unique function ID for usage as array key. */ function _wp_filter_build_unique_id( $hook_name, $callback, $priority ) {