[wp-trac] [WordPress Trac] #61710: Introduce a new action hook for ajax requests for both logged-in and non-logged-in users

WordPress Trac noreply at wordpress.org
Sun Jun 15 03:42:25 UTC 2025


#61710: Introduce a new action hook for ajax requests for both logged-in and non-
logged-in users
-----------------------------+------------------------------
 Reporter:  nirajgirixd      |       Owner:  (none)
     Type:  enhancement      |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  General          |     Version:  6.6
 Severity:  normal           |  Resolution:
 Keywords:  has-patch close  |     Focuses:
-----------------------------+------------------------------

Comment (by nirajgirixd):

 Thank you for the review and feedback!

 I get the concern about the `wp_ajax_all_{action}` hook possibly being
 confusing, especially since it doesn’t explicitly mention `nopriv` like
 the existing ones do. However, I’d also like to share why I still believe
 this could be a helpful addition to the core:

 - **Reduced Boilerplate:** Requiring developers to register the same
 callback twice—once for `wp_ajax_{$action}` and once for
 `wp_ajax_nopriv_{$action}` adds unnecessary duplication, especially in
 projects handling many shared AJAX endpoints.

 - **Cleaner Code, Fewer Mistakes:** Combining both into a single
 `wp_ajax_all_{$action}` hook can help reduce errors (e.g., forgetting to
 register both hooks or misnaming one), improving maintainability and
 clarity.

 - **Potential Performance Benefit:** While minor, consolidating the hook
 registration can reduce the number of callbacks processed during AJAX
 initialization. For sites with many AJAX actions, this small improvement
 could contribute to better performance—especially in high-traffic or API-
 heavy environments.

 - **Optional and Backward-Compatible:** This hook is not meant to replace
 the existing ones but to offer a more ergonomic alternative for cases
 where the same callback applies to all users. Developers who prefer
 explicit user-type distinction can continue to use the existing `wp_ajax_`
 and `wp_ajax_nopriv_` hooks as before.

 That said, I completely respect if this doesn't align with the current
 vision for core. However, if there's openness to re-evaluating the naming
 or implementation to make the intention clearer, I’d be more than happy to
 iterate on the PR based on your guidance.

 Thanks again for the thoughtful review and for everything you do in
 maintaining and improving WordPress!

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/61710#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list