terungwa Posted January 25, 2017 Share Posted January 25, 2017 I have used this tutorial here (https://codex.wordpress.org/Integrating_WordPress_with_Your_Website) as a guide to set up non-wordpress pages to access some wordpress resources on non-wordpress pages. Eg I can view wordpress posts on non-wordpress page. I have wordpress installed in a sub-folder( ./root - PHP pages ./root/wordpres - Wordpress installation} In addition, I need to be able to detect if a user is logged into wordpress on the non-wordpress page. I am using this code below on non-wordpress pages for that: if(is_user_logged_in()){ $current_user = wp_get_current_user(); /** * @example Safe usage: $current_user = wp_get_current_user(); * if ( !($current_user instanceof WP_User) ) * return; */ echo 'Username: ' . $current_user->user_login . '<br />'; echo 'User email: ' . $current_user->user_email . '<br />'; echo 'User first name: ' . $current_user->user_firstname . '<br />'; echo 'User last name: ' . $current_user->user_lastname . '<br />'; echo 'User display name: ' . $current_user->display_name . '<br />'; echo 'User ID: ' . $current_user->ID . '<br />'; echo get_avatar( $current_user->user_email, 32 ). '<br />'; echo '<hr />'; } else{ echo 'Not logged-in'; } Even though I am logged into wordpress, when I navigate to the non-wordpress page, I see wordpress posts listed but, the is_user_logged_in() function returns false and prints 'Not logged-in'!!! Is there a way of achieving this besides the approach I have adopted? I need guidance to resolve this. Quote Link to comment https://forums.phpfreaks.com/topic/303024-how-to-check-if-user-is-logged-into-wordpress-on-non-wordpress-pages/ Share on other sites More sharing options...
Jacques1 Posted January 27, 2017 Share Posted January 27, 2017 You have to make sure that the WordPress session cookie is also valid for your main application. Open the developer tools of your browser. What does the path attribute of the cookie say? 1 Quote Link to comment https://forums.phpfreaks.com/topic/303024-how-to-check-if-user-is-logged-into-wordpress-on-non-wordpress-pages/#findComment-1542037 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.