diff --git a/src/wp-includes/class-wp-hook.php b/src/wp-includes/class-wp-hook.php index 38895c87f1349..d619c9d0c677d 100644 --- a/src/wp-includes/class-wp-hook.php +++ b/src/wp-includes/class-wp-hook.php @@ -201,6 +201,7 @@ private function resort_active_iterations( $new_priority = false, $priority_exis * 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. + * @phpstan-param callable|string|array{ 0: string|object, 1: string, ... } $callback */ public function remove_filter( $hook_name, $callback, $priority ) { if ( null === $priority ) { @@ -248,13 +249,14 @@ public function remove_filter( $hook_name, $callback, $priority ) { * of that hook is returned, or false if the function is not attached. * If `$callback` and `$priority` are both provided, a boolean is returned * for whether the specific function is registered at that priority. + * @phpstan-param callable|string|array{ 0: string|object, 1: string, ... }|false $callback */ public function has_filter( $hook_name = '', $callback = false, $priority = false ) { if ( false === $callback ) { return $this->has_filters(); } - $function_key = _wp_filter_build_unique_id( $hook_name, $callback, false ); + $function_key = _wp_filter_build_unique_id( $hook_name, $callback, is_int( $priority ) ? $priority : 10 ); if ( ! $function_key ) { return false; @@ -320,9 +322,9 @@ public function remove_all_filters( $priority = false ) { * * @since 4.7.0 * - * @param mixed $value The value to filter. - * @param array $args Additional parameters to pass to the callback functions. - * This array is expected to include $value at index 0. + * @param mixed $value The value to filter. + * @param list $args Additional parameters to pass to the callback functions. + * This array is expected to include $value at index 0. * @return mixed The filtered value after all hooked functions are applied to it. */ public function apply_filters( $value, $args ) { @@ -337,9 +339,14 @@ public function apply_filters( $value, $args ) { $num_args = count( $args ); do { - $this->current_priority[ $nesting_level ] = current( $this->iterations[ $nesting_level ] ); + $priority = current( $this->iterations[ $nesting_level ] ); + + if ( false === $priority ) { + // This is not expected to occur since the hook is known to have callbacks at one or more priorities. + break; + } - $priority = $this->current_priority[ $nesting_level ]; + $this->current_priority[ $nesting_level ] = $priority; foreach ( $this->callbacks[ $priority ] as $the_ ) { if ( ! $this->doing_action ) { @@ -370,7 +377,7 @@ public function apply_filters( $value, $args ) { * * @since 4.7.0 * - * @param array $args Parameters to pass to the callback functions. + * @param list $args Parameters to pass to the callback functions. */ public function do_action( $args ) { $this->doing_action = true; @@ -387,7 +394,7 @@ public function do_action( $args ) { * * @since 4.7.0 * - * @param array $args Arguments to pass to the hook callbacks. Passed by reference. + * @param list $args Arguments to pass to the hook callbacks. Passed by reference. */ public function do_all_hook( &$args ) { $nesting_level = $this->nesting_level++; diff --git a/src/wp-includes/plugin.php b/src/wp-includes/plugin.php index 55459c0dd96c8..f76fec3ad9e0c 100644 --- a/src/wp-includes/plugin.php +++ b/src/wp-includes/plugin.php @@ -169,6 +169,7 @@ function add_filter( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) * @param string $hook_name The name of the filter hook. * @param mixed $value The value to filter. * @param mixed ...$args Optional. Additional parameters to pass to the callback functions. + * @no-named-arguments * @return mixed The filtered value after all hooked functions are applied to it. */ function apply_filters( $hook_name, $value, ...$args ) { @@ -222,8 +223,8 @@ function apply_filters( $hook_name, $value, ...$args ) { * @global int[] $wp_filters Stores the number of times each filter was triggered. * @global string[] $wp_current_filter Stores the list of current filters with the current one last. * - * @param string $hook_name The name of the filter hook. - * @param array $args The arguments supplied to the functions hooked to `$hook_name`. + * @param string $hook_name The name of the filter hook. + * @param list $args The arguments supplied to the functions hooked to `$hook_name`. * @return mixed The filtered value after all hooked functions are applied to it. */ function apply_filters_ref_array( $hook_name, $args ) { @@ -484,6 +485,7 @@ function add_action( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) * @param string $hook_name The name of the action to be executed. * @param mixed ...$arg Optional. Additional arguments which are passed on to the * functions hooked to the action. Default empty. + * @no-named-arguments */ function do_action( $hook_name, ...$arg ) { global $wp_filter, $wp_actions, $wp_current_filter; @@ -537,8 +539,8 @@ function do_action( $hook_name, ...$arg ) { * @global int[] $wp_actions Stores the number of times each action was triggered. * @global string[] $wp_current_filter Stores the list of current filters with the current one last. * - * @param string $hook_name The name of the action to be executed. - * @param array $args The arguments supplied to the functions hooked to `$hook_name`. + * @param string $hook_name The name of the action to be executed. + * @param list $args The arguments supplied to the functions hooked to `$hook_name`. */ function do_action_ref_array( $hook_name, $args ) { global $wp_filter, $wp_actions, $wp_current_filter; @@ -713,11 +715,11 @@ function did_action( $hook_name ) { * * @see _deprecated_hook() * - * @param string $hook_name The name of the filter hook. - * @param array $args Array of additional function arguments to be passed to apply_filters(). - * @param string $version The version of WordPress that deprecated the hook. - * @param string $replacement Optional. The hook that should have been used. Default empty. - * @param string $message Optional. A message regarding the change. Default empty. + * @param string $hook_name The name of the filter hook. + * @param list $args Array of additional function arguments to be passed to apply_filters(). + * @param string $version The version of WordPress that deprecated the hook. + * @param string $replacement Optional. The hook that should have been used. Default empty. + * @param string $message Optional. A message regarding the change. Default empty. * @return mixed The filtered value after all hooked functions are applied to it. */ function apply_filters_deprecated( $hook_name, $args, $version, $replacement = '', $message = '' ) { @@ -741,11 +743,11 @@ function apply_filters_deprecated( $hook_name, $args, $version, $replacement = ' * * @see _deprecated_hook() * - * @param string $hook_name The name of the action hook. - * @param array $args Array of additional function arguments to be passed to do_action(). - * @param string $version The version of WordPress that deprecated the hook. - * @param string $replacement Optional. The hook that should have been used. Default empty. - * @param string $message Optional. A message regarding the change. Default empty. + * @param string $hook_name The name of the action hook. + * @param list $args Array of additional function arguments to be passed to do_action(). + * @param string $version The version of WordPress that deprecated the hook. + * @param string $replacement Optional. The hook that should have been used. Default empty. + * @param string $message Optional. A message regarding the change. Default empty. */ function do_action_deprecated( $hook_name, $args, $version, $replacement = '', $message = '' ) { if ( ! has_action( $hook_name ) ) { @@ -967,7 +969,7 @@ function register_uninstall_hook( $file, $callback ) { * * @global WP_Hook[] $wp_filter Stores all of the filters and actions. * - * @param array $args The collected parameters from the hook that was called. + * @param list $args The collected parameters from the hook that was called. */ function _wp_call_all_hook( $args ) { global $wp_filter; @@ -992,12 +994,13 @@ function _wp_call_all_hook( $args ) { * * @access private * - * @param string $hook_name Unused. The name of the filter to build ID for. - * @param callable $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. + * @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|null Unique function ID for usage as array key, or null if it couldn't be determined. + * @phpstan-param callable|string|array{ 0: string|object, 1: string, ... } $callback */ function _wp_filter_build_unique_id( $hook_name, $callback, $priority ): ?string { if ( is_string( $callback ) ) {