Had a situation today where I was using admin-ajax.php from a front end script. As I understand it this the wp way to make ajax calls (registering my function with the wp_ajax_nopriv_myfunction hook)

Seems to me that since admin-ajax.php is on the admin side is_admin() returns true whereas my script calls it from the front end side.

This causes an issue with a plugin I use that does things differently on front and admin side of things.

So I was wondering if I was doing something wrong

is there a way to use ajax in front end the wp way and have is_admin() to return false ?

hope I could make myself understand

5 s
5

WordPress sets is_admin() to true for all ajax requests (front-end or admin-side). (See codex).

There’s isn’t away of over-riding this (and you shouldn’t anyway). If your ajax request can be fired from both front-end and admin side, then you may want to include whether it ‘is admin’ or not when you post the data. But without any details on the ‘issues’ it causes with your plug-in, it’s hard to offer a work-aroudn.

Leave a Reply

Your email address will not be published. Required fields are marked *