[wp-trac] [WordPress Trac] #61060: PHP Warning: Undefined array key 1 in image_constrain_size_for_editor() (was: PHP Warning: Undefined array key 1 in /chroot/home/ab2bb14c/fullerfasteners.com/html/wp-includes/media.php on line 71)

WordPress Trac noreply at wordpress.org
Thu May 2 09:42:29 UTC 2024


#61060: PHP Warning:  Undefined array key 1 in image_constrain_size_for_editor()
-------------------------------+------------------------------
 Reporter:  fullermetric       |       Owner:  (none)
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Media              |     Version:  6.5
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:
-------------------------------+------------------------------

Old description:

> Running PHP 8.1, WordPress 6.5.2, debug.log reports Undefined array key 1
> in /chroot/home/ab2bb14c/fullerfasteners.com/html/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.

New description:

 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.

--

Comment (by sabernhardt):

 This could fit better in the [https://wordpress.org/support/forums/
 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.

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


More information about the wp-trac mailing list