Make WordPress Core


Ignore:
Timestamp:
08/07/2024 07:41:14 PM (2 years ago)
Author:
hellofromTonya
Message:

Media: Check if content URL includes a hostname in wp_calculate_image_srcset().

This resolves an Undefined array key "host" PHP warning if WP_CONTENT_URL is set to a relative URL.

Follow-up to [58097].

Reviewed by hellofromTonya.
Merges [58773] to the 6.6 branch.

Props mattraines, narenin, pamprn, SergeyBiryukov.
Fixes #61690.

Location:
branches/6.6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.6

  • branches/6.6/tests/phpunit/tests/media.php

    r58143 r58862  
    18321832                        $this->assertSame( $expected_srcset, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) );
    18331833                }
     1834        }
     1835
     1836        /**
     1837         * @ticket 61690
     1838         * @requires function imagejpeg
     1839         */
     1840        public function test_wp_calculate_image_srcset_with_relative_content_url() {
     1841                $_SERVER['HTTPS'] = 'on';
     1842
     1843                add_filter(
     1844                        'upload_dir',
     1845                        static function ( $upload_dir ) {
     1846                                $upload_dir['baseurl'] = '/wp-content/uploads';
     1847                                return $upload_dir;
     1848                        }
     1849                );
     1850
     1851                $image_url  = wp_get_attachment_image_url( self::$large_id, 'medium' );
     1852                $image_meta = wp_get_attachment_metadata( self::$large_id );
     1853
     1854                $size_array = array( 300, 225 );
     1855
     1856                $srcset = wp_calculate_image_srcset( $size_array, $image_url, $image_meta );
     1857
     1858                $this->assertStringStartsWith( '/wp-content/uploads', $srcset );
    18341859        }
    18351860
Note: See TracChangeset for help on using the changeset viewer.