使用者個人資料的聯絡資訊裡,預設有郵箱、站點、 AIM 、雅虎通和 Jabber,而有些東西我們可能都沒聽說過,所以去除是非常有必要的。本文就來教你,怎麼自定義這些資訊的專案。
下邊的程式碼刪除了 AIM 、雅虎通和 Jabber,新增了新浪微博、騰訊微博和 QQ 這些國內比較常用的社交網路。
/**
*WordPress 自定義使用者聯絡資訊的專案
*/
function Bing_change_user_contact_information( $fields ){
unset( $fields['aim'] );
unset( $fields['yim'] );
unset( $fields['jabber'] );
$fields['weibo'] = '新浪微博';
$fields['t_weibo'] = '騰訊微博';
$fields['qq'] = '騰訊 QQ';
return $fields;
}
add_filter( 'user_contactmethods', 'Bing_change_user_contact_information' );

想獲取這些資訊只要使用 get_the_author_meta() 函式即可。
$weibo = get_the_author_meta( 'weibo', $user_id );//新浪微博
$t_weibo = get_the_author_meta( 't_weibo', $user_id );//騰訊微博
$qq = get_the_author_meta( 'qq', $user_id );//騰訊 QQ