[Resolved] Free Ad : Feature image doesn’t appear on translated version
This thread is resolved. Here is a description of the problem and solution.
Problem:
Validate featured image dimension or uploaded image dimension using CRED form
Solution:
With CRED form you can validate your image dimension using the CRED hook "cred_form_validate" or "cred_form_ajax_upload_validate" so that user needs to upload the perfect dimension image and if user uploads different dimension image it will throw the error.
When I posted a FREE AD on the Classifieds Reference Site (running WPML), the posting in English was perfect.
I uploaded a feature image and a couple of "gallery images".
However, when I checked the Spanish version, the gallery images were there but the feature image was blank.
BTW is there anyway to force users to upload images of certain dimensions and/or crop uploaded images to a preset size?
When images are all different heights and widths the layout doesn't look so good.
Hello. Thank you for contacting the Toolset support.
Well - with CRED form you can validate your image dimension using the CRED hook cred_form_validate so that user needs to upload the perfect dimension image and if user uploads different dimension image it will throw the error.
For example - something like this code - you can adjust the code as per your requirement:
function validate_featured_image_size( $field_data, $form_data ){
$form_id = array( 9999); // add IDs of CRED forms
$validate_width = 300; // Edit
$validate_height = 200; // 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 != $validate_width || $height != $validate_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 );
Where:
- Replace 9999 with your original CRED form ID