Last active
July 8, 2019 01:24
-
-
Save xnau/7e24c23caf20443c6920320943e1853b 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 | |
/** | |
* validates a field submission for a valid URL | |
* | |
* @param PDb_Validating_Field $field | |
* @return null | |
*/ | |
function xnau_check_valid_url( $field ) | |
{ | |
// first, check to see if it is the field we want to validate | |
// you will modify this to match the name of the field you want to validate | |
if ( $field->name === 'url' ) { | |
// now check if the value is a valid URL | |
// http://php.net/manual/en/function.filter-var.php | |
$valid = filter_var( $field->value, FILTER_VALIDATE_URL ); | |
if ( ! $valid ) { | |
$field->error_type = 'invalid url'; | |
} | |
} | |
} | |
add_action( 'pdb-before_validate_field', 'xnau_check_valid_url' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment