Advertisement
Guest User

Wordpress Front End User Profile

a guest
Oct 5th, 2017
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.49 KB | None | 0 0
  1. <?php
  2. /* Template Name: Agent Profile */
  3. /* Get user info. */
  4. global $current_user, $wp_roles;
  5. //get_currentuserinfo(); //deprecated since 3.1
  6.  
  7.  
  8. /* Load the registration file. */
  9. //require_once( ABSPATH . WPINC . '/registration.php' ); //deprecated since 3.1
  10.  
  11. $error = array();
  12. /* If profile was saved, update profile. */
  13. if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'update-user' ) {
  14.  
  15.  
  16. /* Update user password. */
  17. if ( !empty($_POST['pass1'] ) && !empty( $_POST['pass2'] ) ) {
  18. if ( $_POST['pass1'] == $_POST['pass2'] )
  19. wp_update_user( array( 'ID' => $current_user->ID, 'user_pass' => esc_attr( $_POST['pass1'] ) ) );
  20. else
  21. $error[] = __('The passwords you entered do not match. Your password was not updated.', 'profile');
  22. }
  23.  
  24. /* Update user information. */
  25. if ( !empty( $_POST['url'] ) )
  26. wp_update_user( array( 'ID' => $current_user->ID, 'user_url' => esc_url( $_POST['url'] ) ) );
  27. if ( !empty( $_POST['email'] ) ){
  28. if (!is_email(esc_attr( $_POST['email'] )))
  29. $error[] = __('The Email you entered is not valid. please try again.', 'profile');
  30. elseif(email_exists(esc_attr( $_POST['email'] )) != $current_user->id )
  31. $error[] = __('This email is already used by another user. try a different one.', 'profile');
  32. else{
  33. wp_update_user( array ('ID' => $current_user->ID, 'user_email' => esc_attr( $_POST['email'] )));
  34. }
  35. }
  36.  
  37. if ( !empty( $_POST['first-name'] ) )
  38. update_user_meta( $current_user->ID, 'first_name', esc_attr( $_POST['first-name'] ) );
  39. if ( !empty( $_POST['last-name'] ) )
  40. update_user_meta($current_user->ID, 'last_name', esc_attr( $_POST['last-name'] ) );
  41. if ( !empty( $_POST['description'] ) )
  42. update_user_meta( $current_user->ID, 'description', esc_attr( $_POST['description'] ) );
  43.  
  44.  
  45.  
  46. /* Redirect so the page will show updated info.*/
  47. /*I am not Author of this Code- i dont know why but it worked for me after changing below line to if ( count($error) == 0 ){ */
  48. if ( count($error) == 0 ) {
  49. //action hook for plugins and extra fields saving
  50. do_action('edit_user_profile_update', $current_user->ID);
  51. wp_redirect( get_permalink() );
  52. exit;
  53. }
  54. }
  55. get_header(); ?>
  56. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  57. <div id="post-<?php the_ID(); ?>">
  58. <div class="entry-content entry">
  59. <?php the_content(); ?>
  60. <?php if ( !is_user_logged_in() ) : ?>
  61. <p class="warning">
  62. <?php _e('You must be logged in to edit your profile.', 'profile'); ?>
  63. </p><!-- .warning -->
  64. <?php else : ?>
  65. <?php if ( count($error) > 0 ) echo '<p class="error">' . implode("<br />", $error) . '</p>'; ?>
  66. <form method="post" id="adduser" enctype="multipart/form-data" action="<?php the_permalink(); ?>">
  67.  
  68.  
  69.  
  70. <!-- NEW PROFILE LAYOUT -->
  71. <!-- MAIN CONTAINER -->
  72. <div class="psecmain">
  73.  
  74. <!-- FIRST SECTION -->
  75. <div class="psections">
  76.  
  77. <!-- THE HEADING -->
  78. <h2>General Details</h2>
  79. <hr>
  80. <!-- END THE HEADING -->
  81. <!-- THE FIELDS -->
  82. <div>
  83.  
  84. <!-- PROFILE PICTURE -->
  85. <div class="full-divsn"><h4>Upload Image</h4>
  86. <?php $image_attributes = wp_get_attachment_image_src( get_usermeta($user_id,'_thumbnail_id',true )); // returns an array
  87. echo '<img src="'.$image_attributes[0].'">'; ?>
  88.  
  89. <p><?php _e('Upload image that are best clicked for better appearance of your profile','framework'); ?></p>
  90. <div class="full-divsn mbottom2">
  91. <div class="col-md-8 col-sm-8 submit-image">
  92. <input type="file" name="agent-image">
  93. </div>
  94. </div>
  95.  
  96.  
  97. </div>
  98. <!-- END PROFILE PICTURE -->
  99.  
  100. <!-- AGENT NAME -->
  101. <div class="full-divsn"><h4>Name</h4>
  102. <div class="full-divsn">
  103. <div class="col-md-4 col-sm-4">
  104. <input type="text" name="first_name" id="first_name" value="<?php echo $userdata->first_name; ?>" class="form-control first_name" placeholder="<?php _e('First Name','framework'); ?>" required>
  105. </div>
  106. <div class="col-md-4 col-sm-4">
  107. <input type="text" name="last_name" id="last_name" class="form-control last_name" value="<?php echo $userdata->last_name; ?>" placeholder="<?php _e('Last Name','framework'); ?>" required>
  108. </div>
  109. </div></div>
  110. <!-- END AGENT NAME -->
  111.  
  112. <!-- COMPANY INFO -->
  113. <div class="full-divsn"><h4>Company</h4>
  114. <div class="full-divsn">
  115. <div class="col-md-4 col-sm-4">
  116. <input type="text" name="uagency" id="uagency" value="<?php echo $userdata->uagency; ?>" class="form-control uagency" placeholder="<?php _e('Agency','framework'); ?>" required>
  117. </div>
  118. </div>
  119. <div class="full-divsn">
  120. <div class="col-md-4 col-sm-4">
  121. <input type="text" name="utitle" id="utitle" value="<?php echo $userdata->utitle; ?>" class="form-control utitle" placeholder="<?php _e('Title','framework'); ?>" required>
  122. </div>
  123. </div></div>
  124. <!-- END COMPANY INFO -->
  125.  
  126. <!-- CONTACT INFO -->
  127. <div class="full-divsn"><h4>Contact</h4>
  128. <div class="full-divsn">
  129. <div class="col-md-4 col-sm-4">
  130. <input type="text" value="<?php the_author_meta( 'mobile-phone', $current_user->ID ); ?>" name="mobile-phone" id="mobile-phone" class="form-control mobile-phone" placeholder="<?php _e('Mobile Phone','framework'); ?>">
  131. </div>
  132. <div class="col-md-4 col-sm-4">
  133. <input type="text" value="<?php the_author_meta( 'work-phone', $current_user->ID ); ?>" name="work-phone" id="work-phone" class="form-control work-phone" placeholder="<?php _e('Work Phone','framework'); ?>" required>
  134. </div>
  135. </div>
  136. <div class="full-divsn">
  137. <div class="col-md-4 col-sm-4">
  138. <input type="text" name="ufax" id="ufax" value="<?php the_author_meta( 'ufax', $current_user->ID ); ?>" class="form-control ufax" placeholder="<?php _e('Fax','framework'); ?>">
  139. </div>
  140. <!-- Agent Email -->
  141. <div class="col-md-4 col-sm-4">
  142. <input type="email" id="email" value="<?php echo $userdata->user_email ?>" name="email" class="form-control email1" placeholder="<?php _e('Email','framework'); ?>" required>
  143. </div>
  144. <!-- End Agent Email -->
  145. </div></div>
  146. <!-- END CONTACT INFO -->
  147.  
  148. <!-- LOCATION INFO -->
  149. <div class="full-divsn"><h4>Company</h4>
  150. <div class="full-divsn">
  151. <div class="col-md-6 col-sm-6">
  152. <input type="text" name="uaddress" id="uaddress" value="<?php the_author_meta( 'uaddress', $current_user->ID ); ?>" class="form-control uaddress" placeholder="<?php _e('Address','framework'); ?>">
  153. </div>
  154. <div class="col-md-2 col-sm-2">
  155. <input type="text" name="uunit" id="uunit" value="<?php the_author_meta( 'uunit', $current_user->ID ); ?>" class="form-control uunit" placeholder="<?php _e('Unit','framework'); ?>">
  156. </div>
  157. </div>
  158. <div class="full-divsn">
  159. <!-- Agent City and State -->
  160. <div class="col-md-4 col-sm-4">
  161. <input type="text" value="<?php echo $userdata->ucity; ?>" name="ucity" id="ucity" class="form-control" placeholder="<?php _e('City','framework'); ?>" required>
  162. </div>
  163. <div class="col-md-4 col-sm-4">
  164. <input type="text" value="<?php echo $userdata->ustate; ?>" name="ustate" id="ustate" class="form-control" placeholder="<?php _e('State','framework'); ?>" required>
  165. </div>
  166. <!-- End Agent City and State -->
  167. </div></div>
  168. <!-- END LOCATION INFO -->
  169.  
  170. <!-- SOCIAL LINKS -->
  171. <div class="full-divsn"><h4>Social</h4>
  172. <div class="full-divsn">
  173. <!-- Agent Social Links -->
  174. <div class="col-md-3 col-sm-3">
  175. <input type="text" value="<?php echo esc_attr(get_the_author_meta('fb-link', $user_ID)); ?>" name="fb-link" id="fb-link" class="form-control" placeholder="<?php _e('Facebook','framework'); ?>">
  176. </div>
  177. <div class="col-md-3 col-sm-3">
  178. <input type="text" value="<?php echo esc_attr(get_the_author_meta('twt-link', $user_ID)); ?>" name="twt-link" id="twt-link" class="form-control" placeholder="<?php _e('Twitter','framework'); ?>">
  179. </div>
  180. <div class="col-md-3 col-sm-3">
  181. <input type="text" value="<?php echo esc_attr(get_the_author_meta('gp-link', $user_ID)); ?>" name="gp-link" id="gp-link" class="form-control" placeholder="<?php _e('Google Plus','framework'); ?>">
  182. </div>
  183. <div class="col-md-3 col-sm-3">
  184. <input type="text" value="<?php echo esc_attr(get_the_author_meta('msg-link', $user_ID)); ?>" name="msg-link" id="msg-link" class="form-control" placeholder="<?php _e('Message','framework'); ?>">
  185. </div>
  186. <!-- End Agent Social Links -->
  187. </div></div>
  188. <!-- END SOCIAL LINKS -->
  189.  
  190. </div>
  191. <!-- END THE FIELDS -->
  192. </div>
  193. <!-- END FIRST SECTION -->
  194.  
  195. <!-- SECOND SECTION -->
  196. <div class="psections">
  197.  
  198. <!-- THE HEADING -->
  199. <h2>About Yourself</h2>
  200. <hr>
  201. <!-- END THE HEADING -->
  202.  
  203. <!-- THE FIELDS -->
  204. <div>
  205. <!-- ABOUT BIO -->
  206. <div class="full-divsn"><h4>About Bio</h4>
  207. <div class="full-divsn mbottom2">
  208. <div class="col-md-8 col-sm-8">
  209. <textarea name="description" id="description" class="form-control margin-0" rows="5" cols="10" value="<?php the_author_meta( 'description', $current_user->ID ); ?>" placeholder="<?php _e('About Bio','framework'); ?>"><?php the_author_meta( 'description', $current_user->ID ); ?></textarea>
  210. </div>
  211. </div></div>
  212. <!-- END ABOUT BIO -->
  213. <!-- EXP AND SP -->
  214. <div class="full-divsn"><h4>Experience/Specialties</h4>
  215. <div class="full-divsn mbottom2">
  216. <div class="col-md-8 col-sm-8 submit-description">
  217. <textarea name="uexp" id="uexp" class="form-control margin-0" rows="5" cols="10" placeholder="<?php _e('Experience/Specialties','framework'); ?>" value="<?php the_author_meta( 'uexp', $current_user->ID ); ?>" ><?php the_author_meta( 'uexp', $current_user->ID ); ?></textarea>
  218. </div>
  219. </div></div>
  220. <!-- END EXP AND SP -->
  221.  
  222. <!-- EDUCATION -->
  223. <div class="full-divsn mbottom2"><h4>Education</h4>
  224. <div class="full-divsn">
  225. <div class="col-md-8 col-sm-8">
  226. <textarea name="ueduc" id="ueduc" class="form-control ueduc margin-0" rows="5" cols="10" value="<?php the_author_meta( 'ueduc', $current_user->ID ); ?>" placeholder="<?php _e('Education','framework'); ?>"><?php the_author_meta( 'ueduc', $current_user->ID ); ?></textarea>
  227. </div>
  228. </div></div>
  229. <!-- END EDUCATION -->
  230.  
  231.  
  232. </div>
  233. <!-- END THE FIELDS -->
  234.  
  235. </div>
  236. <!-- END SECOND SECTION -->
  237.  
  238. </div>
  239. <!-- END MAIN CONTAINER -->
  240.  
  241.  
  242.  
  243.  
  244.  
  245. <p class="form-submit">
  246. <?php echo $referer; ?>
  247. <input name="updateuser" type="submit" id="updateuser" class="submit button" value="<?php _e('Update', 'profile'); ?>" />
  248. <?php wp_nonce_field( 'update-user' ) ?>
  249. <input name="action" type="hidden" id="action" value="update-user" />
  250. </p><!-- .form-submit -->
  251. </form><!-- #adduser -->
  252. <?php endif; ?>
  253. </div><!-- .entry-content -->
  254. </div><!-- .hentry .post -->
  255. <?php endwhile; ?>
  256. <?php else: ?>
  257. <p class="no-data">
  258. <?php _e('Sorry, no page matched your criteria.', 'profile'); ?>
  259. </p><!-- .no-data -->
  260. <?php endif; ?>
  261. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement