Function Reference/get currentuserinfo

来自WordPress中文文档
Bures23willi2讨论 | 贡献2008年8月7日 (四) 14:59的版本 Usage
跳转至: 导航搜索

Description

获取当前登录用户信息(wp_users表的字段),将其赋值给全局变量$userdata中,同时对下面几个独立的全局变量赋值

  • $user_login
  • $user_level
  • $user_ID
  • $user_email
  • $user_url (User's website, as entered in the user's Profile)
  • $user_pass_md5 (A md5 hash of the user password -- a type of encoding that is very nearly, if not entirely, impossible to decode, but useful for comparing input at a password prompt with the actual user password.)
  • $user_identity (User's name, displayed according to the 'How to display name' User option)

Usage

<?php get_currentuserinfo(); ?>

Examples

Default Usage

The call to get_currentuserinfo() places the current user's info into $userdata, where it can be retrieved using member variables.

<?php global $userdata;
      get_currentuserinfo();

      echo('Username: ' . $userdata->user_login . "\n");
      echo('User level: ' . $userdata->user_level . "\n");
      echo('User ID: ' . $userdata->ID . "\n");
?>
Username: Zedd

User level: 10

User ID: 1

Using Separate Globals

Much of the user data is placed in separate global variables, which can be accessed directly.

<?php global $user_identity , $user_email;
      get_currentuserinfo();

      echo($user_identity . "'s email address is: " . $user_email);
?>
Zedd's email address is: fake@email.com

Parameters

This function does not accept any parameters.

To determine if there is a user currently logged in, do this:

<?php global $user_ID;
      get_currentuserinfo();

      if ('' == $user_ID) {
         //no user logged in
      }
?>

includeonlydiv style=clear:both; background-color:#EEEEFF; border:1px solid #CCCCCC; color:#000000; padding:7px; margin:0.5em auto 0.5em auto; vertical-align:middle;This article is marked as in need of editing. You can help Codex by editing it./div/includeonlynoinclude

Description

This Template is used by Codex:Template Messages.

Usage

pre 检查到模板循环:模板:Message /pre

Result

检查到模板循环:模板:Message

/noinclude