Plugins: Add missing $priority parameter to has_filter() and has_action().
This brings `has_filter()`/`has_action()` in parity with `add_filter()`/`add_action()` and `remove_filter()`/`remove_action()`, all of which support a `$priority` parameter. Props westonruter, swissspidy. Fixes #64186. See #64178. Built from https://develop.svn.wordpress.org/trunk@61118 git-svn-id: http://core.svn.wordpress.org/trunk@60454 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -223,16 +223,21 @@ final class WP_Hook implements Iterator, ArrayAccess {
|
||||
* that evaluates to false (e.g. 0), so use the `===` operator for testing the return value.
|
||||
*
|
||||
* @since 4.7.0
|
||||
* @since 6.9.0 Added the `$priority` parameter.
|
||||
*
|
||||
* @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.
|
||||
* @param int|false $priority Optional. The specific priority at which to check for the callback.
|
||||
* 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.
|
||||
* If `$callback` and `$priority` are both provided, a boolean is returned
|
||||
* for whether the specific function is registered at that priority.
|
||||
*/
|
||||
public function has_filter( $hook_name = '', $callback = false ) {
|
||||
public function has_filter( $hook_name = '', $callback = false, $priority = false ) {
|
||||
if ( false === $callback ) {
|
||||
return $this->has_filters();
|
||||
}
|
||||
@@ -243,9 +248,13 @@ final class WP_Hook implements Iterator, ArrayAccess {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ( $this->callbacks as $priority => $callbacks ) {
|
||||
if ( is_int( $priority ) ) {
|
||||
return isset( $this->callbacks[ $priority ][ $function_key ] );
|
||||
}
|
||||
|
||||
foreach ( $this->callbacks as $callback_priority => $callbacks ) {
|
||||
if ( isset( $callbacks[ $function_key ] ) ) {
|
||||
return $priority;
|
||||
return $callback_priority;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -267,6 +267,7 @@ function apply_filters_ref_array( $hook_name, $args ) {
|
||||
* that evaluates to false (e.g. 0), so use the `===` operator for testing the return value.
|
||||
*
|
||||
* @since 2.5.0
|
||||
* @since 6.9.0 Added the `$priority` parameter.
|
||||
*
|
||||
* @global WP_Hook[] $wp_filter Stores all of the filters and actions.
|
||||
*
|
||||
@@ -274,18 +275,22 @@ function apply_filters_ref_array( $hook_name, $args ) {
|
||||
* @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.
|
||||
* @param int|false $priority Optional. The specific priority at which to check for the callback.
|
||||
* 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.
|
||||
* If `$callback` and `$priority` are both provided, a boolean is returned
|
||||
* for whether the specific function is registered at that priority.
|
||||
*/
|
||||
function has_filter( $hook_name, $callback = false ) {
|
||||
function has_filter( $hook_name, $callback = false, $priority = false ) {
|
||||
global $wp_filter;
|
||||
|
||||
if ( ! isset( $wp_filter[ $hook_name ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $wp_filter[ $hook_name ]->has_filter( $hook_name, $callback );
|
||||
return $wp_filter[ $hook_name ]->has_filter( $hook_name, $callback, $priority );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -574,6 +579,7 @@ function do_action_ref_array( $hook_name, $args ) {
|
||||
* that evaluates to false (e.g. 0), so use the `===` operator for testing the return value.
|
||||
*
|
||||
* @since 2.5.0
|
||||
* @since 6.9.0 Added the `$priority` parameter.
|
||||
*
|
||||
* @see has_filter() This function is an alias of has_filter().
|
||||
*
|
||||
@@ -581,12 +587,16 @@ function do_action_ref_array( $hook_name, $args ) {
|
||||
* @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.
|
||||
* @param int|false $priority Optional. The specific priority at which to check for the callback.
|
||||
* 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.
|
||||
* If `$callback` and `$priority` are both provided, a boolean is returned
|
||||
* for whether the specific function is registered at that priority.
|
||||
*/
|
||||
function has_action( $hook_name, $callback = false ) {
|
||||
return has_filter( $hook_name, $callback );
|
||||
function has_action( $hook_name, $callback = false, $priority = false ) {
|
||||
return has_filter( $hook_name, $callback, $priority );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.9-beta2-61117';
|
||||
$wp_version = '6.9-beta2-61118';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
||||
Reference in New Issue
Block a user