Problem:
Set image dimension in the custom field to save space as it is uploaded to media
Solution:
With Types 3.3 release we added the various usability improvements for custom field inputs with main focus on image fields. This includes better drag-and-drop functionality, uploading multiple files at once, and more. But there is no native way to validate the image but I can show you the way using which you can achieve this.
So, to validate the image while uploading, you need to use the hook: wp_handle_upload_prefilter
For example:
function func_validate_image_size( $file ) { $size = $file['size']; $size = $size / 1024; $type = $file['type']; $is_image = strpos( $type, 'image' ) !== false; $limit = 250; $limit_output = '250kb'; if ( $is_image && $size > $limit ) { $file['error'] = 'Image files must be smaller than ' . $limit_output; }//end if return $file; }//end nelio_max_image_size() add_filter( 'wp_handle_upload_prefilter', 'func_validate_image_size' );
You can find the proposed solution in this case with the following reply:
https://toolset.com/forums/topic/set-image-dimension-in-the-custom-field-to-save-space-as-it-is-uploaded-to-media/#post-1242980
Relevant Documentation:
https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_handle_upload_prefilter
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.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Kolkata (GMT+05:30)
This topic contains 2 replies, has 2 voices.
Last updated by 5 years, 10 months ago.
Assisted by: Minesh.