update_user_option()函數(shù)
update_user_option()函數(shù)作用利用全局博客權(quán)限更新用戶(hù)選項(xiàng)。
用戶(hù)選項(xiàng)類(lèi)似于用戶(hù)元數(shù)據(jù),唯一的不同之處在于用戶(hù)選項(xiàng)支持全局博客選項(xiàng)。如果'global'參數(shù)為False(默認(rèn)情況下),update_user_option會(huì)預(yù)先將WordPress表前綴改成選項(xiàng)名稱(chēng)。
【函數(shù)使用】
<?php update_user_option( $user_id, $option_name, $newvalue, $global ) ?>
【函數(shù)參數(shù)】
$user_id
(整數(shù))(必需)用戶(hù)ID
默認(rèn)值:None
$option_name
(字符串)(必需)用戶(hù)選項(xiàng)名稱(chēng)
默認(rèn)值:0
$newvalue
(混合)(必需)用戶(hù)選項(xiàng)值
默認(rèn)值:None
$global
(布爾值)(可選)選項(xiàng)名稱(chēng)是否博客特有
默認(rèn)值:false
【返回值】
(boolean)
成功返回True,失敗返回False
【源文件】
update_user_option())位于 wp-includes/user.php中。
wordpress get_user_option()函數(shù)
get_user_option()函數(shù)
【函數(shù)介紹】
檢索用戶(hù)選項(xiàng),包括global、user或blog。
如果未給出用戶(hù)ID,使用當(dāng)前用戶(hù)ID。如果給出用戶(hù)ID,檢索該用戶(hù)相關(guān)數(shù)據(jù)。函數(shù)結(jié)果的過(guò)濾器將原始選項(xiàng)名稱(chēng)和最終用戶(hù)數(shù)據(jù)庫(kù)對(duì)象作為第三個(gè)參數(shù)傳遞。
該選項(xiàng)函數(shù)首先查找非全局名稱(chēng),然后查找全局名稱(chēng),如果仍然沒(méi)有找到,函數(shù)會(huì)查找博客選項(xiàng)??赏ㄟ^(guò)插件設(shè)置或修改選項(xiàng)。
【函數(shù)用法】
<?php get_user_option( $option, $user, $check_blog_options ) ?>
【參數(shù)介紹】
$option
(字符串)(必需)用戶(hù)選項(xiàng)名稱(chēng)
默認(rèn)值:None
$user
(整數(shù))(可選)用戶(hù)ID
默認(rèn)值:0
$check_blog_options
(布爾值)(可選)如果之前的用戶(hù)選項(xiàng)不存在,是否需要在選項(xiàng)表中查找一個(gè)選項(xiàng)
默認(rèn)值:true
【返回值】
(混合)
成功返回選項(xiàng)的值,失敗返回FALSE
【函數(shù)實(shí)例】
<?php $bar = get_user_option( 'show_admin_bar_front', get_current_user_id() ); if( $bar == 'true' ) { echo 'The admin bar is enabled'; } else { echo 'The admin bar is disabled'; }?>
【源文件】
get_user_option() is located in wp-includes/user.php.