Skip to content

Instantly share code, notes, and snippets.

@xnau
Last active July 8, 2019 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xnau/7e24c23caf20443c6920320943e1853b to your computer and use it in GitHub Desktop.
Save xnau/7e24c23caf20443c6920320943e1853b to your computer and use it in GitHub Desktop.
<?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