Make WordPress Core


Ignore:
Timestamp:
11/03/2025 11:45:40 PM (5 months ago)
Author:
westonruter
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-hook.php

    r60809 r61118  
    224224     *
    225225     * @since 4.7.0
     226     * @since 6.9.0 Added the `$priority` parameter.
    226227     *
    227228     * @param string                      $hook_name Optional. The name of the filter hook. Default empty.
     
    229230     *                                               This method can be called unconditionally to speculatively check
    230231     *                                               a callback that may or may not exist. Default false.
     232     * @param int|false                   $priority  Optional. The specific priority at which to check for the callback.
     233     *                                               Default false.
    231234     * @return bool|int If `$callback` is omitted, returns boolean for whether the hook has
    232235     *                  anything registered. When checking a specific function, the priority
    233236     *                  of that hook is returned, or false if the function is not attached.
    234      */
    235     public function has_filter( $hook_name = '', $callback = false ) {
     237     *                  If `$callback` and `$priority` are both provided, a boolean is returned
     238     *                  for whether the specific function is registered at that priority.
     239     */
     240    public function has_filter( $hook_name = '', $callback = false, $priority = false ) {
    236241        if ( false === $callback ) {
    237242            return $this->has_filters();
     
    244249        }
    245250
    246         foreach ( $this->callbacks as $priority => $callbacks ) {
     251        if ( is_int( $priority ) ) {
     252            return isset( $this->callbacks[ $priority ][ $function_key ] );
     253        }
     254
     255        foreach ( $this->callbacks as $callback_priority => $callbacks ) {
    247256            if ( isset( $callbacks[ $function_key ] ) ) {
    248                 return $priority;
     257                return $callback_priority;
    249258            }
    250259        }
Note: See TracChangeset for help on using the changeset viewer.