問題描述
USERS 中有 5 個名為 Username Name Email Role 的默認列。現在我想添加一個更多的列與他的聯繫電話。
我該如何實現?
最佳解決方案
好的,以下是允許用户添加電話號碼的代碼。將此完整代碼粘貼到 functions.php 文件中。這將為”Phone Number” 的用户配置文件添加新字段,並在 WordPress 管理員手機上添加列用户表。
function new_contact_methods( $contactmethods ) {
$contactmethods['phone'] = 'Phone Number';
return $contactmethods;
}
add_filter( 'user_contactmethods', 'new_contact_methods', 10, 1 );
function new_modify_user_table( $column ) {
$column['phone'] = 'Phone';
return $column;
}
add_filter( 'manage_users_columns', 'new_modify_user_table' );
function new_modify_user_table_row( $val, $column_name, $user_id ) {
switch ($column_name) {
case 'phone' :
return get_the_author_meta( 'phone', $user_id );
break;
default:
}
return $val;
}
add_filter( 'manage_users_custom_column', 'new_modify_user_table_row', 10, 3 );
編輯
要添加兩列,您需要進行一些更改。比較兩個代碼來理解。
function new_modify_user_table( $column ) {
$column['phone'] = 'Phone';
$column['xyz'] = 'XYZ';
return $column;
}
add_filter( 'manage_users_columns', 'new_modify_user_table' );
function new_modify_user_table_row( $val, $column_name, $user_id ) {
switch ($column_name) {
case 'phone' :
return get_the_author_meta( 'phone', $user_id );
break;
case 'xyz' :
return '';
break;
default:
}
return $val;
}
add_filter( 'manage_users_custom_column', 'new_modify_user_table_row', 10, 3 );
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。
