Created
May 5, 2016 20:23
-
-
Save thomasplevy/af65ed3c84e5837451f6b299c7539306 to your computer and use it in GitHub Desktop.
This file contains 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 copy this line into your functions.php file! | |
/** | |
* Run custom validation against the field | |
* If filter function returns a truthy, validation will stop, fields will not be saved, | |
* and an error message will be displayed on screen | |
* | |
* This should return false or a string which will be used as the error message | |
* | |
* If false is returned, the field has "passed" validation (eg no errors) | |
* | |
* @param mixed $error false or error message string | |
* @param string $field_id field id or name | |
* @param obj $user Instace of WP_User | |
* @return mixed | |
*/ | |
function my_custom_field_validation( $error, $field_id, $user ) { | |
// for example, lets make sure the field is numeric | |
if ( ! is_numeric( $_POST[$field_id] ) ) { | |
$error = __( 'ERROR: The value of "My Custom Field" must be numeric!', 'my-text-doamin' ); | |
} | |
return $error; | |
} | |
add_filter( 'lifterlms_validate_custom_user_field_my_custom_field_id', 'my_custom_field_validation', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment