[wp-trac] [WordPress Trac] #13372: Separate Image sizes for different post types

WordPress Trac noreply at wordpress.org
Sat Apr 18 02:30:35 UTC 2020


#13372: Separate Image sizes for different post types
--------------------------------------------+------------------------------
 Reporter:  brandondove                     |       Owner:  (none)
     Type:  enhancement                     |      Status:  reopened
 Priority:  normal                          |   Milestone:  Awaiting Review
Component:  Media                           |     Version:  4.6.1
 Severity:  normal                          |  Resolution:
 Keywords:  dev-feedback close 2nd-opinion  |     Focuses:
--------------------------------------------+------------------------------
Changes (by Howdy_McGee):

 * keywords:  needs-patch dev-feedback close 2nd-opinion => dev-feedback
     close 2nd-opinion


Comment:

 I think we could close this issue. From my understanding we could use the
 `intermediate_image_sizes` filter hook to manage image sizes per post
 type. In this hook we should either get the post ID or post type:

 {{{#!php
 <?php
 add_filter( 'intermediate_image_sizes', function( $image_sizes ) {

         // WordPress uses post_id and post_ID
         $request = array_change_key_case( $_REQUEST, CASE_LOWER );
         $type    = null;

         if( isset( $request['post_type'] ) ) {
                 $type = $request['post_type'];
         } else if( isset( $request['post_id'] ) ) {
                 $type = get_post_type( $request['post_id'] );
         } else if ( isset( $request['taxonomy'] ) ) {
                 $type = $request['taxonomy'];
         }

         switch( $type ) {

                 case 'post':
                         $image_sizes = array( 'thumbnail', 'medium',
 'large', 'full', 'blog_image' );
                         break;

         }

         return $image_sizes;

 } );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/13372#comment:23>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list