用户個人資料的聯繫信息裏,默認有郵箱、站點、 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