Skip Navigation

[Gelöst] Form restrict featured image to exact image dimensions

This support ticket is created vor 2 Jahren, 10 Monaten. 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.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von leilaG vor 2 Jahren, 10 Monaten.

Author
Artikel
#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

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: 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. versteckter Link

#2276411

Great! thanks for the workaround.