Why is my staging subdomain not sending wordpress_logged_in cookies?

We have a custom login and account creation plugin. It works fine on our live environment (example.com) but not on our staging environment (test.example.com).

When we call wp_insert_user via an AJAX function, it successfully creates the user and returns their ID. wp_signon also appears to work. But in both cases, the user doesn't actually get logged in on the staging environment.

After looking through Chrome's developer tools, I realized that the live environment is sending set-cookie: wordpress_logged_in_... like it's supposed to, but the staging environment is not.

There's nothing in the error log about this, and it happens if we disable all of our other plugins on the staging environment.

What could be the cause of this? How can we make it send the login cookies like it's supposed to?

Topic clone-site cookies staging login plugins Wordpress

Category Web


I noticed that the staging environment had different content in its wp-config.php and .htaccess files. I changed them to be closer to the ones on the live environment.

While I was there, I noticed that some of the differing content was related to various caching plugins that we previously had installed on the staging environment. In desperation, I reinstalled all of those plugins through wp-admin and then uninstalled them.

Surprisingly, that fixed the issue of the cookies not being sent. However, the cookies had incorrect paths or domains. After some trial and error, I finally got it working by adding these seven lines to wp-config.php:

define('ADMIN_COOKIE_PATH', '/wp-admin');
define('COOKIE_DOMAIN', '');
define('COOKIEPATH', '/');
define('SITECOOKIEPATH', '/');
define('DOMAIN_CURRENT_SITE', 'test.example.com');
define('WP_HOME','https://test.example.com');
define('WP_SITEURL','https://test.example.com');

My assumption is that one or more of the caching plugins hadn't cleaned up after itself when we uninstalled it.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.