add_filter('cred_form_validate_488', 'cred_image_resolution_validation',10,2);
function cred_image_resolution_validation($field_data, $form_data)
{
// Field data are field values and errors
list($fields,$errors)=$field_data;
//Run the rest of code for this CRED ONLY and IF the file is upload type and size are set.
if (( 99 == $form_data['id']) && (isset($_FILES['wpcf-featured-image']['tmp_name']))) {
$check = getimagesize($_FILES["wpcf-featured-image"]["tmp_name"]);
if($check !== false) {
$width = $check[0];
$height = $check[1];
if($width !== 300 && $height !== 200) {
$errors['the-file-field'] = 'Sorry, image has wrong dimensions.';
}
} else {
$errors['the-file-field'] = 'Sorry this is not a valid image file.';
}
}
return array($fields,$errors);
}
This validation only happens when you submit the form, not when the user chooses an image and it is uploaded to the server.
Is that what you were expecting?
If you added the code and users can submit the form with incorrect images sizes then I had better take a look, as it worked ok on my local test site.
I will mark your next reply as private so that I can get log-in credentials from you—you may want to create a temporary admin user for me to use that you can later delete. And be sure to have a current backup of your site, even though I don't intend to make any changes other than to temporarily add a backup plugin to take a snapshot of the site.
Can you also confirm which form and where to find it?
1. Is there anyway to validate the image when the image is selected rather than waiting to validate it until the form is submitted?
2. Do the dimensions specified in the link above affect whether the image can be portrait or landscape? I don't want any restriction on the orientation of the image, but do want to be sure the images are at least a minimum size so they don't appear pixelated. Can you please elaborate on this?