Answers:
您需要使用'show_user_profile'
,'edit_user_profile'
,'personal_options_update'
和'edit_user_profile_update'
挂钩。
这是添加电话号码的一些代码:
add_action( 'show_user_profile', 'yoursite_extra_user_profile_fields' );
add_action( 'edit_user_profile', 'yoursite_extra_user_profile_fields' );
function yoursite_extra_user_profile_fields( $user ) {
?>
<h3><?php _e("Extra profile information", "blank"); ?></h3>
<table class="form-table">
<tr>
<th><label for="phone"><?php _e("Phone"); ?></label></th>
<td>
<input type="text" name="phone" id="phone" class="regular-text"
value="<?php echo esc_attr( get_the_author_meta( 'phone', $user->ID ) ); ?>" /><br />
<span class="description"><?php _e("Please enter your phone."); ?></span>
</td>
</tr>
</table>
<?php
}
add_action( 'personal_options_update', 'yoursite_save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'yoursite_save_extra_user_profile_fields' );
function yoursite_save_extra_user_profile_fields( $user_id ) {
$saved = false;
if ( current_user_can( 'edit_user', $user_id ) ) {
update_user_meta( $user_id, 'phone', $_POST['phone'] );
$saved = true;
}
return true;
}
该代码将在用户屏幕上添加一个类似于以下内容的字段:
关于此主题,也有一些博客文章可能会有所帮助:
或者,如果您不喜欢自己动手,则可以使用一些插件添加上述功能(尽管我确定还有其他功能):
// remove aim, jabber, yim
function hide_profile_fields( $contactmethods ) {
unset($contactmethods['aim']);
unset($contactmethods['jabber']);
unset($contactmethods['yim']);
return $contactmethods;
}
// add anything else
function my_new_contactmethods( $contactmethods ) {
//add Birthday
$contactmethods['birthday'] = 'Birthday';
//add Address
$contactmethods['address'] = 'Address';
//add City
$contactmethods['city'] = 'City';
//add State
$contactmethods['state'] = 'State';
//add Postcode
$contactmethods['postcode'] = 'Postcode';
//add Phone
$contactmethods['phone'] = 'Phone';
//add Mobilphone
$contactmethods['mphone'] = 'Mobilphone';
return $contactmethods;
}
add_filter('user_contactmethods','my_new_contactmethods',10,1);
add_filter('user_contactmethods','hide_profile_fields',10,1);
希望这可以帮助。
资料来源:WPBeginner