[wp-hackers] Ajax requests, admin-ajax.php and the WP_ADMIN constant
24/7
24-7 at gmx.net
Tue Feb 7 04:02:20 UTC 2012
I'm currently developing an app that needs some ajax requests. Suddenly I
found myself in a weird position: I couldn't make any requests from my ajax
callback function. Everything loaded fine, the request was sent via
jQuery.post() and the response was `0`. As I made the request from inside a
class, I tested if I could hook the callback from outside and it worked.
After a lot of debugging [1] I found the *"error"*: is_admin() returns true
as admin-ajax.php defines WP_ADMIN as true on top of the file. This is a
bit weird behavior, as we got the wp_ajax_* (admin/logged-in) and the
wp_ajax_nopriv_* (public/guest) hook. If I want to, like in my case, built
the front-end stuff completely separated from the back end extensions, then
I have the problem that I simply can't divide stuff. This brings me in a
strange situation for organizing my files: I can't stick stuff together
that belongs together.
Is there some work-around, some ideas, some concepts? Or does the ticket
from Denis-de-Bernard [2] will receive some attention for 3.4?
Thanks!
[1] I found the note about the is_admin() in the Ajax Codex article a
little too late: http://codex.wordpress.org/AJAX_in_Plugins
[2] http://core.trac.wordpress.org/ticket/12400
More information about the wp-hackers
mailing list