Add Custom User Meta Field
Add Custom User Meta Field.
<?php
function add_custom_user_meta_field($user) {
?>
<h3>Custom Meta Field</h3>
<table class="form-table">
<tr>
<th><label for="custom_meta">Custom Meta</label></th>
<td>
<input type="text" name="custom_meta" id="custom_meta" value="<?php echo esc_attr(get_the_author_meta('custom_meta', $user->ID)); ?>" class="regular-text" />
<br />
<span class="description">Enter your custom meta value here.</span>
</td>
</tr>
</table>
<?php
}
add_action('show_user_profile', 'add_custom_user_meta_field');
add_action('edit_user_profile', 'add_custom_user_meta_field');
function save_custom_user_meta_field($user_id) {
if (!current_user_can('edit_user', $user_id)) {
return false;
}
update_usermeta($user_id, 'custom_meta', $_POST['custom_meta']);
}
add_action('personal_options_update', 'save_custom_user_meta_field');
add_action('edit_user_profile_update', 'save_custom_user_meta_field');
?>
Post Comment