Skip to content

Instantly share code, notes, and snippets.

@kriskhoury
Last active June 15, 2021 06:26
Show Gist options
  • Save kriskhoury/ab9afda80657480f9261983eb91c9855 to your computer and use it in GitHub Desktop.
Save kriskhoury/ab9afda80657480f9261983eb91c9855 to your computer and use it in GitHub Desktop.
add_filter('acf/validate_value/name=validate_this_image', 'my_acf_validate_value', 10, 4);
function my_acf_validate_value( $valid, $value, $field, $input ){
// bail early if value is already invalid
if( !$valid ) {
return $valid;
}
// load image data
$data = wp_get_attachment_image_src( $value, 'full' );
$width = $data[1];
$height = $data[2];
if( $width < 960 ) {
$valid = 'Image must be at least 960px wide';
}
// return
return $valid;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment