Advertisement
Guest User

profile.php

a guest
May 17th, 2010
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.63 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Add more profile fields to the user
  5.  *
  6.  * Easy to add new fields to the user profile by just
  7.  * creating your new section below and adding a new
  8.  * update_usermeta line
  9.  *
  10.  * @since 3.0.0
  11.  * @uses show_user_profile & edit_user_profile WordPress functions
  12.  *
  13.  * @param int $user User Object
  14.  * @return bool True on successful update, false on failure.
  15.  *
  16.  */
  17. function cp_profile_fields($user) {
  18. ?>
  19.  
  20.  
  21.     <table class="form-table">
  22.  
  23.         <tr>
  24.             <th><label for="twitter"><?php _e('Twitter','cp')?></label></th>
  25.  
  26.             <td>
  27.                 <input type="text" name="twitter_id" id="twitter_id" value="<?php echo esc_attr(get_the_author_meta('twitter_id', $user->ID)); ?>" class="regular-text" size="35" /><br />
  28.                 <span class="description"><?php _e('Please enter your Twitter username.','cp')?></span>
  29.             </td>
  30.         </tr>
  31.  
  32.         <tr>
  33.             <th><label for="facebook"><?php _e('Facebook','cp')?></label></th>
  34.  
  35.             <td>
  36.                 <input type="text" name="facebook_id" id="facebook_id" value="<?php echo esc_attr(get_the_author_meta('facebook_id', $user->ID)); ?>" class="regular-text" /><br />
  37.                 <span class="description"><?php _e('Please enter your Facebook username.','cp')?></span>
  38.             </td>
  39.         </tr>
  40.  
  41.     </table>
  42.  
  43.  
  44.     <table class="form-table">
  45.  
  46.         <tr>
  47.             <th><label for="paypal"><?php _e('PayPal Email','cp')?></label></th>
  48.  
  49.             <td>
  50.                 <input type="text" name="paypal_email" id="paypal_email" value="<?php echo esc_attr(get_the_author_meta('paypal_email', $user->ID)); ?>" class="regular-text" /><br />
  51.                 <span class="description"><?php _e('Please enter your PayPal email address.','cp')?></span>
  52.             </td>
  53.         </tr>
  54.  
  55.     </table>
  56.  
  57. <?php
  58. }
  59.  
  60.  
  61. function cp_profile_fields_save($user_id) {
  62.     if (!current_user_can('edit_user', $user_id ))
  63.         return false;
  64.  
  65.     /* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */
  66.     update_usermeta( $user_id, 'twitter_id', $_POST['twitter_id'] );
  67.     update_usermeta( $user_id, 'facebook_id', $_POST['facebook_id'] );
  68.     update_usermeta( $user_id, 'paypal_email', $_POST['paypal_email'] );
  69. }
  70.  
  71.  
  72. // hook these new fields into the profile page with high priority
  73. add_action('show_user_profile', 'cp_profile_fields', 0);
  74. add_action('edit_user_profile', 'cp_profile_fields');
  75.  
  76. // save the updated profile field information
  77. add_action('personal_options_update', 'cp_profile_fields_save');
  78. add_action('edit_user_profile_update', 'cp_profile_fields_save');
  79.  
  80. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement