dragunoff

wpquestions.com, ID = 3810

Jan 28th, 2012
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.45 KB | None | 0 0
  1. /**
  2.  * Add additional custom fields to profile page
  3.  */
  4.  
  5. add_action ( 'show_user_profile', 'wpq_show_extra_profile_fields' );
  6. add_action ( 'edit_user_profile', 'wpq_show_extra_profile_fields' );
  7.  
  8. function wpq_show_extra_profile_fields ( $user ) {
  9. ?>
  10.  
  11.     <h3><?php _e( 'Extra Profile Info'); ?></h3>
  12.    
  13.     <table class="form-table">
  14.    
  15.         <?php // duplicate this chunk (changing the meta field) for more fields ?>
  16.         <tr>
  17.        
  18.             <th><label for="icl_admin_language"><?php _e( 'Admin Language' ); ?></label></th>
  19.            
  20.             <td>
  21.                 <?php $value = get_the_author_meta( 'icl_admin_language', $user->ID ); ?>
  22.                 <select name="icl_admin_language" id="icl_admin_language">
  23.                     <option value="en" <?php selected( $value, 'en' ); ?>>English</option>
  24.                     <option value="es" <?php selected( $value, 'es' ); ?>>Espanol</option>
  25.                     <option value="it" <?php selected( $value, 'it' ); ?>>Italiano</option>
  26.                 </select>
  27.             </td>
  28.        
  29.         </tr>
  30.         <?php // end of chunk ?>
  31.        
  32.     </table>
  33.  
  34. <?php
  35. }
  36.  
  37. /**
  38.  * Save data input from custom field on profile page
  39.  */
  40.  
  41. add_action ( 'personal_options_update', 'wpq_save_extra_profile_fields' );
  42. add_action ( 'edit_user_profile_update', 'wpq_save_extra_profile_fields' );
  43.  
  44. function wpq_save_extra_profile_fields( $user_id ) {
  45.  
  46.     if ( !current_user_can( 'edit_user', $user_id ) )
  47.         return false;      
  48.    
  49.     // copy this line for other fields
  50.     update_user_meta( $user_id, 'icl_admin_language', $_POST['icl_admin_language'] );
  51.    
  52. }
Advertisement
Add Comment
Please, Sign In to add comment