1

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?

1
  • do you have any login mechanism on your staging env, to hide it from public? are URL path's in database correct? Commented Dec 14, 2018 at 10:25

1 Answer 1

1

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.

2
  • Another reason why Nginx is so much easier to work with... no .htaccess to worry about and server-level caching (no cache plugins/hacks). Also if you want more verbose settings you can use .example.com for COOKIE_DOMAIN here (the default/blank value is doing the same thing). See also: wordpress.stackexchange.com/questions/130753/… Commented Nov 1, 2020 at 10:42
  • Also the DOMAIN_CURRENT_SITE is only for Multisite installations. Commented Jan 11, 2022 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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