Hello Nigel
I notice that users of the website sometimes upload far too small images, as a result, the pages do not look good.
So I tried to set a minimum height and width for the featured image, so that an image that is too small is rejected.
As help I used the ticket below, I have adjusted the ID number in the code to the ID number of the form of my site, but it doesn't work in some way.
The Form ID number is: 349
The minimum width should be: 500 px x 300 px
Would you like to take a look and help me?
https://toolset.com/forums/topic/form-with-image-resolution-check/
The code I add to functions.php
function validate_featured_image_size( $field_data, $form_data ){
$form_id = array( 349 ); // add IDs of CRED forms
$target_width = 500; // Edit
$target_height = 300; // Edit
if ( in_array( $form_data['id'], $form_id ) ) {
// Split field data into field values and errors
list( $fields,$errors ) = $field_data;
$check = getimagesize( $fields['_featured_image']['value'] );
if ( $check !== false ) {
$width = $check[0];
$height = $check[1];
if ( $width != $target_width || $height != $target_height ) {
$errors['_featured_image'] = "Image wrong size";
}
}
$field_data = array($fields,$errors);
}
return $field_data;
}
add_action( 'cred_form_validate', 'validate_featured_image_size', 10, 2 );