Upload image to acf field on user form update

On my wordpress site, i have a custom profile template on the front end where the user can update their user profile (including normal user fields and some ACF fields).

My form works fine, however i have a profile picture ACF field which i have created as i didnt want to use the gravatar. Now i need the user to be able to upload their image and for it to update the ACF field, but im stuck as to how to achieve it.
Below is what i have so far in terms of my user editing form. You will see the field

/* Get user info. */
global $current_user, $wp_roles;

$error = array();
/* If profile was saved, update profile. */
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'update-user' ) {

// Example of field update
if( isset($address) )
                update_user_meta($current_user->ID, 'address', esc_attr($address) );

// If form is submitted...
    if ( count($error) == 0 ) {
        do_action('edit_user_profile_update', $current_user->ID);
        $userPage = '/members/' . $firstName . '-' . $lastName;
        wp_redirect( $userPage );
<!-- Below iv just included the form and one of the fields as an example, as well as the image field which i need to work -->
<form method="post" id="edituser" action="" enctype="multipart/form-data">

<textarea class="form-control" name="address" id="address" placeholder="Address"><?php the_author_meta( 'address', $current_user->ID ); ?></textarea>

<input type="file" class="form-control" id="user_photo" name="user_photo" accept="image/*" >

<input name="updateuser" type="submit" id="updateuser" class="btn btn-primary btn-outline" value="<?php _e('Save Profile', 'profile'); ?>" />
<?php wp_nonce_field( 'update-user' ) ?>
<input name="action" type="hidden" id="action" value="update-user" />

Iv had a look at the wp_handle_upload function and if thats something i need to use? Any help will be appreciated.

Read more here: Upload image to acf field on user form update

Leave a Reply

Your email address will not be published. Required fields are marked *