WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 8 months ago

#22911 closed defect (bug) (invalid)

new media dialog doesn't list custom image sizes

Reported by: wdfee Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Media Keywords:
Focuses: Cc:

Description

When inserting an image into a post, the custom image sizes set by the theme are not listed and cannot be inserted. The theme uses set_post_thumbnail_size(...) and add_image_size(...).

Checked: The new uploader still generates the sizes, they are only not listed.

Change History (7)

comment:1 @nacin2 years ago

This is not a regression, 3.4 worked the same way. If you want custom sizes to appear in the media dialog, a plugin should use the image_size_names_choose filter.

comment:2 @wdfee2 years ago

Hi nacin, unfortunately I didn't got it working. I tried this in the theme's functions.php:

  1. first trial
    add_filter('image_size_names_choose', 'my_image_sizes');
    function my_image_sizes($sizes) {
            $addsizes = array(
                    "my-size" => __( "My Size")
                    );
            $newsizes = array_merge($sizes, $addsizes);
            return $newsizes;
    }
    
  1. second trial
    add_filter('image_size_names_choose', 'my_image_sizes', 11, 1);
    function my_image_sizes($sizes) {
    	$new_sizes = array();
    	$added_sizes = get_intermediate_image_sizes();
    	foreach( $added_sizes as $key => $value) {
    		$new_sizes[$value] = $value;
    	}
    	$new_sizes = array_merge( $new_sizes, $sizes );
    	return $new_sizes;
    }
    

Also tried a print_r(get_intermediate_image_sizes()); in the themes header, it's giving nothing back.

comment:3 @wdfee2 years ago

  • Resolution set to fixed
  • Status changed from new to closed

stop! got it working now. There have been a mistake in my code, it's easiest...

add_filter('image_size_names_choose', 'my_image_sizes', 11, 1);
function my_image_sizes($sizes) { 
	$new_sizes = array(  
		'my-size' => __( "My Size")  
	);  
	return array_merge( $sizes, $new_sizes );  
} 


comment:4 @markoheijnen2 years ago

  • Milestone Awaiting Review deleted
  • Resolution changed from fixed to invalid
  • Version 3.5 deleted

comment:5 @SergeyBiryukov2 years ago

#22955 was marked as a duplicate.

comment:7 @SergeyBiryukov8 months ago

#29393 was marked as a duplicate.

Note: See TracTickets for help on using tickets.