Ticket #34945: 34945.8.diff
File 34945.8.diff, 7.2 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/media.php
2819 2819 $media_dims = apply_filters( 'media_meta', $media_dims, $post ); 2820 2820 2821 2821 $att_url = wp_get_attachment_url( $post->ID ); 2822 // The "File URL" on the Edit Media screen should be the URL expected in content. 2823 $att_url = _wp_ssl_url( $att_url, 'content' ); 2822 2824 ?> 2823 2825 <div class="misc-pub-section misc-pub-attachment"> 2824 2826 <label for="attachment_url"><?php _e( 'File URL:' ); ?></label> -
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
351 351 */ 352 352 $class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size ); 353 353 354 $img_src = _wp_ssl_url( $img_src, 'content' ); 354 355 $html = '<img src="' . esc_attr($img_src) . '" alt="' . esc_attr($alt) . '" ' . $title . $hwstring . 'class="' . $class . '" />'; 355 356 356 357 /** … … 903 904 } 904 905 905 906 /** 907 * For local URLs, sets https scheme if needed. 908 * 909 * @since 4.5.0 910 * @access private 911 * 912 * @param string $url URL. 913 * @param string $context Whether the URL is being used in a "content" or "admin" context. 914 * @return string The same URL with proper scheme. 915 */ 916 function _wp_ssl_url( $url, $context = 'admin' ) { 917 918 if ( 'content' === $context ) { 919 /** 920 * If we're inserting a URL into content, the site's siteurl is configured for HTTP, and the URL host 921 * matches that of the siteurl, then we convert the URL to HTTP. 922 */ 923 $site_url = parse_url( get_option( 'siteurl' ) ); 924 if ( 'https' === substr( $url, 0, 5 ) && 'http' === $site_url['scheme'] && parse_url( $url, PHP_URL_HOST ) === $site_url['host'] ) { 925 $url = set_url_scheme( $url, 'http' ); 926 } 927 } else { 928 /* 929 * If we're using a URL outside of content and are currently viewing an HTTPS page, prefer HTTPS URLs 930 * as we know they are supported by the domain. 931 */ 932 if ( is_ssl() && 'https' !== substr( $url, 0, 5 ) && parse_url( $url, PHP_URL_HOST ) === $_SERVER['HTTP_HOST'] ) { 933 $url = set_url_scheme( $url, 'https' ); 934 } 935 } 936 937 return $url; 938 } 939 940 /** 906 941 * Get the image size as array from its meta data. 907 942 * 908 943 * Used for responsive images. … … 1025 1060 } 1026 1061 1027 1062 $upload_dir = wp_get_upload_dir(); 1028 $image_baseurl = trailingslashit( $upload_dir['baseurl'] ) . $dirname; 1063 1064 // Set URL scheme when front-end is https. 1065 $image_baseurl = _wp_ssl_url( $upload_dir['baseurl'] ); 1066 $image_baseurl = trailingslashit( $image_baseurl ) . $dirname; 1029 1067 1030 1068 /* 1031 1069 * Images that have been edited in WordPress after being uploaded will … … 2998 3036 2999 3037 $attachment_url = wp_get_attachment_url( $attachment->ID ); 3000 3038 3039 // @todo When displaying images in the media grid, this is an admin context. Is this different elsewhere? 3040 $attachment_url = _wp_ssl_url( $attachment_url, 'admin' ); 3041 3001 3042 $response = array( 3002 3043 'id' => $attachment->ID, 3003 3044 'title' => $attachment->post_title, -
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 = _wp_ssl_url( $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 1422 // Mock meta for the image. 1423 $image_meta = array( 1424 'width' => 1200, 1425 'height' => 600, 1426 'file' => 'test.jpg', 1427 'sizes' => array( 1428 'thumbnail' => array( 1429 'file' => 'test-150x150.jpg', 1430 'width' => 150, 1431 'height' => 150, 1432 ), 1433 'medium' => array( 1434 'file' => 'test-300x150.jpg', 1435 'width' => 300, 1436 'height' => 150, 1437 ), 1438 'large' => array( 1439 'file' => 'test-1024x512.jpg', 1440 'width' => 1024, 1441 'height' => 512, 1442 ), 1443 ) 1444 ); 1445 1446 // Test using the large file size. 1447 $size_array = array(1024, 512); 1448 $image_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_meta['sizes']['large']['file']; 1449 1450 $_SERVER['HTTPS'] = 'on'; 1451 1452 $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'; 1453 1454 $this->assertSame( $expected, wp_calculate_image_srcset( $size_array, $image_url, $image_meta ) ); 1455 1456 // Cleanup 1457 $_SERVER['HTTPS'] = $is_ssl; 1410 1458 } 1411 1459 } -
tests/phpunit/tests/post/attachments.php
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 … … 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 /**