Tùy biến thêm trường cho User.
//custom user profile
//show và edit page
add_action('show_user_profile', 'my_show_extra_profile_fields');
add_action('edit_user_profile', 'my_show_extra_profile_fields');
function my_show_extra_profile_fields($user)
{
$phone=get_the_author_meta('phone',$user->ID);
?>
<table class="form-table">
<tr>
<td>phone number</td>
<td><input type="text" name="phone" value="<?php echo $phone?>"/></td>
</tr>
</table>
<?php
}
|
Để lưu vào database sử dụng thêm đồng thời 2 action “personal_options_update” ,”edit_user_profile_update” để cập nhật fields.
//update user profile
add_action('personal_options_update', 'my_save_extra_profile_fields');
add_action('edit_user_profile_update', 'my_save_extra_profile_fields');
function my_save_extra_profile_fields($user_id)
{
if (!current_user_can('edit_user', $user_id))
return false;
update_usermeta($user_id, 'phone', $_POST['phone']); //update user profile
}
|
Unregistered version