[wp-trac] [WordPress Trac] #40692: Filter default image size in gallery

WordPress Trac noreply at wordpress.org
Mon May 8 13:39:45 UTC 2017


#40692: Filter default image size in gallery
-----------------------------+-----------------------------
 Reporter:  Catapult_Themes  |      Owner:
     Type:  enhancement      |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  Gallery          |    Version:  trunk
 Severity:  normal           |   Keywords:
  Focuses:  ui               |
-----------------------------+-----------------------------
 Using the `media_view_settings` filter, I can specify default `link` and
 `column` settings for new galleries but the `size` parameter is not
 filterable. For example:

 {{{
 function me_filter_gallery_settings( $settings ) {
         // This will successfully set the default number of columns to 5
         $settings['galleryDefaults']['columns'] = 5;
         // This does nothing
         $settings['galleryDefaults']['size'] = 'large';
         return $settings;
 }
 add_filter( 'media_view_settings', 'me_filter_gallery_settings' );
 }}}

 I know that it’s possible to override these defaults when outputting the
 gallery via the `gallery_shortcode`. However, this may be confusing to the
 user who would expect to see the same value for the image size appear when
 the gallery is generated on the front end as they have seen in the admin.
 To clarify: at the moment, I can set a default size for gallery images to
 ‘medium’, for example, although in the Gallery Settings panel in the page
 editor, the size will still display as ‘Thumbnail’. Indeed, the user could
 change the value of the size field without actually affecting the image
 size on the front end.

 [[Image(https://catapultthemes.com/wp-content/uploads/2017/05/gallery-
 admin-default-size.jpeg)]]

 In wp-includes/media-template.php replace lines 775 - 779 with:

 {{{
 foreach ( $size_names as $size => $label ) : ?>
         <option value="<?php echo esc_attr( $size ); ?>" <#
                 if ( '<?php echo $size ?>' ==
 wp.media.galleryDefaults.size ) { #>selected="selected"<# }
                                         #>>
                 <?php echo esc_html( $label ); ?>
         </option>
 <?php endforeach; ?>
 }}}

 This will allow:

 {{{
 function me_filter_gallery_settings( $settings ) {
         $settings['galleryDefaults']['size'] = 'large';
         return $settings;
 }
 add_filter( 'media_view_settings', 'me_filter_gallery_settings' );
 }}}

 Thereby allowing plugin and theme developers to set a default value for
 the image size in galleries.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40692>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list