Ticket #34945: 34945.4.diff
File 34945.4.diff, 5.0 KB (added by , 8 years ago) |
---|
-
src/wp-includes/deprecated.php
3747 3747 * @return string The base URL. 3748 3748 */ 3749 3749 function _wp_upload_dir_baseurl() { 3750 _deprecated_function( __FUNCTION__, '4.5' ); 3750 3751 $upload_dir = wp_get_upload_dir(); 3751 3752 return $upload_dir['baseurl']; 3752 3753 } -
src/wp-includes/media.php
903 903 } 904 904 905 905 /** 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 */ 914 function _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 /** 906 935 * Get the image size as array from its meta data. 907 936 * 908 937 * Used for responsive images. … … 1025 1054 } 1026 1055 1027 1056 $upload_dir = wp_get_upload_dir(); 1028 $image_baseurl = trailingslashit( $upload_dir['baseurl'] ) . $dirname; 1057 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; 1029 1061 1030 1062 /* 1031 1063 * Images that have been edited in WordPress after being uploaded will -
src/wp-includes/post.php
5015 5015 if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true ) ) { 5016 5016 // Get upload directory. 5017 5017 if ( ( $uploads = wp_get_upload_dir() ) && false === $uploads['error'] ) { 5018 $image_baseurl = _ssl_image_baseurl( $uploads['baseurl'] ); 5018 5019 // Check that the upload base exists in the file location. 5019 5020 if ( 0 === strpos( $file, $uploads['basedir'] ) ) { 5020 5021 // Replace file location with url location. 5021 $url = str_replace( $uploads['basedir'], $uploads['baseurl'], $file);5022 $url = str_replace( $uploads['basedir'], $image_baseurl, $file ); 5022 5023 } elseif ( false !== strpos($file, 'wp-content/uploads') ) { 5023 5024 // Get the directory name relative to the basedir (back compat for pre-2.7 uploads) 5024 $url = trailingslashit( $ uploads['baseurl']. '/' . _wp_get_attachment_relative_path( $file ) ) . basename( $file );5025 $url = trailingslashit( $image_baseurl . '/' . _wp_get_attachment_relative_path( $file ) ) . basename( $file ); 5025 5026 } else { 5026 5027 // It's a newly-uploaded file, therefore $file is relative to the basedir. 5027 $url = $uploads['baseurl'] . "/$file";5028 $url = trailingslashit( $image_baseurl ) . $file; 5028 5029 } 5029 5030 } 5030 5031 } -
tests/phpunit/tests/media.php
1407 1407 $actual = wp_make_content_images_responsive( $unfiltered ); 1408 1408 1409 1409 $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; 1410 1461 } 1411 1462 }