get_current_user_id()
Get 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 );
}  Related
Uses
| Uses | Description | 
|---|---|
| wp-includes/pluggable.php: wp_get_current_user() |   Retrieve the current user object.  |  
Used By
| Used By | Description | 
|---|---|
| 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.  |  
| 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() |   Function that 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() |   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/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() |   Get 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() |   Publish changeset values.  |  
| wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::save_changeset_post() |   Save the post for the loaded changeset.  |  
| wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::changeset_data() |   Get 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() |   Print 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() |   Get 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() |   Remove all session tokens for the current user from the database.  |  
| wp-includes/user.php: wp_get_all_sessions() |   Retrieve a list of sessions for the current user.  |  
| wp-includes/user.php: wp_destroy_current_session() |   Remove the current session token from the database.  |  
| wp-includes/user.php: wp_destroy_other_sessions() |   Remove 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() |   Show 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() |   Check to see if the post is currently being edited by another user.  |  
| wp-admin/includes/post.php: wp_set_post_lock() |   Mark 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 $_POST data.  |  
| 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() |   Save a post submitted with XHR  |  
| 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/post.php: _wp_translate_postdata() |   Rename $_POST data from form names to DB post columns.  |  
| wp-admin/includes/post.php: edit_post() |   Update an existing post with values provided in $_POST.  |  
| 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/capabilities.php: is_super_admin() |   Determine if user is a site admin.  |  
| 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() | |
| wp-includes/admin-bar.php: wp_admin_bar_wp_menu() |   Add the WordPress logo menu.  |  
| wp-includes/admin-bar.php: wp_admin_bar_my_account_item() |   Add the “My Account” item.  |  
| wp-includes/admin-bar.php: wp_admin_bar_my_account_menu() |   Add 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() |   Clean all user caches  |  
| wp-includes/user.php: is_user_member_of_blog() |   Find out whether a user is a member of a given blog.  |  
| wp-includes/user.php: setup_userdata() |   Set up global user vars.  |  
| wp-includes/user.php: get_user_option() |   Retrieve 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() |   Register all WordPress scripts.  |  
| wp-includes/comment.php: get_page_of_comment() |   Calculate what page number a comment will appear on for comment paging.  |  
Changelog
| Version | Description | 
|---|---|
| MU (3.0.0) | Introduced. | 
    © 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
    https://developer.wordpress.org/reference/functions/get_current_user_id