get current user email wordpress

  1. Use the WordPress function wp_get_current_user() to retrieve the current user object.
  2. Check if the user object is not empty to ensure a user is logged in.
  3. If a user is logged in, use the get method on the user object to retrieve the user's email address.
// Step 1: Get the current user object
$current_user = wp_get_current_user();

// Step 2: Check if the user object is not empty
if ($current_user->ID != 0) {

    // Step 3: Retrieve the user's email address
    $user_email = $current_user->user_email;

    // Now $user_email contains the current user's email address
}