这很简单。只需将功能和选项添加到show_user_profile
和edit_user_profile
挂钩,并将其保存在personal_options_update
和edit_user_profile_update
.
例如,像这样(您可以添加自己的字段(文本、数字等))
/********* Additional User Content ***********/
add_action( \'show_user_profile\', \'mytheme_extra_profile_fields\' );
add_action( \'edit_user_profile\', \'mytheme_extra_profile_fields\' );
function mytheme_extra_profile_fields( $user ) { ?>
<?php $customData = get_user_meta( $user->ID, \'custom_user_fields\', true ); ?>
<h3><?php esc_html_e(\'Custom option\', \'mytheme\'); ?></h3>
<table class="form-table">
<tr>
<th><?php esc_html_e(\'Custom option\', \'mytheme\'); ?></th>
<td>
<input type="checkbox" name="custom_user_fields_option" id="option" value="1" <?php if(isset($customData[\'checkbox\'])){ checked($customData[\'checkbox\'], 1); } ?>/>
<span class="description"><?php esc_html_e(\'Check for an option.\', \'mytheme\'); ?></span>
</td>
</tr>
</table>
<?php }
add_action( \'personal_options_update\', \'mytheme_save_extra_profile_fields\' );
add_action( \'edit_user_profile_update\', \'mytheme_save_extra_profile_fields\' );
function mytheme_save_extra_profile_fields( $user_id ) {
$userData = array();
if ( !current_user_can( \'edit_user\', $user_id ) )
return false;
if(!empty( $_POST[\'custom_user_fields_option\'] )) {
$userData[\'checkbox\'] = intval( $_POST[\'custom_user_fields_option\'] );
}
if(!empty($userData)) {
update_user_meta( $user_id, \'custom_user_fields\', $userData);
}
}
这会给你
在单用户页面中(
profile.php
).