Do not redirect while DOING_AJAX #121
Comments
This shouldn't happen. The redirect is disabled when |
I apologize for the thin report. I've updated the issue above. I was very glad to find the filter there, which allowed me to fashion a quick workaround, so thank you very much for having thought of that potential. |
Now that I pause a moment.. I can see that you would likely need to do both tests, since you wouldn't want to redirect users within of the admin area in any case. I'm sure that was apparent to you, but I thought I'd mention that it did just now occur to me. |
Oh, they are circumventing the regular API by using some custom AJAX response. Dirty, but yes, we can fix that. The regular admin area will never be redirected. |
Yes, I assume they have their reasons, though I can't say what they are. It's an automatic project, so I'll grudgingly give them the benefit of the doubt. Very good. That certainly continues to be desirable. |
Hi Damian, I just pushed a commit to a separate issue branch. Testing welcome. :) |
@tfrommen I cannot think of any case where an AJAX request should be redirected. Better wait until someone provides a use case before you widen the API. |
@toscho so you would just leave out the filter/variable, right? |
Yes. The API should cover known use cases only. That makes it easier to change the code later. |
Thanks for the quick action! I'll test out the feature banch later today. |
Tested and working! |
Hi Damian, thanks for testing/confirming. The branch has been merged into Closed with 1c2731e. |
I found it necessary in one circumstance to hook
mlp_redirect_url
and prevent redirects during an XHR.Specifically this occurs with plugins that do not use
wp-admin/admin-ajax.php
to provide data to the front end. The case here was the use of the Infinite Scroll plugin, part of Jetpack.You can see the code I am referring to here:
https://github.com/Automattic/jetpack/blob/3.5.3/modules/infinite-scroll/infinity.php#L596-L614
In any case, I believe the definitive determination of whether or not we are in an ajax call should be when
DOING_AJAX
istrue
, notis_admin()
. It's possible to handle XHR outside ofwp-admin/admin-ajax.php
, and at the very least DOING_AJAX should be set if you care for other code to be able cope with it.The text was updated successfully, but these errors were encountered: