Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function extra_user_profile_fields( $user ) { ?>
- <table class="form-table">
- <tr>
- <th><label for="location"><?php _e("Location:",'valentino'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
- <td>
- <input type="text" name="location" id="location" value="<?php echo esc_attr( get_the_author_meta( 'location', $user->ID ) ); ?>" class="regular-text" /><br />
- <span class="description"><?php _e("Please enter your location.",'valentino'); ?> </span>
- </td>
- </tr>
- <?php }
- add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
- add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
- add_filter('user_profile_update_errors', 'valentino_check_fields', 10, 3);
- function valentino_check_fields($errors, $update, $user) {
- // Use the $_POST variable to check required fields
- if( empty($_POST['location']) )
- // add an error message to the WP_Errors object
- $errors->add( 'location_required',__('Location is required, please add one before saving.') );
- // Add as many checks as you have required fields here
- if( empty( $errors->errors ) ){
- // Save your custom fields here if no errors are found
- // Just skip this if you don't need to do extra work.
- // Fields will save if no errors are found
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement