Make WordPress Core


Ignore:
Timestamp:
11/03/2025 11:45:40 PM (2 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/tests/phpunit/tests/hooks/hasFilter.php

    r53804 r61118  
    99class Tests_Hooks_HasFilter extends WP_UnitTestCase {
    1010
     11    /**
     12     * @ticket 64186
     13     */
    1114    public function test_has_filter_with_function() {
    1215        $callback      = '__return_null';
    1316        $hook          = new WP_Hook();
    1417        $hook_name     = __FUNCTION__;
    15         $priority      = 1;
     18        $priority_a    = 1;
     19        $priority_b    = 10;
    1620        $accepted_args = 2;
    1721
    18         $hook->add_filter( $hook_name, $callback, $priority, $accepted_args );
     22        $hook->add_filter( $hook_name, $callback, $priority_a, $accepted_args );
     23        $hook->add_filter( $hook_name, $callback, $priority_b, $accepted_args );
    1924
    20         $this->assertSame( $priority, $hook->has_filter( $hook_name, $callback ) );
     25        $this->assertSame( $priority_a, $hook->has_filter( $hook_name, $callback ) );
     26        $this->assertTrue( $hook->has_filter( $hook_name, $callback, $priority_a ) );
     27        $this->assertTrue( $hook->has_filter( $hook_name, $callback, $priority_b ) );
     28        $hook->remove_filter( $hook_name, $callback, $priority_a );
     29        $this->assertSame( $priority_b, $hook->has_filter( $hook_name, $callback ) );
    2130    }
    2231
Note: See TracChangeset for help on using the changeset viewer.