解析WordPress中控制用戶登陸和判斷用戶登陸的PHP函數(shù)
登陸函數(shù):wp_signon()
函數(shù)介紹:
wp_signon()函數(shù)用于授權(quán)給用戶登陸wordpress并可記住該用戶名稱。該函數(shù)取代了wp_login。WordPress 2.5版本起啟用。
函數(shù)使用:
<?php wp_signon( $credentials, $secure_cookie ) ?>
參數(shù)說明:
- $credentials
- (array) (可選) 登陸用戶信息.
- Default: None
- $secure_cookie
- (boolean) (可選) 決定是否使用安全cookie。
- Default: None
注意:如果你沒有提供 $credentials, wp_signon 使用 $_POST 參數(shù)(鍵值為 “l(fā)og”, “pwd” 和 “rememberme”).
函數(shù)返回值:
(object)
登陸失敗返回對象WP_Error,登陸成功則返回WP_User
函數(shù)實例:
$creds = array(); $creds['user_login'] = 'example'; //wordperss后臺用戶名稱 $creds['user_password'] = '123456'; //wordperss后臺用戶密碼 $creds['remember'] = true; $user = wp_signon( $creds, false ); if ( is_wp_error($user) ) echo $user->get_error_message();
源文件:
wp_signon() 位于 wp-includes/user.php.
判斷用戶是否登陸函數(shù):is_user_logged_in()
函數(shù)介紹:
is_user_logged_in()函數(shù)由于判斷用戶是否登陸,如果用戶已經(jīng)登陸返回True否則返回False。
函數(shù)使用:
<?php if ( is_user_logged_in() ) { ... } ?>
函數(shù)參數(shù):
該函數(shù)不接受任何參數(shù)。
返回值:
(boolean)
已登陸返回True,否則返回False。
函數(shù)實例:
以下實例顯示已登陸用戶或者未登陸用戶顯示的內(nèi)容:
<?php if ( is_user_logged_in() ) { echo 'Welcome, registered user!'; } else { echo 'Welcome, visitor!'; } ?>
源文件:
is_user_logged_in() 位于文件 wp-includes/pluggable.php.
相關(guān)文章
php echo, print, print_r, sprintf, var_dump, var_expor的使用區(qū)別
本篇文章是對php中echo, print, print_r, sprintf, var_dump, var_expor的使用區(qū)別進行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06php采集文章中的圖片獲取替換到本地(實現(xiàn)代碼)
本篇文章是對php采集文章中的圖片獲取替換到本地的實現(xiàn)代碼進行了詳細(xì)的分析介紹,需要的朋友參考下2013-07-07完美解決dedecms中的[html][/html]和[code][/code]問題
完美解決dedecms中的[html][/html]和[code][/code]問題...2007-03-03Windows下的PHP 5.3.x安裝 Zend Guard Loader教程
這篇文章主要介紹了Windows下的PHP 5.3.x安裝 Zend Guard Loader教程,安裝方法很簡單,下載DLL文件,加入配置文件即可,需要的朋友可以參考下2014-09-09深入研究PHP中的preg_replace和代碼執(zhí)行
這篇文章主要給大家介紹了關(guān)于PHP中preg_replace和代碼執(zhí)行的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-08-08