Updating User ‘Description’ Meta Data (not working as expected)
Question
I’m creating a form to allow users to update their bio (‘description’ metadata) on a custom profile page.
Current values are successfully retrieved and new values are being stored to the DB, but with a few unexpected issues:
- After clicking ‘Save’, the page updates with a blank field. I have to refresh to show the updated value. Can I get this to update automatically on form submit?
- Is there a better alternative to an HTML textarea tag? I don’t like the idea of the textarea being below the Save button. I see there is a wp_editor() function but I don’t understand the required syntax to use it.
Also, please feel free to give any pointers on my function. I’m new at PHP so I’m sure it’s not 100% solid.
function show_user_bio_edit_form() {
global $current_user;
$get_user_bio = get_user_meta( $current_user->ID, 'description', true);
?>
<form id="update_user_bio" name="update_user_bio" action="" method="POST">
<button type="submit">Save</button>
</form>
<textarea id="bio_field" name="bio_field" form="update_user_bio"><?php echo $get_user_bio; ?></textarea>
<?php
$update_user_bio = wp_kses_post( $_POST['bio_field'] );
update_user_meta( $current_user->ID, 'description', $update_user_bio);
}
add_shortcode('user_bio_edit', 'show_user_bio_edit_form');
0
custom-field, functions, profiles, user-meta
3 years
2019-10-31T17:18:58-05:00
2019-10-31T17:18:58-05:00 0 Answers
72 views
0
Leave an answer