WordPress:Function Reference/get currentuserinfo

来自站长百科
跳转至: 导航、​ 搜索

Description[ ]

描述[ ]

Retrieves the information pertaining to the currently logged in user, and places it in the global variable $userdata. Properties map directly to the wp_users table in the database (see Database Description).

返回关于当前登录的用户的信息并且将这个信息放置于全局变量$userdata中。属性直接映射到数据库中的wp_users表格(请看看数据库描述)。

Also places the individual attributes into the following separate global variables:

同时将单个的属性放置到下面分开的全局变量中:

  • $user_login
  • $user_level
  • $user_ID
  • $user_email


  • $user_login
  • $user_level
  • $user_ID
  • $user_email
  • $user_url (User's website, as entered in the user's Profile)
  • $user_url(用户的网站,输入进用户的基本资料)
  • $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_pass_md5(用户密码的md5 hash-编码的一种方式,几乎不能够解码,但还不是完全不能够,对于使用真正的用户密码来比较密码提示中的输入内容,很有用。)
  • $display_name (User's name, displayed according to the 'How to display name' User option)
  • $display_name (用户的名称,根据'怎样显示名称'用户选项,显示)

Usage[ ]

用法[ ]

%%% <?php get_currentuserinfo(); ?> %%%

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

调用get_currentuserinfo(),将当前用户的信息放置到$userdata,使用member变数,可以重新得到用户的信息。

<?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 $userdata;

      get_currentuserinfo();

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

用户级别: 10

用户ID: 1

Using Separate Globals[ ]

使用分开的 Globals[ ]

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

大多数用户的数据都放置在分开的全局变数中,你可以直接访问这些变数。

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

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

<?php global $display_name , $user_email;

      get_currentuserinfo();

      echo($display_name . "'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
      }
?>

<?php global $user_ID;

      get_currentuserinfo();

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

Here is another IF STATEMENT Example. It was used in the sidebar, in reference to the "My Fav" plugin at http://www.kriesi.at/archives/wordpress-plugin-my-favorite-posts

下面是另一个IF STATEMENT的例子。这个例子是用在边框中,指的是http://www.kriesi.at/archives/wordpress-plugin-my-favorite-posts中的"My Fav"插件。

<?php if ( $user_ID ) { ?>
<!-- enter info that logged in users will see -->
<!-- in this case im running a bit of php to a plugin -->

<?php mfp_display(); ?>

<?php } else {   ?>
<!-- here is a paragraph that is shown to anyone not logged in -->

<p>By <a href="<?php bloginfo('url'); ?>/wp-register.php">registering</a>, you can save your favorite posts for future reference.</p>

<?php } ?>


<?php if ( $user_ID ) { ?>
<!—输入信息,登录的用户能够看到 -->
<!-- in this case im running a bit of php to a plugin -->

<?php mfp_display(); ?>

<?php } else {   ?>
<!—下面有一个段落,显示给任何没有登录进来的人看 -->

<p>By <a href="<?php bloginfo('url'); ?>/wp-register.php">registering</a>, 你可以保存你最喜欢的文章,供以后阅读。</p>

<?php } ?>