• Resolved Howdy_McGee

    (@howdy_mcgee)


    This is kind of a complex and also niche request but here it goes.

    :: Background ::
    I like to keep my WordPress clean and only create image sizes for what I need. For posts types this is very simple, I use the filter intermediate_image_sizes like so:

    function alter_image_sizes( $image_sizes ){
    	$type = (isset($_REQUEST['post_id'])) ? get_post_type($_REQUEST['post_id']) : '';
    	$normal_sizes = array('thumbnail', 'medium', 'large', 'full');
    	$slider_image_sizes = array('slider_image');
    
    	if(!empty($type)){
    		if($type === 'cpt_slides')
    			$image_sizes = $slider_image_sizes;
    		else
    			$image_sizes = $normal_sizes;
    	}
    
    	return $image_sizes;
    }
    add_filter('intermediate_image_sizes', 'alter_image_sizes', 999 );

    What the above does is on the Slider Custom Post Type (cpt_slides) whenever a user uploads an image either by tinyMCE or Featured Image box, this function tells WordPress to only create 1 image size (in this case slider_image) so that in the Uploads folder it only has 2 images: The Original Image and the resized Slider Image instead of the Natural: Thumbnail, Medium, Large, and Full(original). It also tells everything that’s NOT a post type of cpt_slides to NOT create a size for Slider Image. Very nifty.

    :: The Problem ::
    The above works for Post Types but not for taxonomies as it stands right now with this plugin (or probably any taxonomy based media plugin). I’m currently looking through the plugin to see if there’s a way to tell the intermediate_image_sizes filter that we’re currently on a category / taxonomy. I believe it boils down to how the media uploader is actually working and if anything can be passed to it upon opening. Right now it looks like via $_POST / $_REQUEST I have the following array:

    Array
    (
        [name] => image.jpg
        [action] => upload-attachment
        [_wpnonce] => bce707cf68
    )

    Now I don’t have a ton of experience in changing or editing the built in media uploader but I was curious if you knew of a way to indicate the taxonomy when uploading an image from the extra taxonomy field (z image upload). This way I could use your plugin and not necessarily create a bunch of extra image sizes that I’ll never use.

    :: Testing Info ::
    If you’d like to test the top function it’s probably best to use the built in wp_debug_log and in the function itself error_log to see any information you need.

    I know that even if I find a solution, editing the plugin itself it not really a long term solution but if I do I’ll post back here and hope it gets included in a future update. Thanks!

    https://www.ads-software.com/plugins/categories-images/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Pass Taxonomy on Media Module Open’ is closed to new replies.