檢索當前登陸用戶的相關信息,並將信息置入$userdata全局變量。函數屬性直接映射到數據庫(參見 Database Description)中的wp_usrs表格。php
一樣也將個體屬性放置到如下獨立全局變量中:數據庫
<?php get_currentuserinfo(); ?>wordpress
調用get_currentuserinfo()將當前用戶信息放入$userdata,可用成員變量在$userdata中檢索用戶信息。函數
<?php global $current_user; get_currentuserinfo(); echo('Username: ' . $current_user->user_login . "\n"); echo('User email: ' . $current_user->user_email . "\n"); echo('User level: ' . $current_user->user_level . "\n"); echo('User first name: ' . $current_user->user_firstname . "\n"); echo('User last name: ' . $current_user->user_lastname . "\n"); echo('User display name: ' . $current_user->display_name . "\n"); echo('User ID: ' . $current_user->ID . "\n"); ?>
Username: Zedd
User email: my@email.com
User level: 10
User first name: John
User last name: Doe
User display name: John Doepost
User ID: 1this
用戶資料大多存放在單個全局變量中,可直接訪問。編碼
<?php global $display_name , $user_email; get_currentuserinfo(); echo($display_name . "'s email address is: " . $user_email); ?>
Zedd's email address is: fake@email.comurl
注意:$display_name彷佛沒法在2.5以上版本中運行。$user_login運行良好。插件
<?php global $user_login , $user_email; get_currentuserinfo(); echo($user_login . "'s email address is: " . $user_email); ?>
該函數不接受任何參數。code
檢查當前是否有已登陸用戶,執行如下代碼:
<?php global $user_ID; get_currentuserinfo(); if ('' == $user_ID) { //no user logged in } ?>
下面仍然是一個IF STATEMENT示例,用在側邊條中,參照ttp://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 } ?>