Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php function custom_user_profile_fields($user){
- $previous_value = '';
- if( is_object($user) && isset($user->ID) ) {
- $teamleader_id = get_user_meta( $user->ID, 'teamleader_id', true );
- }
- ?>
- <h3>Extra profile information</h3>
- <table class="form-table">
- <tr>
- <th><label for="teamleader_id">TeamLeader ID(required)</label></th>
- <td>
- <input type="number" class="regular-text" name="teamleader_id" value="<?php echo $teamleader_id; ?>" id="teamleader_id" required /><br />
- <span class="description">Type teamleader ID here</span>
- </td>
- </tr>
- </table><?php }
- add_action( 'show_user_profile', 'custom_user_profile_fields' );
- add_action( 'edit_user_profile', 'custom_user_profile_fields' );
- add_action( "user_new_form", "custom_user_profile_fields" );
- function save_custom_user_profile_fields($user_id){
- if(!current_user_can('manage_options'))
- return false;
- if( isset($_POST['teamleader_id']) && $_POST['teamleader_id']!='' && is_numeric($_POST['teamleader_id']) ) {
- update_user_meta( $user_id, 'teamleader_id', sanitize_text_field( $_POST['teamleader_id'] ) );
- } else {
- return false;
- }
- }
- add_action('user_register', 'save_custom_user_profile_fields');
- add_action( 'personal_options_update', 'save_custom_user_profile_fields' );
- add_action( 'edit_user_profile_update', 'save_custom_user_profile_fields' );
- function myplugin_check_fields( $errors ) {
- /*
- if ( $_POST['teamleader_id']!='' && is_numeric($_POST['teamleader_id']) ) {
- $errors->add( 'teamleadere_id_error', __( '<strong>ERROR</strong>: Invalid Teamleader ID.', 'my_textdomain' ) );
- }
- */
- $errors->add( 'empty_teamleader_id', __( '<strong>ERROR</strong>: Invalid Zip.', 'remmbravo' ) );
- return $errors;
- }
- add_filter( 'registration_errors', 'myplugin_check_fields', 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement