dalbeck

Wordpress Edit Profile Page

Sep 28th, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.76 KB | None | 0 0
  1. <?php
  2.     /* Template Name: Edit Profile Page */
  3. ?>
  4. <?php get_header(); ?>
  5.  
  6. <?php
  7.  
  8. /* Get user info. */
  9. global $current_user, $wp_roles;
  10. get_currentuserinfo();
  11.  
  12. /* Load the registration file. */
  13. require_once( ABSPATH . WPINC . '/registration.php' );
  14.  
  15. /* If profile was saved, update profile. */
  16. if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'update-user' ) {
  17.  
  18.     /* Update user password. */
  19.     if ( !empty($_POST['pass1'] ) && !empty( $_POST['pass2'] ) ) {
  20.         if ( $_POST['pass1'] == $_POST['pass2'] )
  21.             wp_update_user( array( 'ID' => $current_user->id, 'user_pass' => esc_attr( $_POST['pass1'] ) ) );
  22.         else
  23.             $error = __('The passwords you entered do not match.  Your password was not updated.', 'profile');
  24.     }
  25.  
  26.     /* Update user information. */
  27.     if ( !empty( $_POST['url'] ) )
  28.         update_usermeta( $current_user->id, 'user_url', esc_url( $_POST['url'] ) );
  29.     if ( !empty( $_POST['email'] ) )
  30.         update_usermeta( $current_user->id, 'user_email', esc_attr( $_POST['email'] ) );
  31.     if ( !empty( $_POST['first-name'] ) )
  32.         update_usermeta( $current_user->id, 'first_name', esc_attr( $_POST['first-name'] ) );
  33.     if ( !empty( $_POST['last-name'] ) )
  34.         update_usermeta($current_user->id, 'last_name', esc_attr( $_POST['last-name'] ) );
  35.     if ( !empty( $_POST['description'] ) )
  36.         update_usermeta( $current_user->id, 'description', esc_attr( $_POST['description'] ) );
  37.     if ( !empty( $_POST['_line1'] ) )
  38.         update_usermeta( $current_user->id, '_line1', esc_attr( $_POST['_line1'] ) );
  39.  
  40.     /* Redirect so the page will show updated info. */
  41.  
  42.     if ( !$error ) { wp_redirect( get_permalink() .'?updated=true' ); exit; }
  43. }
  44.  
  45. ?>
  46.  
  47. <section id="title">
  48.  
  49.     <article>
  50.         <h2>Become A Member</h2>
  51.     </article>
  52.  
  53. </section><!--end of title-->
  54.  
  55. <section id="container">
  56.  
  57.     <article id="content">
  58.  
  59.         <aside id="left">
  60.  
  61.             <?php get_sidebar(); ?>
  62.  
  63.         </aside><!--end of left-->
  64.  
  65.         <aside id="right">
  66.  
  67.             <article>
  68.  
  69.                 <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  70.                         <div id="post-<?php the_ID(); ?>">
  71.                             <div class="entry-content entry">
  72.                                 <?php the_content(); ?>
  73.                                 <?php if ( !is_user_logged_in() ) : ?>
  74.                                         <p class="warning">
  75.                                             <?php _e('You must be logged in to edit your profile.', 'profile'); ?>
  76.                                         </p><!-- .warning -->
  77.                                 <?php else : ?>
  78.  
  79.                                     <?php if ( $error ) echo '<p class="error">' . $error . '</p>'; ?>
  80.                                     <form method="post" id="adduser" action="<?php the_permalink(); ?>">
  81.                                         <p class="form-username">
  82.                                             <label for="first-name"><?php _e('First Name', 'profile'); ?></label>
  83.                                             <input class="text-input" name="first-name" type="text" id="first-name" value="<?php the_author_meta( 'user_firstname', $current_user->id ); ?>" />
  84.                                         </p><!-- .form-username -->
  85.                                         <p class="form-username">
  86.                                             <label for="last-name"><?php _e('Last Name', 'profile'); ?></label>
  87.                                             <input class="text-input" name="last-name" type="text" id="last-name" value="<?php the_author_meta( 'user_lastname', $current_user->id ); ?>" />
  88.                                         </p><!-- .form-username -->
  89.                                         <p class="form-email">
  90.                                             <label for="email"><?php _e('E-mail *', 'profile'); ?></label>
  91.                                             <input class="text-input" name="email" type="text" id="email" value="<?php the_author_meta( 'user_email', $current_user->id ); ?>" />
  92.                                         </p><!-- .form-email -->
  93.                                         <p class="form-url">
  94.                                             <label for="url"><?php _e('Website', 'profile'); ?></label>
  95.                                             <input class="text-input" name="url" type="text" id="url" value="<?php the_author_meta( 'user_url', $current_user->id ); ?>" />
  96.                                         </p><!-- .form-url -->
  97.  
  98.                                         <p class="address-1">
  99.                                             <label for="address1"><?php _e('Address', 'profile'); ?></label>
  100.                                             <input class="text-input" name="line1" type="text" id="line1" value="<?php the_author_meta( '_line1', $current_user->id ); ?>" />
  101.                                         </p><!-- .form-url -->
  102.  
  103.                                         <p class="form-password">
  104.                                             <label for="pass1"><?php _e('Password *', 'profile'); ?> </label>
  105.                                             <input class="text-input" name="pass1" type="password" id="pass1" />
  106.                                         </p><!-- .form-password -->
  107.                                         <p class="form-password">
  108.                                             <label for="pass2"><?php _e('Repeat Password *', 'profile'); ?></label>
  109.                                             <input class="text-input" name="pass2" type="password" id="pass2" />
  110.                                         </p><!-- .form-password -->
  111.                                         <p class="form-textarea">
  112.                                             <label for="description"><?php _e('Biographical Information', 'profile') ?></label>
  113.                                             <textarea name="description" id="description" rows="3" cols="50"><?php the_author_meta( 'description', $current_user->id ); ?></textarea>
  114.                                         </p><!-- .form-textarea -->
  115.                                         <p class="form-submit">
  116.                                             <?php echo $referer; ?>
  117.                                             <input name="updateuser" type="submit" id="updateuser" class="submit button" value="<?php _e('Update', 'profile'); ?>" />
  118.                                             <?php wp_nonce_field( 'update-user' ) ?>
  119.                                             <input name="action" type="hidden" id="action" value="update-user" />
  120.                                         </p><!-- .form-submit -->
  121.                                     </form><!-- #adduser -->
  122.                                     <?php endif; ?>
  123.                                 </div><!-- .entry-content -->
  124.                             </div><!-- .hentry .post -->
  125.                             <?php endwhile; ?>
  126.                         <?php else: ?>
  127.                             <p class="no-data">
  128.                                 <?php _e('Sorry, no page matched your criteria.', 'profile'); ?>
  129.                             </p><!-- .no-data -->
  130.                         <?php endif; ?>
  131.  
  132.                 <?php if ( $_GET['updated'] == 'true' ) : ?> <p class="updated">Your profile has been updated</p> <?php endif; ?>
  133.  
  134.  
  135.             </article>
  136.  
  137.         </aside><!--end of right-->
  138.  
  139.     </article><!--end of content-->
  140.  
  141. </section><!--end of container-->
  142.  
  143. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment