Posted By

m-pokrovskii on 05/13/10


Tagged

wordpress field Extra


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

themolitor
BrianCoyDesign
maxvee8
laurentzziu
diegotrap
srdjan


Adding Extra Fields to the Wordpress User Profile


 / Published in: PHP
 

  1. <?php
  2. add_action( 'show_user_profile', 'extra_user_profile_fields' );
  3. add_action( 'edit_user_profile', 'extra_user_profile_fields' );
  4.  
  5. function extra_user_profile_fields( $user ) { ?>
  6. <h3><?php _e("Extra profile information", "blank"); ?></h3>
  7.  
  8. <table class="form-table">
  9. <tr>
  10. <th><label for="address"><?php _e("Address"); ?></label></th>
  11. <td>
  12. <input type="text" name="address" id="address" value="<?php echo esc_attr( get_the_author_meta( 'address', $user->ID ) ); ?>" class="regular-text" /><br />
  13. <span class="description"><?php _e("Please enter your address."); ?></span>
  14. </td>
  15. </tr>
  16. <tr>
  17. <th><label for="city"><?php _e("City"); ?></label></th>
  18. <td>
  19. <input type="text" name="city" id="city" value="<?php echo esc_attr( get_the_author_meta( 'city', $user->ID ) ); ?>" class="regular-text" /><br />
  20. <span class="description"><?php _e("Please enter your city."); ?></span>
  21. </td>
  22. </tr>
  23. <tr>
  24. <th><label for="province"><?php _e("Province"); ?></label></th>
  25. <td>
  26. <input type="text" name="province" id="province" value="<?php echo esc_attr( get_the_author_meta( 'province', $user->ID ) ); ?>" class="regular-text" /><br />
  27. <span class="description"><?php _e("Please enter your province."); ?></span>
  28. </td>
  29. </tr>
  30. <tr>
  31. <th><label for="postalcode"><?php _e("Postal Code"); ?></label></th>
  32. <td>
  33. <input type="text" name="postalcode" id="postalcode" value="<?php echo esc_attr( get_the_author_meta( 'postalcode', $user->ID ) ); ?>" class="regular-text" /><br />
  34. <span class="description"><?php _e("Please enter your postal code."); ?></span>
  35. </td>
  36. </tr>
  37. </table>
  38. <?php }
  39.  
  40. add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
  41. add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
  42.  
  43. function save_extra_user_profile_fields( $user_id ) {
  44.  
  45. if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
  46.  
  47. update_usermeta( $user_id, 'address', $_POST['address'] );
  48. update_usermeta( $user_id, 'city', $_POST['city'] );
  49. update_usermeta( $user_id, 'province', $_POST['province'] );
  50. update_usermeta( $user_id, 'postalcode', $_POST['postalcode'] );
  51. }
  52. ?>

Report this snippet  

You need to login to post a comment.