0

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:

  1. 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?
  2. 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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.