Ticket #34945: 34945.6.diff
File 34945.6.diff, 6.9 KB (added by , 9 years ago) |
---|
-
src/wp-includes/deprecated.php
diff --git src/wp-includes/deprecated.php src/wp-includes/deprecated.php index 5d871be..6954ebd 100644
function popuplinks( $text ) { 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
diff --git src/wp-includes/media.php src/wp-includes/media.php index 6b0187a..ac56119 100644
function get_image_tag( $id, $alt, $title, $align, $size = 'medium' ) { 351 351 */ 352 352 $class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size ); 353 353 354 $site_url = get_option( 'siteurl' ); 355 if ( 'https' === substr( $img_src, 0, 5 ) && 'http' === parse_url( $site_url, PHP_URL_SCHEME ) && parse_url( $img_src, PHP_URL_HOST ) === parse_url( $site_url, PHP_URL_HOST ) ) { 356 $img_src = set_url_scheme( $img_src, 'http' ); 357 } 358 354 359 $html = '<img src="' . esc_attr($img_src) . '" alt="' . esc_attr($alt) . '" ' . $title . $hwstring . 'class="' . $class . '" />'; 355 360 356 361 /** … … function _wp_get_attachment_relative_path( $file ) { 903 908 } 904 909 905 910 /** 911 * Sets the protocol, caches and returns the base URL of the uploads directory. 912 * 913 * @since 4.5.0 914 * @access private 915 * 916 * @param string $baseurl The base URL of the uploads directory. 917 * @return string The base URL, cached. 918 */ 919 function _ssl_image_baseurl( $baseurl ) { 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 return $baseurl; 929 } 930 931 /** 906 932 * Get the image size as array from its meta data. 907 933 * 908 934 * Used for responsive images. … … function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attac 1025 1051 } 1026 1052 1027 1053 $upload_dir = wp_get_upload_dir(); 1028 $image_baseurl = trailingslashit( $upload_dir['baseurl'] ) . $dirname; 1054 1055 // Set URL schema when front-end is https. 1056 $image_baseurl = _ssl_image_baseurl( $upload_dir['baseurl'] ); 1057 $image_baseurl = trailingslashit( $image_baseurl ) . $dirname; 1029 1058 1030 1059 /* 1031 1060 * Images that have been edited in WordPress after being uploaded will … … function wp_prepare_attachment_for_js( $attachment ) { 2998 3027 2999 3028 $attachment_url = wp_get_attachment_url( $attachment->ID ); 3000 3029 3030 $site_url = get_option( 'siteurl' ); 3031 3032 if ( 'https' === substr( $attachment_url, 0, 5 ) && 'http' === parse_url( $site_url, PHP_URL_SCHEME ) && parse_url( $attachment_url, PHP_URL_HOST ) === parse_url( $site_url, PHP_URL_HOST ) ) { 3033 $attachment_url = set_url_scheme( $attachment_url, 'http' ); 3034 } 3035 3001 3036 $response = array( 3002 3037 'id' => $attachment->ID, 3003 3038 'title' => $attachment->post_title, -
src/wp-includes/post.php
diff --git src/wp-includes/post.php src/wp-includes/post.php index d5f4f0e..5a94321 100644
function wp_get_attachment_url( $post_id = 0 ) { 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
diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php index d5ae231..1a6c270 100644
EOF; 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 } -
tests/phpunit/tests/post/attachments.php
diff --git tests/phpunit/tests/post/attachments.php tests/phpunit/tests/post/attachments.php index 3df4ce4..7dcf9c8 100644
class Tests_Post_Attachments extends WP_UnitTestCase { 389 389 /** 390 390 * @ticket 15928 391 391 */ 392 public function test_wp_get_attachment_url_should_ not_force_https_when_administering_over_https_but_siteurl_is_not_https() {392 public function test_wp_get_attachment_url_should_force_https_when_administering_over_https_but_siteurl_is_not_https() { 393 393 $siteurl = get_option( 'siteurl' ); 394 394 update_option( 'siteurl', set_url_scheme( $siteurl, 'http' ) ); 395 395 … … class Tests_Post_Attachments extends WP_UnitTestCase { 410 410 // Cleanup. 411 411 set_current_screen( 'front' ); 412 412 413 $this->assertSame( set_url_scheme( $url, 'http ' ), $url );413 $this->assertSame( set_url_scheme( $url, 'https' ), $url ); 414 414 } 415 415 416 416 /**