Last active
March 10, 2016 15:29
-
-
Save thomasplevy/aac29bc2a619db5fa37c to your computer and use it in GitHub Desktop.
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
| <?php // don't include this line when copying | |
| /** | |
| * Add custom validation to the LifterLMS Registration Form | |
| * @param obj $errors instance of WP_Error | |
| * @return obj | |
| */ | |
| function my_lifterlms_registration_validation( $errors ) { | |
| // if the phone number field is not submitted or is empty | |
| if( ! isset( $_POST['phone'] ) || empty( $_POST['phone'] ) ) { | |
| // need to be sure $errors object is a WP_Error instance | |
| if ( ! is_wp_error( $errors ) ) { | |
| $errors = new WP_Error(); | |
| } | |
| // add your error | |
| // parameters are: | |
| // error code (not really needed or used but required) | |
| // error message | |
| // data to pass (again not really needed but could be useful for logging) | |
| $errors->add( 'phone-required', __( 'You must enter a phone number', 'mytextdomain' ), array() ); | |
| } | |
| return $errors; | |
| } | |
| add_filter( 'lifterlms_user_registration_errors', 'my_lifterlms_registration_validation', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment