Advertisement
Guest User

add website URL field to RCP

a guest
May 23rd, 2014
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.99 KB | None | 0 0
  1. /**
  2.  * Adds the custom fields to the registration form and profile editor
  3.  *
  4.  */
  5. function pw_rcp_add_user_fields() {
  6.    
  7.     $website_url = get_user_meta( get_current_user_id(), 'rcp_website_url', true );
  8.  
  9.  
  10.     ?>
  11.     <p>
  12.         <label for="rcp_website_url"><?php _e( 'Your Website URL', 'rcp' ); ?></label>
  13.         <input name="rcp_website_url" id="rcp_website_url" type="text" value="<?php echo esc_attr( $website_url ); ?>"/>
  14.     </p>
  15.    
  16.     <?php
  17. }
  18. add_action( 'rcp_after_password_registration_field', 'pw_rcp_add_user_fields' );
  19. add_action( 'rcp_profile_editor_after', 'pw_rcp_add_user_fields' );
  20.  
  21. /**
  22.  * Adds the custom fields to the member edit screen
  23.  *
  24.  */
  25. function pw_rcp_add_member_edit_fields( $user_id = 0 ) {
  26.    
  27.     $website_url = get_user_meta( $user_id, 'rcp_website_url', true );
  28.  
  29.  
  30.     ?>
  31.     <tr valign="top">
  32.         <th scope="row" valign="top">
  33.             <label for="rcp_website_url"><?php _e( 'website_url', 'rcp' ); ?></label>
  34.         </th>
  35.         <td>
  36.             <input name="rcp_website_url" id="rcp_website_url" type="text" value="<?php echo esc_attr( $website_url ); ?>"/>
  37.             <p class="description"><?php _e( 'The member\'s website URL', 'rcp' ); ?></p>
  38.         </td>
  39.     </tr>
  40.    
  41.     <?php
  42. }
  43. add_action( 'rcp_edit_member_after', 'pw_rcp_add_member_edit_fields' );
  44.  
  45.  
  46.  
  47. /**
  48.  * Determines if there are problems with the registration data submitted
  49.  *
  50.  */
  51. function pw_rcp_validate_user_fields_on_register( $posted ) {
  52.  
  53.     if( empty( $posted['rcp_website_url'] ) ) {
  54.         rcp_errors()->add( 'invalid_website_url', __( 'Please enter your website URL', 'rcp' ), 'register' );
  55.     }
  56.  
  57. }
  58. add_action( 'rcp_form_errors', 'pw_rcp_validate_user_fields_on_register', 10 );
  59.  
  60.  
  61. /**
  62.  * Stores the information submitted during registration
  63.  *
  64.  */
  65. function pw_rcp_save_user_fields_on_register( $posted, $user_id ) {
  66.  
  67.     if( ! empty( $posted['rcp_website_url'] ) ) {
  68.         update_user_meta( $user_id, 'rcp_website_url', sanitize_text_field( $posted['rcp_website_url'] ) );
  69.     }
  70.  
  71. }
  72. add_action( 'rcp_form_processing', 'pw_rcp_save_user_fields_on_register', 10, 2 );
  73.  
  74.  
  75. /**
  76.  * Stores the information submitted profile update
  77.  *
  78.  */
  79. function pw_rcp_save_user_fields_on_profile_save( $user_id ) {
  80.  
  81.     if( ! empty( $_POST['rcp_website_url'] ) ) {
  82.         update_user_meta( $user_id, 'rcp_website_url', sanitize_text_field( $_POST['rcp_website_url'] ) );
  83.     }
  84.  
  85. }
  86. add_action( 'rcp_user_profile_updated', 'pw_rcp_save_user_fields_on_profile_save', 10 );
  87. add_action( 'rcp_edit_member', 'pw_rcp_save_user_fields_on_profile_save', 10 );
  88.  
  89.  
  90. // display the info in the members list
  91. function website_url_add_table_header_footer() {
  92.     ?>
  93.     <th class="rcp-website_url-col"><?php _e('Website URL', 'rcp'); ?></th>
  94.     <?php
  95. }
  96. add_action('rcp_members_page_table_header', 'website_url_add_table_header_footer');
  97. add_action('rcp_members_page_table_footer', 'website_url_add_table_header_footer');
  98.  
  99. function website_url_add_row($user_id) {
  100.     ?>
  101.     <td><?php echo get_user_meta($user_id, 'rcp_website_url', true); ?></td>
  102.     <?php
  103. }
  104. add_action('rcp_members_page_table_column', 'website_url_add_row');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement