Last active
January 30, 2020 09:23
-
-
Save greathmaster/bff496fbbdb8e34e4684b3d988a47699 to your computer and use it in GitHub Desktop.
Makes fields added to the profile required if the required => true is set.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Makes fields added to the profile required if the required => true is set. | |
| */ | |
| function pmprorh_make_profile_fields_required(&$errors, $update = null, &$user = null) | |
| { | |
| //admin can leave them blank if he wants | |
| if(current_user_can("manage_options")) | |
| return; | |
| $profile_fields = pmprorh_getProfileFields($user->ID); | |
| foreach($profile_fields as $field) | |
| { | |
| if(isset($field->required) && $field->required == true && empty($_REQUEST[$field->id]) ) | |
| { | |
| $error_msg = '<strong>ERROR</strong>: '; | |
| if(isset($field->label)) | |
| { | |
| $error_msg .= "The ".$field->label." field is required"; | |
| } | |
| else | |
| { | |
| $error_msg .= "Please fill all required fields"; | |
| } | |
| $errors->add('pmprorh_empty_profile_fields', $error_msg); | |
| } | |
| } | |
| } | |
| add_action( 'user_profile_update_errors', 'pmprorh_make_profile_fields_required' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment