Resizing only featured images while uploading

You can simply set all unused image size attributes to 0 to stop WordPress generating them. Whilst this only applies for default image sizes, you can use filters to remove them. In general, WP stores all those sizes to generate images for in the global $_wp_additional_image_sizes. The following plugin uses a filter to remove sizes … Read more

Prevent image upload unless exact size

Haven’t tested it, but this should work: // check for file upload size // { if( !current_user_can( ‘administrator’) ) add_filter( ‘wp_handle_upload_prefilter’, ‘mdu_validate_image_size’ ); } add_filter(‘wp_handle_upload_prefilter’,’mdu_validate_image_size’); function mdu_validate_image_size( $file ) { if ( mime_content_type($file) == ‘application/zip’ ) { mdu_validate_zip_image_size($file); return $file; } $image = getimagesize($file[‘tmp_name’]); $minimum = array( ‘width’ => ‘800’, ‘height’ => ‘450’ ); $maximum … Read more

How to crop image from image src in a specific size

WordPress has a function solely designed for this purpose. the attachment_url_to_postid() allows you to retrieve an attachment’s ID from it’s URL, which then you can use to get the post’s ID later. If you want to do it by writing a MySQL query, i would however prefer to suggest searching the file’s name in meta_value … Read more

Displaying images with relative paths in the editor

I had a client ask for that and it took a little while to get it but its simple: function change_mce_path_options( $init ) { $init[‘relative_urls’] = true; $init[‘document_base_url’] = get_bloginfo(‘url’); return $init; } add_filter(‘tiny_mce_before_init’, ‘change_mce_path_options’);

hook into completed image upload filter

WordPress’ media handling strikes me as scattered and inconsistent. I say that only to say that I can’t promise this will work in all cases. However, I think I’d use the add_attachment hook from wp_insert_attachment. You will get a post ID, so you will have to … retrieve the image src with wp_get_attachment_imge_src, probably, retrieve … Read more

How to create thumbnails for PDF uploads?

If I’m not totally mistaken, the code you have given on your update won’t work, because the file/mime type pdf isn’t supported by the WP_image_editor class called by wp_get_image_editor(). Creating a thumbnail from a uploaded pdf file can be achieved though. Below code gives you a insight in a possibility how to do it, I … Read more