我已经用上面的代码和另一个代码移动电话字段的组合进行了分类。我想与任何需要这些代码的人分享这些代码:
/* ADD EXTRA PHONE FIELD INTO USER PROFILE - WORKING */
// Add a phone field into user profile page
add_action( \'show_user_profile\', \'extra_user_profile_fields\' );
add_action( \'edit_user_profile\', \'extra_user_profile_fields\' );
function extra_user_profile_fields( $user ) { ?>
<table class="form-table">
<tr id="custom_user_field_row">
<th><label for="Phone"><?php _e("Phone Number"); ?></label></th>
<td>
<input type="text" name="phone" id="phone" value="<?php echo esc_attr(
get_the_author_meta( \'phone\', $user->ID ) ); ?>" class="regular-text" /><br />
</td>
</tr>
</table>
<?php } // Saving Phone field
add_action( \'personal_options_update\', \'save_extra_user_profile_fields\' );
add_action( \'edit_user_profile_update\', \'save_extra_user_profile_fields\' );
function save_extra_user_profile_fields( $user_id ) {
if ( !current_user_can( \'edit_user\', $user_id ) ) { return false; }
update_user_meta( $user_id, \'designation\', $_POST[\'designation\'] );
update_user_meta( $user_id, \'phone\', $_POST[\'phone\'] );
}
function moving_extra_field() { // Moving Phone field above Password on user
profile page
$screen = get_current_screen();
if ( $screen->id != "profile" && $screen->id != "user-edit" )
return;
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
field = $(\'#custom_user_field_row\').remove();
field.insertBefore(\'#password\');
});
</script>
<?php
}
add_action( \'admin_head\', \'moving_extra_field\' );
上述代码将在用户配置文件页面上显示电话字段,将其保存并移动到密码上方。这不是我的代码;我在这个网站上合并了代码。
尽情享受吧!