I’m creating a website that has a front-end login and dashboard. I have created my login form and several “authentication required” pages. They worked flawlessly.
However, one of my authentication-required pages would constantly log me out. I could go to the page, but once I went to it, if I tried to access another page that required authentication, it would log me out and I’d be forced to log in again.
I have no idea what was causing it; I used the same code that I was using for the other pages. Eventually I deleted the custom template and header files as well as the page in the WP dashboard. I figured I’d start from scratch on that page since I was obviously missing something that my eyes weren’t catching.
As soon as I did that a different page was exhibiting the same behaviour. I started commenting out code to see what could possibly be causing this and I’ve narrowed it down to the wp_head() function that’s called in the header. If I comment it out, I can stay logged in and go about my merry way. If I leave it in, I get logged out every time I visit THAT page.
I know I can’t remove it because it’s one of the most important hooks, but since I have narrowed it down to that function, I did a print_r() on the $wp_actions variable to see if there was any difference and there isn’t. This is the output:
Array ( [muplugins_loaded] => 1 [registered_taxonomy] => 10 [registered_post_type] => 11 [plugins_loaded] => 1 [sanitize_comment_cookies] => 1 [setup_theme] => 1 [load_textdomain] => 2 [after_setup_theme] => 1 [auth_cookie_malformed] => 1 [auth_cookie_valid] => 1 [set_current_user] => 1 [init] => 1 [widgets_init] => 1 [register_sidebar] => 5 [wp_register_sidebar_widget] => 14 [wp_loaded] => 1 [parse_request] => 1 [send_headers] => 1 [parse_query] => 1 [pre_get_posts] => 1 [posts_selection] => 1 [wp] => 1 [template_redirect] => 1 [get_header] => 1 [wp_default_scripts] => 1 )
I have added back the original page and used the same code as before, and it is working as expected. Truly perplexing.
Some more information:
– I’m using the wp_signon() function to do the logging in.
– I’m using the is_user_logged_in() function to check if the user is logged in long before the wp_head() function is called.
– If I view a page that does not require authentications, such as the home page, it works as expected: that is, I’m still logged in. But, as soon as I visit THAT page I get logged out.
Is this a bug, or am I misunderstanding something about WordPress?
Any help would be greatly appreciated. If you need code for anything, just ask.
Thank you for your time.
- The topic ‘wp_head logs me out somewhat randomly’ is closed to new replies.