get_current_user_id() WordPress Function
The get_current_user_id() function is used to retrieve the current user's ID. This function is useful for checking if a user is logged in or not. If the user is not logged in, the function will return 0.
get_current_user_id() #
Gets the current user’s ID.
Return
(int) The current user's ID, or 0 if no user is logged in.
Source
File: wp-includes/user.php
function get_current_user_id() { if ( ! function_exists( 'wp_get_current_user' ) ) { return 0; } $user = wp_get_current_user(); return ( isset( $user->ID ) ? (int) $user->ID : 0 ); }
Expand full source codeCollapse full source codeView on TracView on GitHub
Related
Uses
Uses | Description |
---|---|
wp-includes/pluggable.php:wp_get_current_user() | Retrieve the current user object. |
Used By
Used By | Description |
---|---|
wp-includes/blocks.php:build_comment_query_vars_from_block() | Helper function that constructs a comment query vars array from the passed block properties. |
wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php:WP_REST_Templates_Controller::prepare_item_for_database() | Prepares a single template for create or update. |
wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php:WP_REST_Application_Passwords_Controller::get_current_item_permissions_check() | Checks if a given request has access to get the currently used application password for a user. |
wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php:WP_REST_Autosaves_Controller::create_item() | Creates, updates or deletes an autosave revision. |
wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php:WP_REST_Autosaves_Controller::create_post_autosave() | Creates autosave for the specified post. |
wp-includes/script-loader.php:wp_default_packages_inline_scripts() | Adds inline scripts required for the WordPress JavaScript packages. |
wp-admin/includes/template.php:do_block_editor_incompatible_meta_box() | Renders a “fake” meta box with an information message, shown on the block editor, when an incompatible meta box is found. |
wp-admin/includes/post.php:the_block_editor_meta_boxes() | Renders the meta boxes forms. |
wp-admin/includes/meta-boxes.php:register_and_do_post_meta_boxes() | Registers the default post meta boxes, and runs the |
wp-includes/class-wp-customize-manager.php:WP_Customize_Manager::handle_dismiss_autosave_or_lock_request() | Deletes 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() | Handles request to trash a changeset. |
wp-includes/class-wp-customize-manager.php:WP_Customize_Manager::set_changeset_lock() | Marks the changeset post as being currently edited by the current user. |
wp-includes/class-wp-customize-manager.php:WP_Customize_Manager::refresh_changeset_lock() | Refreshes changeset lock with the current time if current user edited the changeset before. |
wp-includes/class-wp-customize-manager.php:WP_Customize_Manager::get_changeset_posts() | Gets changeset posts. |
wp-includes/script-loader.php:wp_localize_community_events() | Localizes community events data that needs to be passed to dashboard.js. |
wp-includes/widgets/class-wp-widget-text.php:WP_Widget_Text::render_control_template_scripts() | Render form template scripts. |
wp-admin/includes/ajax-actions.php:wp_ajax_get_community_events() | Handles Ajax requests for community events |
wp-includes/class-wp-customize-manager.php:WP_Customize_Manager::_publish_changeset_values() | Publishes the values of a changeset. |
wp-includes/class-wp-customize-manager.php:WP_Customize_Manager::save_changeset_post() | Saves the post for the loaded changeset. |
wp-includes/class-wp-customize-manager.php:WP_Customize_Manager::changeset_data() | Gets changeset data. |
wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php:WP_REST_Users_Controller::delete_current_item() | Deletes the current user. |
wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php:WP_REST_Users_Controller::check_role_update() | Determines if the current user is allowed to make the desired roles change. |
wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php:WP_REST_Users_Controller::update_current_item_permissions_check() | Checks if a given request has access to update the current user. |
wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php:WP_REST_Users_Controller::update_current_item() | Updates the current user. |
wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php:WP_REST_Users_Controller::delete_current_item_permissions_check() | Checks if a given request has access to delete the current user. |
wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php:WP_REST_Users_Controller::get_current_item() | Retrieves the current user. |
wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php:WP_REST_Users_Controller::get_item_permissions_check() | Checks if a given request has access to read a user. |
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:WP_REST_Posts_Controller::prepare_item_for_database() | Prepares a single post for create or update. |
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:WP_REST_Posts_Controller::update_item_permissions_check() | Checks if a given request has access to update a post. |
wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:WP_REST_Posts_Controller::create_item_permissions_check() | Checks if a given request has access to create a post. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php:WP_REST_Comments_Controller::check_edit_permission() | Checks if a comment can be edited or deleted. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php:WP_REST_Comments_Controller::check_read_permission() | Checks if the comment can be read. |
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/comment.php:wp_check_comment_flood() | Checks whether comment flooding is occurring. |
wp-includes/class-wp-customize-manager.php:WP_Customize_Manager::customize_pane_settings() | Prints JavaScript settings for parent window. |
wp-admin/includes/class-wp-screen.php:WP_Screen::render_meta_boxes_preferences() | Render the meta boxes preferences. |
wp-admin/includes/ajax-actions.php:wp_ajax_save_wporg_username() | Ajax handler for saving the user’s WordPress.org username. |
wp-includes/customize/class-wp-customize-nav-menu-item-setting.php:WP_Customize_Nav_Menu_Item_Setting::value_as_wp_post_nav_menu_item() | Get the value emulated into a WP_Post and set up as a nav_menu_item. |
wp-admin/includes/post.php:wp_edit_attachments_query_vars() | Returns the query variables for the current attachments request. |
wp-admin/includes/ajax-actions.php:wp_ajax_destroy_sessions() | Ajax handler for destroying multiple open sessions for a user. |
wp-includes/user.php:wp_destroy_all_sessions() | Removes all session tokens for the current user from the database. |
wp-includes/user.php:wp_get_all_sessions() | Retrieves a list of sessions for the current user. |
wp-includes/user.php:wp_destroy_current_session() | Removes the current session token from the database. |
wp-includes/user.php:wp_destroy_other_sessions() | Removes all but the current session token for the current user for the database. |
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-admin/includes/ms.php:choose_primary_blog() | Handles the display of choosing a user’s primary site. |
wp-includes/user.php:new_user_email_admin_notice() | Adds an admin notice alerting the user to check for confirmation request email after email address change. |
wp-admin/includes/plugin-install.php:install_plugins_favorites_form() | Shows a username form for the favorites page. |
wp-admin/includes/dashboard.php:wp_dashboard_quick_press() | The Quick Draft widget display and creation of drafts. |
wp-admin/includes/dashboard.php:wp_dashboard_recent_drafts() | Show recent drafts of the user on the dashboard. |
wp-admin/includes/user.php:edit_user() | Edit user settings based on contents of $_POST |
wp-admin/includes/class-wp-plugin-install-list-table.php:WP_Plugin_Install_List_Table::prepare_items() | |
wp-admin/includes/class-wp-internal-pointers.php:WP_Internal_Pointers::enqueue_scripts() | Initializes the new feature pointers. |
wp-admin/includes/class-wp-users-list-table.php:WP_Users_List_Table::single_row() | Generate HTML for a single row on the users.php admin panel. |
wp-admin/includes/post.php:wp_check_post_lock() | Determines whether the post is currently being edited by another user. |
wp-admin/includes/post.php:wp_set_post_lock() | Marks the post as currently being edited by the current user. |
wp-admin/includes/post.php:wp_create_post_autosave() | Creates autosave data for the specified post from |
wp-admin/includes/post.php:post_preview() | Saves a draft or manually autosaves for the purpose of showing a post preview. |
wp-admin/includes/post.php:wp_autosave() | Saves a post submitted with XHR. |
wp-admin/includes/post.php:_wp_translate_postdata() | Renames |
wp-admin/includes/post.php:edit_post() | Updates an existing post with values provided in |
wp-admin/includes/post.php:bulk_edit_posts() | Processes the post data for the bulk editing of posts. |
wp-admin/includes/ajax-actions.php:wp_ajax_save_user_color_scheme() | Ajax handler for auto-saving the selected color scheme for a user’s own profile. |
wp-admin/includes/ajax-actions.php:wp_ajax_wp_remove_post_lock() | Ajax handler for removing a post lock. |
wp-admin/includes/ajax-actions.php:wp_ajax_dismiss_wp_pointer() | Ajax handler for dismissing a WordPress pointer. |
wp-admin/includes/ajax-actions.php:wp_ajax_update_welcome_panel() | Ajax handler for updating whether to display the welcome panel. |
wp-admin/includes/ajax-actions.php:wp_ajax_inline_save() | Ajax handler for Quick Edit saving a post from a list table. |
wp-admin/includes/bookmark.php:wp_insert_link() | Inserts a link into the database, or updates an existing link. |
wp-admin/includes/class-wp-media-list-table.php:WP_Media_List_Table::display_rows() | |
wp-admin/includes/class-wp-comments-list-table.php:WP_Comments_List_Table::get_views() | |
wp-admin/includes/class-wp-posts-list-table.php:WP_Posts_List_Table::single_row() | |
wp-admin/includes/class-wp-posts-list-table.php:WP_Posts_List_Table::get_views() | |
wp-admin/includes/class-wp-posts-list-table.php:WP_Posts_List_Table::__construct() | Constructor. |
wp-admin/includes/class-wp-posts-list-table.php:WP_Posts_List_Table::prepare_items() | |
wp-includes/pluggable.php:wp_notify_postauthor() | Notify an author (and/or others) of a comment/trackback/pingback on a post. |
wp-includes/pluggable.php:wp_clear_auth_cookie() | Removes all of the cookies associated with authentication. |
wp-includes/pluggable.php:wp_logout() | Log the current user out. |
wp-includes/deprecated.php:wp_admin_bar_dashboard_view_site_menu() | Add the “Dashboard”/”Visit Site” menu. |
wp-includes/deprecated.php:is_blog_user() | Checks if the current user belong to a given site. |
wp-includes/class-wp-query.php:WP_Query::get_posts() | Retrieves an array of posts based on query variables. |
wp-includes/link-template.php:get_dashboard_url() | Retrieves the URL to the user’s dashboard. |
wp-includes/link-template.php:get_edit_profile_url() | Retrieves the URL to the user’s profile editor. |
wp-includes/link-template.php:get_edit_user_link() | Retrieves the edit user link. |
wp-includes/link-template.php:get_adjacent_post() | Retrieves the adjacent post. |
wp-includes/class-wp-admin-bar.php:WP_Admin_Bar::initialize() | Initializes the admin bar. |
wp-includes/admin-bar.php:wp_admin_bar_wp_menu() | Adds the WordPress logo menu. |
wp-includes/admin-bar.php:wp_admin_bar_my_account_item() | Adds the “My Account” item. |
wp-includes/admin-bar.php:wp_admin_bar_my_account_menu() | Adds the “My Account” submenu items. |
wp-includes/option.php:wp_user_settings() | Saves and restores user interface settings stored in a cookie. |
wp-includes/option.php:get_all_user_settings() | Retrieves all user interface settings. |
wp-includes/option.php:wp_set_all_user_settings() | Private. Sets all user interface settings. |
wp-includes/option.php:delete_all_user_settings() | Deletes the user settings of the current user. |
wp-includes/user.php:clean_user_cache() | Cleans all user caches. |
wp-includes/user.php:is_user_member_of_blog() | Finds out whether a user is a member of a given blog. |
wp-includes/user.php:setup_userdata() | Sets up global user vars. |
wp-includes/user.php:get_user_option() | Retrieves user option that can be either per Site or per Network. |
wp-includes/post.php:get_posts_by_author_sql() | Retrieve the post SQL based on capability, author, and type. |
wp-includes/post.php:wp_insert_post() | Insert or update a post. |
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/revision.php:wp_restore_post_revision() | Restores a post to the specified revision. |
wp-includes/ms-deprecated.php:is_site_admin() | Determine if user is a site admin. |
wp-includes/comment-template.php:wp_list_comments() | Displays a list of comments. |
wp-includes/comment-template.php:comments_template() | Loads the comment template specified in $file. |
wp-includes/script-loader.php:wp_default_scripts() | Registers all WordPress scripts. |
wp-includes/comment.php:get_page_of_comment() | Calculates what page number a comment will appear on for comment paging. |
Changelog
Version | Description |
---|---|
MU (3.0.0) | Introduced. |