0

I have a custom front end user profile form. When updating the profile without changing the profile's image it will remove the image. You have to reupload the image any time you update your user profile.

This is the edit-profile.php

<?php
// Template Name: Edit Profile

//get user id from email address
$current_user = wp_get_current_user();

if ($current_user->user_email == ""):
    wp_redirect("/login");
endif;

$posts = get_posts(array(
    'numberposts' => -1,
    'post_type' => 'member',
    'meta_key' => 'email_address',
    'meta_value' => $current_user->user_email
));

if ( $posts ) :
    $pid = $posts[0]->ID;;
endif;


get_header(); 

?>
<div id="content" class="full-width">
    <?php echo avada_render_rich_snippets_for_pages(); ?>
    <?php echo avada_featured_images_for_pages(); ?>
    <form action="/save-profile" method="post" enctype="multipart/form-data">
        <div style="float:left;width:50%">
            <h3>Contact Information:</h3>
            <p> 
            First Name:<br/>
            <input type="text" name="first_name" value="<?php echo get_post_meta($pid,'first_name',true);?>"/>
            </p>
            <p>
            Middle Name:<br/>
            <input type="text" name="middle_name" value="<?php echo get_post_meta($pid,'middle_name',true);?>"/>
            </p>
            <p>
            Last Name:<br/>
            <input type="text" name="last_name" value="<?php echo get_post_meta($pid,'last_name',true);?>"/>
            </p>
            <p>
            Company Name:<br/>
            <input type="text" name="company_name" value="<?php echo get_post_meta($pid,'company_name',true);?>"/>
            </p>
            <p>
            Address:<br/>
            <input type="text" name="address" value="<?php echo get_post_meta($pid,'address',true);?>"/>
            </p>
            <p>
            Address:<br/>
            <input type="text" name="address_2" value="<?php echo get_post_meta($pid,'address_2',true);?>"/>
            </p>
            <p>
            City:<br/>
            <input type="text" name="city" value="<?php echo get_post_meta($pid,'city',true);?>"/>
            </p>
            <p>
            State:<br/>
            <input type="text" name="state" value="<?php echo get_post_meta($pid,'state',true);?>"/>
            </p>
            <p>
            Zip:<br/>
            <input type="text" name="zip" value="<?php echo get_post_meta($pid,'zip',true);?>"/>
            </p>
            <p>
            Phone Number:<br/>
            <input type="text" name="phone_number" value="<?php echo get_post_meta($pid,'phone_number',true);?>"/>
            </p>
            <p>
            Fax Number:<br/>
            <input type="text" name="fax_number" value="<?php echo get_post_meta($pid,'fax_number',true);?>"/>
            </p>
            <p>
            Website:<br/>
            <input type="text" name="company_website" value="<?php echo get_post_meta($pid,'company_website',true);?>"/>
            </p>
            <p>
            Bio:<br/>
            <textarea name="biographical_info" style="width:100%;height:100px;"><?php echo get_post_meta($pid,'biographical_info',true);?></textarea>
            </p>
        </div>

        <div style="float:right;width:45%">
            <h3>User Profile Image:</h3>
            <p>To add your picture to your profile, select the image and it will be added when you save the form.</p>
            <img src="<?php echo get_field('profile_picture',$pid);?>" width="150"/>
            <br/>
            <input type="file" name="profile_picture"/>
            <?php wp_nonce_field( 'profile_picture', 'profile_picture_nonce'); ?>
            <h3>Project Images:</h3>
            <p>To add an image to your profile, select the image and it will be added when you save the form.</p>
            <p>
                <input type="file" name="my_image_upload"/>
                <?php wp_nonce_field( 'my_image_upload', 'my_image_upload_nonce' ); ?>
            </p>
            <p><b>Current Project Images</b></p>
            <p>To remove an image, click Delete and it will be removed when you save.</p>
            <?php
            //get acf gallery field
            $images = get_field('gallery',$pid);
            if( $images ):
                foreach( $images as $image ):
                    echo '<div style="float:left;margin-right:10px;">'; 
                    echo '<img src="'.$image['sizes']['thumbnail'].'" alt="'.$image['caption'].'"/><br/>';
                    echo '<input type="checkbox" name="delete[]" value="'.$image['ID'].'"/> Delete';
                    echo '</div>';
                endforeach;

            endif;  
            ?>

        </div>
        <br style="clear:both;"/>
        <p><input type="submit" name="submit" value="Update"/> (<a target="_blank" href="<?php echo get_the_permalink($pid);?>">View My Profile</a>)</p>
    </form>

</div>
<?php get_footer();

// Omit closing PHP tag to avoid "Headers already sent" issues.


What am I missing?

  • get_field() is an ACF-specific function, and your input tag is not hooked to ACF. You also don't have anything set up to check for posted data, parse it, and actually save it. So, first decide whether you want to use ACF to handle the extra fields. If so, use only their functionality. If not, then remove your call to get_field(), set up an actual form so you can post the data, add a condition so that if there is $_POST data you capture it and save to the database before displaying everything again, and use a non-ACF function to retrieve the data. – WebElaine Sep 23 '19 at 20:31
  • Without seeing the code that saves these input values it's impossible to answer this question. Keep in mind too that ACF and Avada dev support is off topic here – Tom J Nowell Sep 23 '19 at 21:06

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.