Why not set the wp-login.php TEST_COOKIE earlier?
-
I’ve been having a problem with the login test cookie. Users have to log in twice because their first attempt yields this message: “Cookies are blocked or not supported by your browser. You must enable cookies to use WordPress.” Yet I can see in the dev console the TEST_COOKIE is set upon initially visiting wp-login.php. After the first login attempt, the login cookie is also set. Because of this, users are even able to bypass the verification math problem that appears during the second login attempt. Simply moving the setcookie directive higher in the wp-login.php page (right at the top in this case) resolves this issue completely.
`//Set a cookie now to see if they are supported by the browser.
$secure = ( ‘https’ === parse_url( wp_login_url(), PHP_URL_SCHEME ) );
setcookie( TEST_COOKIE, ‘WP Cookie check’, 0, COOKIEPATH, COOKIE_DOMAIN, $secure );
if ( SITECOOKIEPATH != COOKIEPATH )
setcookie( TEST_COOKIE, ‘WP Cookie check’, 0, SITECOOKIEPATH, COOKIE_DOMAIN, $secure );I see numerous complaints over several years about this issue on these forums and elsewhere with numerous recommendations for “fixes” (many of which involved forcing the TEST_COOKIE to be set earlier via functions.php hacks), none of which worked for me. Is there a reason the setcookie directive exists where it does? Is there any reason it cannot be set earlier in core?
The topic ‘Why not set the wp-login.php TEST_COOKIE earlier?’ is closed to new replies.