determining if the user is logged in

The question:

I am new to wordpress, and trying to get my head around the idea of sessions and all. I read in a lot of places that session concept is not used in wordpress. Anyway, I downloaded the my-login-theme plugin. My question is, when a user navigates to some secured area, I want to check if that user is logged in or not. Once I check that, I want to get user details like email, and full name. Is this possible in wordpress?

Thanks

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

Use the is_user_logged_in() conditional tag (Codex ref) to determine if the current user is logged in.

Use the get_userdata() function (Codex ref) to return user data.

Method 2

You can use is_user_logged_in() to see if the user is logged in. You can use get_userdata() to get the logged in users info.

If you want to restrict access to pages, have you looked at using the plugin Members You can enable shortcodes and template tags to control restricted content to Roles.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment