Skip Navigation

[Resolved] Form restrict featured image to exact image dimensions

This support ticket is created 2 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by leilaG 2 years, 10 months ago.

Author
Posts
#2276101

Hi, do you have any example code to restrict the featured in image being submitted in a form to the exact image dimensions?
1920 by 962 pixels. Thanks

#2276153

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

You would need to disable using the WP Media Uploader in the form settings, and could then use the cred_form_validate hook to check and accept or reject the image based on its dimensions (https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate).

I'm not sure that is a very good workflow though: it involves uploading the image to the server when the form is submitted, running the validation test, and rejecting the form if the image doesn't match the requirements. Your users would have waited for the image to upload for nothing.

Why not register a custom image size with those dimensions? Then when the image is uploaded WordPress will automatically generate an image of that size (subject to the cropping and resizing settings you specify).

See https://developer.wordpress.org/reference/functions/add_image_size/

Also, there are lots of tutorials around this subject, e.g. hidden link

#2276411

Great! thanks for the workaround.