Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This is the code i am using for front end profile editing

How do i add avatar image upload option?

<?php
/*
Template Name: Update Profile
*/

$wpdb->hide_errors(); nocache_headers();

global $userdata; get_currentuserinfo();

if(!empty($_POST['action'])){

    require_once(ABSPATH . 'wp-admin/includes/user.php');
    require_once(ABSPATH . WPINC . '/registration.php');

    check_admin_referer('update-profile_' . $user_ID);

    $errors = edit_user($user_ID);

    if ( is_wp_error( $errors ) ) {
        foreach( $errors->get_error_messages() as $message )
            $errmsg = "$message";
    }

    if($errmsg == '')
    {
        do_action('personal_options_update',$user_ID);
        $d_url = $_POST['dashboard_url'];
        wp_redirect( get_option("siteurl").'?page_id='.$post->ID.'&updated=true' );
    }
    else{
        $errmsg = '<div class="box-red">' . $errmsg . '</div>';
        $errcolor = 'style="background-color:#FFEBE8;border:1px solid #CC0000;"';

    }
}

get_header(); 

get_currentuserinfo();
?>

<div id="primary">
            <div id="content" role="main">

<form name="profile" action="" method="post" enctype="multipart/form-data">
  <?php wp_nonce_field('update-profile_' . $user_ID) ?>
  <input type="hidden" name="from" value="profile" />
  <input type="hidden" name="action" value="update" />
  <input type="hidden" name="checkuser_id" value="<?php echo $user_ID ?>" />
  <input type="hidden" name="dashboard_url" value="<?php echo get_option("dashboard_url"); ?>" />
  <input type="hidden" name="user_id" id="user_id" value="<?php echo $user_id; ?>" />
  <table width="100%" cellspacing="0" cellpadding="0" border="0">
    <?php if ( isset($_GET['updated']) ):
$d_url = $_GET['d'];?>
    <tr>
      <td align="center" colspan="2"><span style="color: #FF0000; font-size: 11px;">Your profile changed successfully</span></td>
    </tr>
    <?php elseif($errmsg!=""): ?>
    <tr>
      <td align="center" colspan="2"><span style="color: #FF0000; font-size: 11px;"><?php echo $errmsg;?></span></td>
    </tr>
    <?php endif;?>
    <tr>
    <td colspan="2" align="center"><h2><span style="color: #C0C0C0; font-size: 32px;">Update profile</span></h2></td>
    </tr>
<hr>
    <tr>
      <td><span style="font-size:16px;"><span style="font-family: trebuchet ms,helvetica,sans-serif;"><span style="color: rgb(0, 0, 0);"><strong>First Name</strong></span></span></span></td>
      <td><input type="text" name="first_name" id="first_name" class="rounded" value="<?php echo $userdata->first_name ?>" style="width: 300px;" /></td>
    </tr>
    <tr>
      <td><span style="font-size:16px;"><span style="font-family: trebuchet ms,helvetica,sans-serif;"><span style="color: rgb(0, 0, 0);"><strong>Last Name</strong></span></span></span></td>
      <td><input type="text" name="last_name" class="rounded"   id="last_name" value="<?php echo $userdata->last_name ?>" style="width: 300px;" /></td>
    </tr>
    <tr>
      <td><span style="font-size:16px;"><span style="font-family: trebuchet ms,helvetica,sans-serif;"><span style="color: rgb(0, 0, 0);"><strong>Email</strong></span></span></span> <span style="color: #F00">*</span></td>
      <td><input type="text" name="email" class="rounded" id="email" value="<?php echo $userdata->user_email ?>" style="width: 300px;" /></td>
    </tr>
    <tr>
      <td><span style="font-size:16px;"><span style="font-family: trebuchet ms,helvetica,sans-serif;"><span style="color: rgb(0, 0, 0);"><strong>New Password</strong></span></span></span></td>
      <td><input type="password" name="pass1" class="rounded" id="pass1" value="" style="width: 300px;" /></td>
    </tr>
    <tr>
      <td><span style="font-size:16px;"><span style="font-family: trebuchet ms,helvetica,sans-serif;"><span style="color: rgb(0, 0, 0);"><strong>New Password Confirm </strong></span></span></span></td>
      <td><input type="password" name="pass2" class="rounded" id="pass2" value="" style="width: 300px;" /></td>
    </tr>
    <tr>
      <td align="right" colspan="2"><span style="color: #F00">*</span> <span style="padding-right:40px;">mandatory fields</span></td>
    </tr>

    <tr><td colspan="2"><h3><span style="color: #C0C0C0; font-size: 35px;">Extra profile information</span></h3></td></tr>
    <tr>
        <td><span style="font-size:16px;"><span style="font-family: trebuchet ms,helvetica,sans-serif;"><span style="color: rgb(0, 0, 0);"><strong>Facebook URL</strong></span></span></span></td>
        <td><input type="text" name="facebook" class="rounded"  id="facebook" value="<?php echo esc_attr( get_the_author_meta( 'facebook', $userdata->ID ) ); ?>" style="width: 300px;" /></td>
    </tr>
    <tr>
        <td><span style="font-size:16px;"><span style="font-family: trebuchet ms,helvetica,sans-serif;"><span style="color: rgb(0, 0, 0);"><strong>Twitter</strong></span></span></span></td>
        <td><input type="text" class="rounded" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $userdata->ID ) ); ?>" style="width: 300px;" /></td>
    </tr>
    <tr>
        <td><span style="font-size:16px;"><span style="font-family: trebuchet ms,helvetica,sans-serif;"><span style="color: rgb(0, 0, 0);"><strong>Date of birth</strong></span></span></span></td>
        <td><input type="text" name="dob" id="dob" class="rounded"  value="<?php echo esc_attr( get_the_author_meta( 'dob', $userdata->ID ) ); ?>" style="width: 300px;" /></td>
    </tr>
    <tr>
        <td><span style="font-size:16px;"><span style="font-family: trebuchet ms,helvetica,sans-serif;"><span style="color: rgb(0, 0, 0);"><strong>Phone</strong></span></span></span></td>
        <td><input type="text" name="phone"  class="rounded" id="phone" value="<?php echo esc_attr( get_the_author_meta( 'phone', $userdata->ID ) ); ?>" style="width: 300px;" /></td>
    </tr>
    <tr>
        <td><span style="font-size:16px;"><span style="font-family: trebuchet ms,helvetica,sans-serif;"><span style="color: rgb(0, 0, 0);"><strong>Adress</strong></span></span></span></td>
        <td><input type="text" name="address" id="address" class="rounded" value="<?php echo esc_attr( get_the_author_meta( 'address', $userdata->ID ) ); ?>" style="width: 300px;" /></td>
    </tr>
    <tr>
        <td><span style="font-size:16px;"><span style="font-family: trebuchet ms,helvetica,sans-serif;"><span style="color: rgb(0, 0, 0);"><strong>City</strong></span></span></span></td>
        <td><input type="text" name="city" id="city"  class="rounded" value="<?php echo esc_attr( get_the_author_meta( 'city', $userdata->ID ) ); ?>" style="width: 300px;" /></td>
    </tr>
    <tr>
        <td><span style="font-size:16px;"><span style="font-family: trebuchet ms,helvetica,sans-serif;"><span style="color: rgb(0, 0, 0);"><strong>Province</strong></span></span></span></td>
        <td><input type="text" name="province" id="province" class="rounded"  value="<?php echo esc_attr( get_the_author_meta( 'province', $userdata->ID ) ); ?>" style="width: 300px;" /></td>
    </tr>
    <tr>
        <td><span style="font-size:16px;"><span style="font-family: trebuchet ms,helvetica,sans-serif;"><span style="color: rgb(0, 0, 0);"><strong>Postal Code</strong></span></span></span></td>
        <td><input type="text" name="postalcode" id="postalcode" class="rounded"  value="<?php echo esc_attr( get_the_author_meta( 'postalcode', $userdata->ID ) ); ?>" style="width: 300px;" /></td>
    </tr>
    <tr>
      <td align="center" colspan="2"><input type="submit" value="Update" /></td>
    </tr>
  </table>
  <input type="hidden" name="action" value="update" />
</form>
            </div><!-- #content -->
        </div><!-- #container -->
</div></div>

}



<?php get_footer(); ?>
share|improve this question

1 Answer

I think you can edit and use this snippets.

link here.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.