Advertisement
Guest User

Untitled

a guest
May 31st, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. <?php function custom_user_profile_fields($user){
  2. $previous_value = '';
  3. if( is_object($user) && isset($user->ID) ) {
  4. $teamleader_id = get_user_meta( $user->ID, 'teamleader_id', true );
  5. }
  6. ?>
  7. <h3>Extra profile information</h3>
  8. <table class="form-table">
  9. <tr>
  10. <th><label for="teamleader_id">TeamLeader ID(required)</label></th>
  11. <td>
  12. <input type="number" class="regular-text" name="teamleader_id" value="<?php echo $teamleader_id; ?>" id="teamleader_id" required /><br />
  13. <span class="description">Type teamleader ID here</span>
  14. </td>
  15. </tr>
  16. </table><?php }
  17. add_action( 'show_user_profile', 'custom_user_profile_fields' );
  18. add_action( 'edit_user_profile', 'custom_user_profile_fields' );
  19. add_action( "user_new_form", "custom_user_profile_fields" );
  20. function save_custom_user_profile_fields($user_id){
  21.  
  22. if(!current_user_can('manage_options'))
  23. return false;
  24.  
  25. if( isset($_POST['teamleader_id']) && $_POST['teamleader_id']!='' && is_numeric($_POST['teamleader_id']) ) {
  26. update_user_meta( $user_id, 'teamleader_id', sanitize_text_field( $_POST['teamleader_id'] ) );
  27. } else {
  28. return false;
  29. }
  30. }
  31. add_action('user_register', 'save_custom_user_profile_fields');
  32. add_action( 'personal_options_update', 'save_custom_user_profile_fields' );
  33. add_action( 'edit_user_profile_update', 'save_custom_user_profile_fields' );
  34. function myplugin_check_fields( $errors ) {
  35. /*
  36. if ( $_POST['teamleader_id']!='' && is_numeric($_POST['teamleader_id']) ) {
  37. $errors->add( 'teamleadere_id_error', __( '<strong>ERROR</strong>: Invalid Teamleader ID.', 'my_textdomain' ) );
  38. }
  39. */
  40. $errors->add( 'empty_teamleader_id', __( '<strong>ERROR</strong>: Invalid Zip.', 'remmbravo' ) );
  41. return $errors;
  42. }
  43. add_filter( 'registration_errors', 'myplugin_check_fields', 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement