Make WordPress Core

Ticket #34945: 34945.3.diff

File 34945.3.diff, 2.4 KB (added by joemcgill, 9 years ago)

Refresh of 34945.2.diff

  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index 6b0187a..7820526 100644
    function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attac 
    10281028        $image_baseurl = trailingslashit( $upload_dir['baseurl'] ) . $dirname;
    10291029
    10301030        /*
     1031         * If currently on SSL, prefer HTTPS URLs when we know they're supported by the domain
     1032         * (which is to say, when they share the domain name of the current SSL page).
     1033         */
     1034        if ( is_ssl() && 'https' !== substr( $image_baseurl, 0, 5 ) && parse_url( $image_baseurl, PHP_URL_HOST ) === $_SERVER['HTTP_HOST'] ) {
     1035                $image_baseurl = set_url_scheme( $image_baseurl, 'https' );
     1036        }
     1037
     1038        /*
    10311039         * Images that have been edited in WordPress after being uploaded will
    10321040         * contain a unique hash. Look for that hash and use it later to filter
    10331041         * out images that are leftovers from previous versions.
  • tests/phpunit/tests/media.php

    diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php
    index d5ae231..bdf3e2c 100644
    EOF; 
    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                // Save server data for cleanup
     1418                $is_ssl = is_ssl();
     1419
     1420                // Mock meta for the image.
     1421                $image_meta = array(
     1422                        'width' => 1200,
     1423                        'height' => 600,
     1424                        'file' => 'test.jpg',
     1425                        'sizes' => array(
     1426                                'thumbnail' => array(
     1427                                        'file' => 'test-150x150.jpg',
     1428                                        'width' => 150,
     1429                                        'height' => 150,
     1430                                ),
     1431                                'medium' => array(
     1432                                        'file' => 'test-300x150.jpg',
     1433                                        'width' => 300,
     1434                                        'height' => 150,
     1435                                ),
     1436                                'large' => array(
     1437                                        'file' => 'test-1024x512.jpg',
     1438                                        'width' => 1024,
     1439                                        'height' => 512,
     1440                                ),
     1441                        )
     1442                );
     1443
     1444                // Test using the large file size.
     1445                $size_array = array(1024, 512);
     1446                $image_url  = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_meta['sizes']['large']['file'];
     1447
     1448                $_SERVER['HTTPS'] = 'on';
     1449
     1450                $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';
     1451
     1452                $this->assertSame( $expected, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) );
     1453
     1454                // Cleanup
     1455                $_SERVER['HTTPS'] = $is_ssl;
    14101456        }
    14111457}