WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 10 months ago

#40692 new defect (bug)

Filter default image size in gallery

Reported by: Catapult_Themes Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.8
Component: Gallery Keywords:
Focuses: ui Cc:
PR Number:

Description

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.

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.

Attachments (1)

40692.diff (605 bytes) - added by palmiak 2 years ago.

Download all attachments as: .zip

Change History (7)

@palmiak
2 years ago

#1 @palmiak
2 years ago

I've tested the solution proposed by Catapult_themes and created diff file.

#wcpl2017

#2 @chrisvanpatten
2 years ago

Looks like a duplicate of #35654, although this ticket has a patch and #35654 does not. Someone more well-versed in Trac gardening probably knows what to do in this case (move the patch and close this, or close the original?)

#3 @stephaneguigne
2 years ago

In the meantime, if you want a workaround this issue, you can select the correct image size in the dropdown when the template is generated in order to match your default gallery settings.

#4 @nicmare
2 years ago

please fix that. thanks.

#5 @cezariuszmarek
10 months ago

  • Type changed from enhancement to defect (bug)

In my opinion it's a bug. I expect the "size" default to work the same as the "columns" or "link" ones.

#6 @cezariuszmarek
10 months ago

#35654 was marked as a duplicate.

Note: See TracTickets for help on using tickets.