[wp-trac] [WordPress Trac] #25669: Introduce helper function for AJAX checks

WordPress Trac noreply at wordpress.org
Mon Dec 23 18:04:18 UTC 2013


#25669: Introduce helper function for AJAX checks
-------------------------+------------------------------
 Reporter:  toscho       |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  General      |     Version:
 Severity:  normal       |  Resolution:
 Keywords:               |
-------------------------+------------------------------

Comment (by griffinjt):

 +1 for this in whatever convention works best.

 Ajax requests need to have as little cruft as possible because they are
 meant to be fast. If all you check for is `is_admin()`, which is what the
 majority of plugin/theme developers do, they don't realize that they are
 loading all their admin junk into ajax requests, including potential
 checks to remote servers (tracking, updating, etc.). This is likely the
 reason why `admin-ajax.php` has so many searches for performance issues -
 it can cause a performance nightmare that is tough to track down. For now,
 I use:

 `is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX )`

 otherwise, ajax requests are polluted by everything else I would normally
 only load in the admin. This is especially troubling when running ajax
 requests from the front end to `admin-ajax.php`. It is very confusing.

 I usually wrap the code above in a class method called "is_true_admin" to
 distinguish between admin and ajax states, because while `is_admin()` is
 indicative of the current state, it doesn't necessarily reflect the
 intended use of the state, e.g. for ajax requests. My 2 cents. :-)

--
Ticket URL: <http://core.trac.wordpress.org/ticket/25669#comment:12>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list