[wp-hackers] DOING_AJAX all the time
steve at sltaylor.co.uk
Tue Jan 31 23:30:17 UTC 2012
Duh - thanks!
I always used to think that was a dodgy behaviour for constants (to
return true when not defined). Then I forgot about it and they bit me
On 30 January 2012 18:20, Dion Hulse (dd32) <wordpress at dd32.id.au> wrote:
> Enable PHP Warnings/Notices and you'll get an error along the lines of
> "Constant DOING_AJAX undefined, Assuming 'DOING_AJAX'" (a string).
> so what your code is really saying is... If the string "DOING_AJAX" is
> not empty, echo yes.
> This is because the DOING_AJAX define is only defined when it's true,
> so you should be doing:
> if ( defined('DOING_AJAX') && DOING_AJAX )
> As a easier way to catch this, always use something such as var_dump()
> and inspect the type of the variable printed is what you expect (ie. a
> boolean, and not a string of DOING_AJAX).
> On 30 January 2012 15:09, Tom Barrett <tcbarrett at gmail.com> wrote:
>> What happens if you do this:
>> <?php echo 'DOING_AJAX: ' . ( (defined('DOING_AJAX') && DOING_AJAX) ? 'yes'
>> : 'no' ); exit; ?>
>> On 30 January 2012 14:57, Steve Taylor <steve at sltaylor.co.uk> wrote:
>>> I have a site in development that seems to think it's DOING_AJAX all
>>> the time. There are AJAX aspects to the front-end, but even non-AJAX
>>> requests seem to have this flag set.
>>> So, if I put this line in header.php, functions.php, a plugin:
>>> <?php echo 'DOING_AJAX: ' . ( DOING_AJAX ? 'yes' : 'no' ); exit; ?>
>>> Even if I just make a plain request to a page in the browser, I get:
>>> DOING_AJAX: yes
>>> I'm rushed so I'm heading for a workaround for now - just wondered if
>>> anyone had any ideas?
>>> Needless to say I've double-checked for the constant being defined,
>>> and it's only in admin-ajax.php. Any idea how this may be being
>>> included on a normal request?
>>> Steve Taylor
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com
>> http://www.tcbarrett.com | http://gplus.to/tcbarrett |
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers