get_user_by_email()

September 15th, 2008

Posted by brajesh

This is second in the series of un documented but useful wordpress api functions.

get_user_by_email($email)

Description

It is one of the important but not documented method on codex(as of now),It provides same information as the get_userdata(),get_userdatabylogin(), except the fact that it takes the email address of registered user(e.g. admin@geekytalks.com as an argument rather than the ID/username of user).It returns an object with the information pertaining to the user whose login name is passed to it. Properties map directly to wp_users table in the database.

Usage

The call to get_user_by_email() returns the user’s data, where it can be retrieved using member variables.

<?php
$user_info=get_user_by_email(get_option('admin_email));
echo ('Username:'.$user_info->user_login . '\n');
      echo('User level: ' . $user_info->user_level . '\n');
      echo('User ID: ' . $user_info->ID . '\n');
?>

Username: admin
User level: 10
User ID: 1

Accessing Usermeta Data

<?php
$user_info=get_user_by_email(get_option('admin_email));
echo ($user_info->last_name .  ", " . $user_info->first_name . "\n");
?>

Singh,Brajesh

Parameters

$email

(String) (required) The email address(of registered user) of the user whose data should be retrieved.

Default: None

Values in users & user_meta table

Here are the values in the users table you can access via this function:

users

  • ID
  • user_login
  • user_pass
  • user_nicename
  • user_email
  • user_url
  • user_registered
  • user_activation_key
  • user_status
  • display_name

useful in user_meta

  • first_name
  • last_name
  • nickname
  • user_level
  • admin_color (Theme of your admin page. Default is fresh.)
  • closedpostboxes_page
  • nickname
  • primary_blog
  • rich_editing
  • source_domain
  • It works in the same manner as get_userdata() ,except that the argument passed in get_userdata() is an integer(The ID of User),while In the case of get_userdatabylogin() ,the argument passed is string(The Login name e.g. “admin”)

See as a reference :http://codex.wordpress.org/Function_Reference/get_userdata

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • BlinkList
  • description
  • Furl
  • IndiaGram
  • LinkedIn
  • Live
  • Ma.gnolia
  • Netvouz
  • Slashdot
  • SphereIt
  • StumbleUpon
  • Technorati
  • TwitThis

Leave a Reply