[wp-trac] [WordPress Trac] #64186: has_filter()/has_action() do not support an expected $priority param

WordPress Trac noreply at wordpress.org
Mon Nov 3 22:11:08 UTC 2025


#64186: has_filter()/has_action() do not support an expected $priority param
--------------------------+-------------------------
 Reporter:  westonruter   |      Owner:  westonruter
     Type:  defect (bug)  |     Status:  assigned
 Priority:  normal        |  Milestone:  6.9
Component:  Plugins       |    Version:  2.5
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-------------------------
 This is split out from #64178 for visibility. Initially explained in
 [https://github.com/WordPress/wordpress-develop/pull/10449 PR].

 The `has_action()` and `has_filter()` functions are lacking an expected
 `$priority` parameter to be able to check whether a given callback is
 added at a specific priority. This is something I've missed in the past.
 It also "feels right" given that
 `add_action()`/`remove_action()`/`add_filter()`/`remove_filter()` all have
 an optional `$priority` parameter. '''See
 [https://github.com/search?q=%2F%28has_action%7Chas_filter%29%5C%28%5Cs*%5B%27%22%5D%5B%5E%27%22%5D%2B%5B%27%22%5D%2C%5Cs*%5B%5E%2C%5C%28%5C%29%5C%5B%5D%2B%2C%5Cs*%5Cd%2B%2F&type=code
 examples on GitHub] and
 [https://wpdirectory.net/search/01K91EC0G9DTA8TRVHZW448FND on WP
 Directory] where ecosystem code assumed there was such a `$priority`
 parameter.''' This is important because the same callback can be added
 multiple times on the same hook with different priorities.

 This is needed for #64178 to be able to move up the priority of
 `wp_oembed_add_discovery_links()` from 10 to 4. For back-compt, it cannot
 be unhooked at priority 10 for the sake of the many plugins that remove
 the action via:

 {{{#!php
 <?php
 remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
 }}}

 See
 [https://github.com/search?q=%2Fremove_action%5C%28%5Cs*%5B%27%22%5Dwp_head%5B%27%22%5D%2C%5Cs*%5B%27%22%5Dwp_oembed_add_discovery_links%5B%27%22%5D%2F&type=code
 GitHub Search] (1.7k files) and
 [https://wpdirectory.net/search/01K919XQYVW66SZ6SEZ470BRFT WPDirectory]
 (145 plugins).

 So the action needs to be hooked twice:

 {{{#!php
 <?php
 add_action( 'wp_head', 'wp_oembed_add_discovery_links', 4 ); // Printed
 after feed_links() and feed_links_extra().
 add_action( 'wp_head', 'wp_oembed_add_discovery_links' ); // Unhooked the
 first time that wp_oembed_add_discovery_links() runs for back-compat.
 }}}

 The `wp_oembed_add_discovery_links()` function can then make use of the
 new `$priority` parameter for `has_action()` to check whether a plugin has
 unhooked the function at the original priority:

 {{{#!php
 <?php
 // For back-compat, short-circuit if a plugin has removed the action at
 the original priority.
 if ( ! has_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 ) ) {
         return;
 }

 // Prevent running again at the original priority.
 remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
 }}}

 This was accounting for back-compat was similarly in r60910 with the
 difference there being a new function was introduced as opposed to reusing
 the same function.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64186>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list