Make WordPress Core

Opened 6 months ago

Closed 3 months ago

#61060 closed defect (bug) (invalid)

PHP Warning: Undefined array key 1 in image_constrain_size_for_editor()

Reported by: fullermetric's profile fullermetric Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.5
Component: Media Keywords: reporter-feedback
Focuses: Cc:

Description (last modified by sabernhardt)

Running PHP 8.1, WordPress 6.5.2, debug.log reports Undefined array key 1 in /.../wp-includes/media.php on line 71

function image_constrain_size_for_editor( $width, $height, $size = 'medium', $context = null ) {
	global $content_width;

	$_wp_additional_image_sizes = wp_get_additional_image_sizes();

	if ( ! $context ) {
		$context = is_admin() ? 'edit' : 'display';
	}

	if ( is_array( $size ) ) {
		$max_width  = $size[0];
		$max_height = $size[1];

Line 71 is where $max_height is set, but $size[1] is undefined.

Change History (6)

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


5 months ago

#2 @antpb
5 months ago

  • Keywords reporter-feedback added

Hi @fullermetric thank you for making this ticket! The media team did some investigation in a recent meeting and we're having trouble finding how a $size array can only have one value provided. In all of the core functions that lead up to the function the $size var is passed exactly how it is received so it seems likely there is a plugin or some functionality in your site that is only providing the width value.

Is it possible for you to provide a callstack that shows how this function is being called to produce the warning? Thank you!

#3 @fullermetric
5 months ago

Hello @antpb

This is a warning, so I'm not sure if there would be a stack involved. However, this is a cut of what surrounded the error in our debug.log

[23-Apr-2024 15:29:53 UTC] PHP Deprecated:  preg_split(): Passing null to parameter #2 ($subject) of type string is deprecated in /.../wp-includes/formatting.php on line 3506
[23-Apr-2024 15:30:27 UTC] PHP Warning:  Undefined array key 1 in /.../wp-includes/media.php on line 71
[23-Apr-2024 15:30:27 UTC] PHP Warning:  Undefined array key 1 in /.../wp-includes/media.php on line 71
[23-Apr-2024 15:30:27 UTC] PHP Warning:  Undefined array key 1 in /.../wp-includes/media.php on line 71
[23-Apr-2024 15:30:27 UTC] PHP Warning:  Undefined array key 1 in /.../wp-includes/media.php on line 71
[23-Apr-2024 15:30:27 UTC] PHP Warning:  Undefined array key 1 in /.../wp-includes/media.php on line 71
[23-Apr-2024 15:30:27 UTC] PHP Warning:  Undefined array key 1 in /.../wp-includes/media.php on line 71
[23-Apr-2024 15:30:28 UTC] PHP Warning:  Attempt to read property "post_title" on null in /.../wp-content/plugins/js_composer/include/helpers/helpers.php on line 60

https://stackoverflow.com/questions/6426758/php-log-stacktrace-for-warnings
If you can provide us with the php code to stacktrace on warnings and which file to add the code to then I can assist further.

Last edited 5 months ago by sabernhardt (previous) (diff)

#4 @sabernhardt
5 months ago

  • Description modified (diff)
  • Summary changed from PHP Warning: Undefined array key 1 in /chroot/home/ab2bb14c/fullerfasteners.com/html/wp-includes/media.php on line 71 to PHP Warning: Undefined array key 1 in image_constrain_size_for_editor()

This could fit better in the support forums.

The log has three different messages:

  1. I think the media.php issue is most likely in your custom theme, with how it adds featured images in category.php and/or another archive template. To test that, you could visit your blog's Category and Date archives and check the debug log after viewing each page to check if you have the same number of this warning in the log as the posts without a featured image. For example, the Fastener Blog Hans page might print the warning twice at the same time because it has two posts with empty space in the middle of
    <!-- post thumbnail --><!-- /post thumbnail -->.
  2. The "post_title" warning is related to WPBakery Page Builder, and it seems to come from Single Image elements that either do not define an image or have some problem with the chosen image. If you edit the Volkel brand product page in the back end, you might find eight of the nine Single Image elements say "Add image" (or if you view Classic Mode, you might see the [vc_single_image] shortcode). Check that each of them has the desired image, or remove the element.
  3. The preg_split() notice comes from passing null to convert_smilies() when it should only receive a string. See #58476.

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


3 months ago

#6 @antpb
3 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

As this seems more likely to be a custom theme issue and not Core side I am closing this to keep our backlog true. :)

Note: See TracTickets for help on using tickets.