Make WordPress Core

Ticket #34945: 34945.4.patch

File 34945.4.patch, 3.7 KB (added by azaozz, 9 years ago)
  • src/wp-includes/deprecated.php

     
    37473747 * @return string The base URL.
    37483748 */
    37493749function _wp_upload_dir_baseurl() {
     3750        _deprecated_function( __FUNCTION__, '4.5' );
    37503751        $upload_dir = wp_get_upload_dir();
    37513752        return $upload_dir['baseurl'];
    37523753}
  • src/wp-includes/media.php

     
    903903}
    904904
    905905/**
     906 * Sets the protocol, caches and returns the base URL of the uploads directory.
     907 *
     908 * @since 4.5.0
     909 * @access private
     910 *
     911 * @param string $baseurl The base URL of the uploads directory.
     912 * @return string The base URL, cached.
     913 */
     914function _ssl_image_baseurl( $baseurl ) {
     915        static $tested = array();
     916
     917        $blog_id = get_current_blog_id();
     918
     919        if ( empty( $tested[$blog_id] ) ) {
     920                /*
     921                 * If currently on SSL, prefer HTTPS URLs when we know they're supported by the domain
     922                 * (which is to say, when they share the domain name of the current SSL page).
     923                 */
     924                if ( is_ssl() && 'https' !== substr( $baseurl, 0, 5 ) && parse_url( $baseurl, PHP_URL_HOST ) === $_SERVER['HTTP_HOST'] ) {
     925                        $baseurl = set_url_scheme( $baseurl, 'https' );
     926                }
     927
     928                $tested[$blog_id] = $baseurl;
     929        }
     930
     931        return $tested[$blog_id];
     932}
     933
     934/**
    906935 * Get the image size as array from its meta data.
    907936 *
    908937 * Used for responsive images.
     
    10251054        }
    10261055
    10271056        $upload_dir = wp_get_upload_dir();
    1028         $image_baseurl = trailingslashit( $upload_dir['baseurl'] ) . $dirname;
    10291057
     1058        // Set URL schema when front-end is https.
     1059        $image_baseurl = _ssl_image_baseurl( $upload_dir['baseurl'] );
     1060        $image_baseurl = trailingslashit( $image_baseurl ) . $dirname;
     1061
    10301062        /*
    10311063         * Images that have been edited in WordPress after being uploaded will
    10321064         * contain a unique hash. Look for that hash and use it later to filter
  • tests/phpunit/tests/media.php

     
    14071407                $actual     = wp_make_content_images_responsive( $unfiltered );
    14081408
    14091409                $this->assertSame( $expected, $actual );
     1410}
     1411
     1412        /**
     1413         * @ticket 34945
     1414         * @ticket 33641
     1415         */
     1416        function test_wp_get_attachment_image_with_https_on() {
     1417                global $blog_id;
     1418               
     1419                // Save server data for cleanup
     1420                $is_ssl = is_ssl();
     1421                $current_blog_id = get_current_blog_id();
     1422
     1423                // Mock meta for the image.
     1424                $image_meta = array(
     1425                        'width' => 1200,
     1426                        'height' => 600,
     1427                        'file' => 'test.jpg',
     1428                        'sizes' => array(
     1429                                'thumbnail' => array(
     1430                                        'file' => 'test-150x150.jpg',
     1431                                        'width' => 150,
     1432                                        'height' => 150,
     1433                                ),
     1434                                'medium' => array(
     1435                                        'file' => 'test-300x150.jpg',
     1436                                        'width' => 300,
     1437                                        'height' => 150,
     1438                                ),
     1439                                'large' => array(
     1440                                        'file' => 'test-1024x512.jpg',
     1441                                        'width' => 1024,
     1442                                        'height' => 512,
     1443                                ),
     1444                        )
     1445                );
     1446
     1447                // Test using the large file size.
     1448                $size_array = array(1024, 512);
     1449                $image_url  = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_meta['sizes']['large']['file'];
     1450
     1451                $_SERVER['HTTPS'] = 'on';
     1452                $blog_id = 42; // Used to bust the cache in _ssl_image_baseurl()
     1453
     1454                $expected = 'https://example.org/wp-content/uploads/test-300x150.jpg 300w, https://example.org/wp-content/uploads/test-1024x512.jpg 1024w, https://example.org/wp-content/uploads/test.jpg 1200w';
     1455
     1456                $this->assertSame( $expected, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) );
     1457
     1458                // Cleanup
     1459                $_SERVER['HTTPS'] = $is_ssl;
     1460                $blog_id = $current_blog_id;
    14101461        }
    14111462}