最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Updating User Profile information removes image

programmeradmin1浏览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?

发布评论

评论列表(0)

  1. 暂无评论