WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#36531 closed defect (bug) (fixed)

Default image size medium_large is not generated

Reported by: Indent Owned by: joemcgill
Milestone: 4.5.3 Priority: normal
Severity: normal Version: 4.4
Component: Media Keywords: has-patch fixed-major
Focuses: administration Cc:

Description

With default image sizes in the media settings page, five sizes of an uploaded image is generated; 150px, 300px, 768px, 1024px and 1200px, using Twenty Sixteen. Changing one of the image sizes will cause WordPress to stop generating the medium_large 768px image.

I suspect the medium_large size image is somehow set to zero in the database when changing media settings in WP admin, thus not generated.

Tested with WordPress 4.4.2 and 4.5, server PHP 5.6.10 / MySQL 5.5.42, no plugins in the plugins folder, Twenty Sixteen, Twenty Fifteen and other themes as well. Language set to Norwegian in WP admin. Tested locally and online with Chrome version 49.0.2623.112 (64-bit) and Firefox 45.0.2.

Attachments (1)

36531.diff (1.6 KB) - added by joemcgill 3 years ago.

Download all attachments as: .zip

Change History (16)

#1 @adamsilverstein
3 years ago

  • Version changed from 4.5 to 4.4

@Indent Thanks for the bug report.

I tested and was able to reproduce the issue as you described it: I no longer see the 768x image size after making a change in the settings. The may be related to some of the responsive image changes we have been working on, hopefully @joemcgill can take a look and shed some light.

Before changing any settings:
http://cl.ly/0O2h3K3m1a19/04_2016-04-14_15-54-42.jpg

Changing medium size media setting to 400x300 and uploading the same file results in one less file being created: the 768x size is missing:

http://cl.ly/2O23360l0m02/04_2016-04-14_15-56-45.jpg

#2 @joemcgill
3 years ago

  • Owner set to joemcgill
  • Status changed from new to reviewing

Thanks for the report @Indent and @adamsilverstein for confirming. This bug has probably existed since the new size was introduced in r35479.

@joemcgill
3 years ago

#3 follow-up: @joemcgill
3 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 4.6
  • Status changed from reviewing to accepted

Looks like any time the media options are saved (wp-admin/options-media.php) the values for medium_large_size_h and medium_large_size_w are being set to null because no value for that option exists in the $_POST request. The problem is in this section of options.php:

$value = null;
if ( isset( $_POST[ $option ] ) ) {
	$value = $_POST[ $option ];
	if ( ! is_array( $value ) )
		$value = trim( $value );
	$value = wp_unslash( $value );
}
update_option( $option, $value );

36531.diff removes medium_large_size_h and medium_large_size_w from the whitelist of media options that can be updated so this won't happen going forward, but we would still need to run a DB routine to reset this option if it has been set to null.

#4 @joemcgill
3 years ago

#36700 was marked as a duplicate.

This ticket was mentioned in Slack in #core-images by joemcgill. View the logs.


3 years ago

This ticket was mentioned in Slack in #core by joemcgill. View the logs.


3 years ago

#7 in reply to: ↑ 3 @ocean90
3 years ago

Replying to joemcgill:

Looks like any time the media options are saved (wp-admin/options-media.php) the values for medium_large_size_h and medium_large_size_w are being set to null because no value for that option exists in the $_POST request.

That's right, but it gets stored as 0 because of sanitize_option() which does $value = absint( $value ); for both options. So, for an upgrade routine we can't detect if the change was intentionally or not.

This ticket was mentioned in Slack in #core-images by joemcgill. View the logs.


3 years ago

#9 @joemcgill
3 years ago

  • Milestone changed from 4.6 to 4.5.3

Thanks @ocean90. I'd like to get the patch in 4.5.3, if possible, so we at least stop this issue from spreading further. We can circle back and decide whether we do an upgrade routine in a future release. If so, we should only target installs that have medium_large_size_h and medium_large_size_w set to 0.

#10 @mikeschroder
3 years ago

This looks good.

#11 @joemcgill
3 years ago

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

In 37435:

Media: Remove medium_large size from $whitelist_options['media'] in options.php.

The medium_large_size_w and medium_large_size_h options were added to the
$whitelist_optionsmedia? in options.php in [35479], which causes both options
to be set to 0 when the media settings are changed. When this occurs, the
medium_large image size will no longer be created when an image is uploaded.

Since these options aren't meant to be updated via the settings UI, they can be
safely removed from the whitelist.

Fixes #36531.

#12 @swissspidy
3 years ago

  • Keywords fixed-major added
  • Resolution fixed deleted
  • Status changed from closed to reopened

This ticket was mentioned in Slack in #core by adamsilverstein. View the logs.


3 years ago

#14 @ocean90
3 years ago

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

In 37457:

Media: Remove medium_large size from $whitelist_options['media'] in options.php.

The medium_large_size_w and medium_large_size_h options were added to the
$whitelist_options['media'] in options.php in [35479], which causes both options
to be set to 0 when the media settings are changed. When this occurs, the
medium_large image size will no longer be created when an image is uploaded.

Since these options aren't meant to be updated via the settings UI, they can be
safely removed from the whitelist.

Merge of [37435] to the 4.5 branch.

Props joemcgill.
Fixes #36531.

#15 @drrobotnik
3 years ago

I've encountered this issue in a slightly different scenario. The 36531.diff fixes it, but I figured I'd share in case it's useful.

<?php
add_image_size('large-xl', 1600,1600, false);

I'm generating additional image sizes. The images are getting created on upload, but their meta is not being added to the attachment meta, only the default sizes. Perhaps it's related because i'm not cropping the image?

http://caava-clients.s3-us-west-1.amazonaws.com/Screen%20Shot%202016-05-19%20at%204.35.03%20PM.png

You can see all image sizes are being generated.

http://caava-clients.s3-us-west-1.amazonaws.com/Screen%20Shot%202016-05-19%20at%204.34.47%20PM.png

But the sizes meta data is not.

Again, applying the patch fixes the issue.

Note: See TracTickets for help on using tickets.