Validate width and height of image with CRED

You can retrieve that data through tmp_name. The first and second indexes of this array are width and height, respectively

function validate_image_width_height($field_data, $form_data){
  
list($fields,$errors)=$field_data;  

$image_info = $fields['wpcf-image-1']['value']['tmp_name'];
$image_width = $image_info[0];
$image_width = $image_info[1];

if ($image_width < 100){
     $errors['image-1'] = __('Wrong width', 'nbt');
}

var_dump($fields['wpcf-image-1']);
 
return array($fields,$errors);
}

add_filter('cred_form_validate','validate_image_width_height',10,2);

Use the Code Snippet button to enter php and html snippets.


Let us know if this snippet is not working for you:

This snippet doesn’t work
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments