WordPress Custom User Profile Fields Generator is a tool that enables the creation of custom fields in the WordPress user profile.
function wpskills_custom_user_profile_fields($user) {
$output = '';
$output .= '<h2>'.__("Custom user profile fields", "text-domain").'</h2>';
$output .= '<table class="form-table">';
$output .= '<tr>';
$output .= '<th><label for="hobby">'.__("Hobby", "text-domain").'</label></th>';
$output .= '<td>';
$output .= '<input placeholder="'.__("Hobby", "text-domain").'" type="text" name="hobby" id="hobby" value="'.esc_attr(get_user_meta($user->ID, 'hobby', true)).'" class="regular-text" /><br />';
$output .= '<span class="description">'.__("What is your hobby?", "text-domain").'</span>';
$output .= '</td>';
$output .= '</tr>';
$output .= '</table>';
echo $output;
}
add_action('show_user_profile', 'wpskills_custom_user_profile_fields');
add_action('edit_user_profile', 'wpskills_custom_user_profile_fields');
// Save Custom User Profile Fields
function wpskills_custom_user_profile_fields_save($user_id) {
if (!current_user_can('edit_user', $user_id )) {
return false;
}
update_user_meta($user_id, 'hobby', $_POST['hobby']);
}
add_action('personal_options_update', 'wpskills_custom_user_profile_fields_save');
add_action('edit_user_profile_update', 'wpskills_custom_user_profile_fields_save');