Saturday, 1 June 2013

User Edit Profile Page Upload Forms

User Edit Profile Page Upload Forms

I have this page im using for users to edit their profiles from the front end.
<?php

// Get user info
global $current_user, $wp_roles;
get_currentuserinfo();

// Load the registration file
require_once( ABSPATH . WPINC . '/registration.php' );
require_once( ABSPATH . 'wp-admin/includes' . '/template.php' ); // this is only for the selected() function

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

/* Update user information. */
 if ( !empty( $_POST['weburl'] ) )
    update_user_meta( $current_user->ID, 'weburl', esc_url( $_POST['weburl'] ) );
 if ( !empty( $_POST['primecity'] ) )
    update_user_meta( $current_user->ID, 'primecity', esc_attr( $_POST['primecity'] ) );
 if ( !empty( $_POST['primestate'] ) )
    update_user_meta($current_user->ID, 'primestate', esc_attr( $_POST['primestate'] ) );
if ( !empty( $_POST['phone'] ) )
    update_user_meta( $current_user->ID, 'phone', esc_attr( $_POST['phone'] ) );
if ( !empty( $_POST['description'] ) )
      update_user_meta( $current_user->ID, 'description', esc_attr( $_POST['description'] ) );
if ( !empty( $_POST['twitter'] ) )
      update_user_meta( $current_user->ID, 'twitter', esc_attr( $_POST['twitter'] ) );
if ( !empty( $_POST['pinterest'] ) )
      update_user_meta( $current_user->ID, 'pinterest', esc_attr( $_POST['pinterest'] ) );
if ( !empty( $_POST['instagram'] ) )
      update_user_meta( $current_user->ID, 'instagram', esc_attr( $_POST['instagram'] ) );
if ( !empty( $_POST['myspace'] ) )
      update_user_meta( $current_user->ID, 'myspace', esc_attr( $_POST['myspace'] ) );

if(!empty($_FILES))
{
  if(isset($_FILES['profileimage']))
  {
    //Process the profile image here
  }  
  if(isset($_FILES['banners']))
    foreach($_FILES['banners'] as $banner)
    {
      //Process each banner image here
    }
}

// Redirect so the page will show updated info.
    if ( !$error ) {
        echo '<META http-equiv="refresh" content="0;URL='.get_permalink().'">';
    }
  }

  if ( !is_user_logged_in() ) : ?>

 <div class="box error-box"> You must be logged in to edit your profile.</div>
 <?php else : if ( $error ) echo '<div class="box error-box">' . $error . '</div>'; ?>
 <div class="entry-content">
  <header class="entry-header">
   <h1 class="entry-title">Edit Your Profile</h1>
  </header>
 <a href="<?php bloginfo( 'url' ); ?>/gallery-submit">Submit Gallery Image</a>
   <hr />
<form method="post" id="edituser" class="user-forms" action="<?php the_permalink(); ?>" enctype="multipart/form-data">
     <!-- UPLOAD IMAGES AREA -->
    <label>
     <?php _e('Profile Image', 'frontendprofile'); ?>
   </label>
  <input type="image" name="profileimage" />
   <hr />
   <label>
   <?php _e('Rotating Banner Images', 'frontendprofile'); ?>
  </label>
  <input type="image" name="banners[]" />
  <input type="image" name="banners[]" />
  <input type="image" name="banners[]" />
   <hr />
   <!-- /UPLOAD IMAGES AREA -->
  <label for="primecity">
   <?php _e('Primary City', 'frontendprofile'); ?>
  </label>
    <input name="primecity" type="text" value="<?php the_author_meta( 'primecity', $current_user->id ); ?>" />
  

No comments:

Post a Comment