Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thomasplevy/aac29bc2a619db5fa37c to your computer and use it in GitHub Desktop.
Save thomasplevy/aac29bc2a619db5fa37c to your computer and use it in GitHub Desktop.
<?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