Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Right now for my plugin, I am using in_admin() to determine if the user is in the frontend of the site or in the admin area. However, the problem occurs when plugins use admin_ajax.php to process ajax requests.

I need a way to register hooks and plugins only when processing admin_ajax.php or in the frontend of the site. What is the best way to go about doing that?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Check the constant DOING_AJAX. Its definition is the first working code in wp-admin/admin-ajax.php.

Example:

if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
{
    // do something
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.