WordPress: Function Reference/get currentuserinfo:修订间差异
(新页面: == Description == Retrieves the information pertaining to the currently logged in user, and places it in the global variable <tt>$userdata</tt>. Properties map directly to the wp_users t...) |
无编辑摘要 |
||
第1行: | 第1行: | ||
== Description == | == Description == | ||
== 描述 == | |||
Retrieves the information pertaining to the currently logged in user, and places it in the global variable <tt>$userdata</tt>. Properties map directly to the wp_users table in the database (see [[WordPress:Database Description#Table:_wp_users|Database Description]]). | Retrieves the information pertaining to the currently logged in user, and places it in the global variable <tt>$userdata</tt>. Properties map directly to the wp_users table in the database (see [[WordPress:Database Description#Table:_wp_users|Database Description]]). | ||
返回关于当前登录的用户的信息并且将这个信息放置于全局变量<tt>$userdata</tt>中。属性直接映射到数据库中的wp_users表格(请看看[[WordPress:Database Description#Table:_wp_users|数据库描述]])。 | |||
Also places the individual attributes into the following separate global variables: | Also places the individual attributes into the following separate global variables: | ||
同时将单个的属性放置到下面分开的全局变量中: | |||
:* <tt>$user_login</tt> | |||
:* <tt>$user_level</tt> | |||
:* <tt>$user_ID</tt> | |||
:* <tt>$user_email</tt> | |||
:* <tt>$user_login</tt> | :* <tt>$user_login</tt> | ||
:* <tt>$user_level</tt> | :* <tt>$user_level</tt> | ||
:* <tt>$user_ID</tt> | :* <tt>$user_ID</tt> | ||
:* <tt>$user_email</tt> | :* <tt>$user_email</tt> | ||
:* <tt>$user_url</tt> (User's website, as entered in the user's Profile) | :* <tt>$user_url</tt> (User's website, as entered in the user's Profile) | ||
:* <tt>$user_url</tt>(用户的网站,输入进用户的基本资料) | |||
:* <tt>$user_pass_md5</tt> (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.) | :* <tt>$user_pass_md5</tt> (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.) | ||
:* <tt>$user_pass_md5</tt>(用户密码的md5 hash-编码的一种方式,几乎不能够解码,但还不是完全不能够,对于使用真正的用户密码来比较密码提示中的输入内容,很有用。) | |||
:* <tt>$display_name</tt> (User's name, displayed according to the 'How to display name' User option) | :* <tt>$display_name</tt> (User's name, displayed according to the 'How to display name' User option) | ||
:* <tt>$display_name</tt> (用户的名称,根据'怎样显示名称'用户选项,显示) | |||
== Usage == | == Usage == | ||
== 用法== | |||
%%% <?php get_currentuserinfo(); ?> %%% | |||
%%% <?php get_currentuserinfo(); ?> %%% | %%% <?php get_currentuserinfo(); ?> %%% | ||
第19行: | 第44行: | ||
=== Default Usage === | === Default Usage === | ||
== 例子 == | |||
===默认用法=== | |||
The call to <tt>get_currentuserinfo()</tt> places the current user's info into <tt>$userdata</tt>, where it can be retrieved using member variables. | The call to <tt>get_currentuserinfo()</tt> places the current user's info into <tt>$userdata</tt>, where it can be retrieved using member variables. | ||
调用<tt>get_currentuserinfo()</tt>,将当前用户的信息放置到<tt>$userdata</tt>,使用member变数,可以重新得到用户的信息。 | |||
<?php global $userdata; | <?php global $userdata; | ||
第33行: | 第64行: | ||
User level: 10<br /> | User level: 10<br /> | ||
User ID: 1</div> | User ID: 1</div> | ||
<?php global $userdata; | |||
get_currentuserinfo(); | |||
echo('Username: ' . $userdata->user_login . "\n"); | |||
echo('User level: ' . $userdata->user_level . "\n"); | |||
echo('User ID: ' . $userdata->ID . "\n"); | |||
?> | |||
<div style="border:1px solid blue; width:50%; padding:10px">Username: Zedd<br /> | |||
用户级别: 10<br /> | |||
用户ID: 1</div> | |||
=== Using Separate Globals === | === Using Separate Globals === | ||
=== 使用分开的 Globals === | |||
Much of the user data is placed in separate global variables, which can be accessed directly. | Much of the user data is placed in separate global variables, which can be accessed directly. | ||
大多数用户的数据都放置在分开的全局变数中,你可以直接访问这些变数。 | |||
<?php global $display_name , $user_email; | <?php global $display_name , $user_email; | ||
get_currentuserinfo(); | |||
echo($display_name . "'s email address is: " . $user_email); | |||
?> | |||
<div style="border:1px solid blue; width:50%; padding:10px">Zedd's email address is: fake@email.com</div> | |||
<?php global $display_name , $user_email; | |||
get_currentuserinfo(); | get_currentuserinfo(); | ||
第47行: | 第103行: | ||
== Parameters == | == Parameters == | ||
== 参数== | |||
This function does not accept any parameters. | This function does not accept any parameters. | ||
这个函数不接受任何参数。 | |||
To determine if there is a user currently logged in, do this: | |||
可以执行下面的步骤,决定当前有没有用户登录进来: | |||
<?php global $user_ID; | <?php global $user_ID; | ||
get_currentuserinfo(); | |||
if ('' == $user_ID) { | |||
//no user logged in | |||
} | |||
?> | |||
<?php global $user_ID; | |||
get_currentuserinfo(); | get_currentuserinfo(); | ||
第60行: | 第128行: | ||
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 | 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"插件。 | |||
<pre> | <pre> | ||
第70行: | 第140行: | ||
<?php } else { ?> | <?php } else { ?> | ||
<!-- here is a paragraph that is shown to anyone not logged in --> | <!-- 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 } ?> | |||
</pre> | |||
<pre> | |||
<?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>, you can save your favorite posts for future reference.</p> | <p>By <a href="<?php bloginfo('url'); ?>/wp-register.php">registering</a>, you can save your favorite posts for future reference.</p> |
2008年7月19日 (六) 16:44的版本
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"); ?>
User level: 10
<?php global $userdata;
get_currentuserinfo(); echo('Username: ' . $userdata->user_login . "\n"); echo('User level: ' . $userdata->user_level . "\n"); echo('User ID: ' . $userdata->ID . "\n"); ?>
用户级别: 10
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); ?>
<?php global $display_name , $user_email;
get_currentuserinfo(); echo($display_name . "'s email address is: " . $user_email); ?>
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>, you can save your favorite posts for future reference.</p> <?php } ?>