AJAX logout problem in WordPress using wp-postviews plugin

Been working on a site and we’ve had a random/frequent problems where the user gets logged out. It mostly got triggered by AJAX calls and once the page was refreshed the user was logged out.
We narrowed it down to be caused by the wp-postviews plug-in and all I did was add the following line at the top of the plug-in’s page (/wp-content/plugins/post-views/post-views.php)

if (defined('DOING_AJAX')) return;

And made sure that the PHP files that are called by AJAX has the following at the top of the page

define('DOING_AJAX', true);

It is worth noting that this is only necessary if you requiring something like the wp-load.php file to load WordPress functionality.

Leave a Reply