is_user_logged_in()
Determines whether the current visitor is a logged in user.
Description #Description
For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.
Return #Return
(bool) True if user is logged in, false if not logged in.
Source #Source
File: wp-includes/pluggable.php
function is_user_logged_in() { $user = wp_get_current_user(); return $user->exists(); }
Expand full source code Collapse full source code View on Trac
Changelog #Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |
Related #Related
Uses #Uses
Uses | Description |
---|---|
wp-includes/pluggable.php: wp_get_current_user() |
Retrieve the current user object. |
Used By #Used By
Used By | Description |
---|---|
wp-includes/class-wp-recovery-mode.php: WP_Recovery_Mode::handle_exit_recovery_mode() |
Handles a request to exit Recovery Mode. |
wp-admin/includes/class-wp-site-health.php: WP_Site_Health::check_wp_version_check_exists() |
Test if |
wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php: WP_REST_Themes_Controller::get_items_permissions_check() |
Checks if a given request has access to read the theme. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::handle_dismiss_autosave_or_lock_request() |
Delete a given auto-draft changeset or the autosave revision for a given changeset or delete changeset lock. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::handle_changeset_trash_request() |
Handle request to trash a changeset. |
wp-includes/general-template.php: wp_enqueue_code_editor() |
Enqueue assets needed by the code editor for the given settings. |
wp-includes/rest-api.php: rest_authorization_required_code() |
Returns a contextual HTTP error code for authorization failure. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::changeset_data() |
Get changeset data. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::create_item_permissions_check() |
Checks if a given request has access to create a comment. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::create_item() |
Creates a comment. |
wp-includes/comment.php: wp_check_comment_flood() |
Checks whether comment flooding is occurring. |
wp-includes/rest-api.php: rest_send_cors_headers() |
Sends Cross-Origin Resource Sharing headers with API requests. |
wp-includes/rest-api.php: rest_cookie_check_errors() |
Checks for errors when using cookie-based authentication. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::customize_pane_settings() |
Print JavaScript settings for parent window. |
wp-includes/rest-api/class-wp-rest-server.php: WP_REST_Server::serve_request() |
Handles serving an API request. |
wp-signup.php: validate_another_blog_signup() |
Validate a new site signup for an existing user. |
wp-signup.php: show_blog_form() |
Generates and displays the Signup and Create Site forms |
wp-signup.php: validate_blog_form() |
Validate the new site signup |
wp-admin/includes/ms.php: _access_denied_splash() |
Displays an access denied message when a user tries to view a site’s dashboard they do not have access to. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::save() |
Handle customize_save WP Ajax request to save/update a changeset. |
wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::setup_theme() |
Start preview and customize theme. |
wp-includes/general-template.php: wp_heartbeat_settings() |
Default settings for heartbeat |
wp-includes/general-template.php: user_can_richedit() |
Whether the user can access the visual editor. |
wp-includes/general-template.php: wp_loginout() |
Display the Log In/Out link. |
wp-includes/general-template.php: wp_register() |
Display the Registration or Admin link. |
wp-includes/class-wp.php: WP::send_headers() |
Sends additional HTTP headers for caching, content type, etc. |
wp-includes/class-wp-query.php: WP_Query::get_posts() |
Retrieves an array of posts based on query variables. |
wp-includes/class-wp-query.php: WP_Query::parse_search() |
Generates SQL for the WHERE clause based on passed search terms. |
wp-includes/functions.php: wp_auth_check() |
Check whether a user is still logged in, for the heartbeat. |
wp-includes/functions.php: wp_auth_check_load() |
Load the auth check for monitoring whether the user is still logged in. |
wp-includes/link-template.php: get_adjacent_post() |
Retrieves the adjacent post. |
wp-includes/class-wp-admin-bar.php: WP_Admin_Bar::_render() | |
wp-includes/class-wp-admin-bar.php: WP_Admin_Bar::initialize() | |
wp-includes/admin-bar.php: wp_admin_bar_site_menu() |
Add the “Site Name” menu. |
wp-includes/admin-bar.php: wp_admin_bar_my_sites_menu() |
Add the “My Sites/[Site Name]” menu and all submenus. |
wp-includes/admin-bar.php: is_admin_bar_showing() |
Determines whether the admin bar should be showing. |
wp-includes/post-template.php: get_body_class() |
Retrieves an array of the class names for the body element. |
wp-includes/post.php: get_posts_by_author_sql() |
Retrieve the post SQL based on capability, author, and type. |
wp-includes/post.php: _count_posts_cache_key() |
Return the cache key for wp_count_posts() based on the passed arguments. |
wp-includes/post.php: wp_count_posts() |
Count number of posts of a post type and if user has permissions to view. |
wp-includes/comment-template.php: get_post_reply_link() |
Retrieve HTML content for reply to post link. |
wp-includes/comment-template.php: wp_list_comments() |
List comments. |
wp-includes/comment-template.php: comment_form() |
Outputs a complete commenting form for use within a template. |
wp-includes/comment-template.php: get_comment_reply_link() |
Retrieve HTML content for reply to comment link. |
wp-includes/class-wp-customize-widgets.php: WP_Customize_Widgets::wp_ajax_update_widget() |
Updates widget settings asynchronously. |
User Contributed Notes #User Contributed Notes
You must log in before being able to contribute a note or feedback.
Example: Display different output depending on whether the user is logged in or not.
Please note that
is_user_logged_in
is a pluggable function and you could get a fatal error if you call it too early.To solve this problem, you can wrap the login check within a function hooked to the init action:
Example: From your functions file, this code displays a personal message for logged in users.
Example: In case somebody want to add login and logout link in the template somewhere.
This function is more accurate if used at, or after, the ‘template_redirect’ Action. Before that, under unusual circumstances, it will give unexpected results.
The most common case is for a Site Address (URL) without a “www.” when an http:// request is received with a “www.” specified.
Background: between the ‘wp’ and ‘template_redirect’ Action, the Rewrite rules are applied for Pretty Permalinks. During this process, $_SERVER[‘SERVER_NAME’] is corrected in the common case listed above by removing “www.”