Hire Now!
Whether you’re looking to launch your brand, showcase your portfolio, or open an online store, we’re here to bring your ideas to life.
Understanding the Hook: show_user_profile
and edit_user_profile
These hooks allow you to add custom fields to the user profile page in the admin area.
Add fields to the profile page and save them using the personal_options_update
and edit_user_profile_update
actions.
Code Example
function add_custom_user_profile_fields($user) {
?>
<h3>Extra Information</h3>
<table class="form-table">
<tr>
<th><label for="twitter">Twitter Handle</label></th>
<td>
<input type="text" name="twitter" id="twitter" value="<?php echo esc_attr(get_user_meta($user->ID, 'twitter', true)); ?>" />
</td>
</tr>
</table>
<?php
}
add_action('show_user_profile', 'add_custom_user_profile_fields');
add_action('edit_user_profile', 'add_custom_user_profile_fields');
function save_custom_user_profile_fields($user_id) {
if (!current_user_can('edit_user', $user_id)) {
return false;
}
update_user_meta($user_id, 'twitter', sanitize_text_field($_POST['twitter']));
}
add_action('personal_options_update', 'save_custom_user_profile_fields');
add_action('edit_user_profile_update', 'save_custom_user_profile_fields');
Get the latest news about our updates and discounts
Copyright © 2024 - CollectWP
Powered by DeoPixel with love & passion 💪
Discussion
No discussion