wp_get_current_user()

Purpose

  • Retrieves the current user object.

Implementation

  • Include in
    • Plugin
    • functions.php of active theme
<?php
$current_user = wp_get_current_user();

Example of output of Object $current_user

WP_User Object
(
    [data] => stdClass Object
        (
            [ID] => 8
            [user_login] => subscriber
            [user_pass] => {Users Password}
            [user_nicename] => subscriber
            [user_email] => subscriber@sblik.com
            [user_url] => 
            [user_registered] => 2023-05-02 19:41:27
            [user_activation_key] => 
            [user_status] => 0
            [display_name] => Subscriber Sblik
        )

    [ID] => 8
    [caps] => Array
        (
            [subscriber] => 1
        )

    [cap_key] => wp_capabilities
    [roles] => Array
        (
            [0] => subscriber
        )

    [allcaps] => Array
        (
            [read] => 1
            [level_0] => 1
            [subscriber] => 1
        )

    [filter] => 
    [site_id:WP_User:private] => 1
)