I want to set minimum image dimensions for specific input field with id= "job_logo"
in a submission form on the front end
According to this answer
How to Require a Minimum Image Dimension for Uploading?
Following code sets the limit for all the image uploads
add_filter('wp_handle_upload_prefilter','tc_handle_upload_prefilter');
function tc_handle_upload_prefilter($file)
{
$img=getimagesize($file['tmp_name']);
$minimum = array('width' => '640', 'height' => '480');
$width= $img[0];
$height =$img[1];
if ($width < $minimum['width'] )
return array("error"=>"Image dimensions are too small. Minimum width is {$minimum['width']}px. Uploaded image width is $width px");
elseif ($height < $minimum['height'])
return array("error"=>"Image dimensions are too small. Minimum height is {$minimum['height']}px. Uploaded image height is $height px");
else
return $file;
}
Is there a way i can do this for one specific field with id=”job_logo” i.e
Following is the class of wp job manager used for submission form
https://github.com/Automattic/WP-Job-Manager/blob/c838d6ee3a3d0fd224d666bfee55f58517e10cf6/includes/forms/class-wp-job-manager-form-submit-job.php#L206
this is the code i have used to add the upload image field
add_filter( 'submit_job_form_fields', 'my_custom_tax' );
function my_custom_tax( $fields ) {
$fields['job']['job_logo'] = array(
'label' => __( 'Logo', 'wp-job-manager' ),
'type' => 'file',
'required' => false,
'placeholder' => '',
'priority' => 1.15,
'ajax' => true,
'multiple' => false,
'allowed_mime_types' => array(
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'png' => 'image/png'
)
);
return $fields;
}
Following is the html output for upload logo image field
<input type="file" class="input-text wp-job-manager-file-upload" data-file_types="jpg|jpeg|png" name="job_logo" id="job_logo" placeholder="">