Function Reference/get currentuserinfo

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

描述

获取当前登录用户信息(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)

用法

<?php get_currentuserinfo(); ?>

例子

默认用法

调用get_currentuserinfo()赋值给$userdata,然后可以通过访问$userdata的成员变量获取这些数据

<?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

访问全局变量

很多数据被置于独立的全局变量中,可以被直接访问

<?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

参数

该函数不接收任何参数,下面程序可用语判断当前是否有用户登录


<?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