Make WordPress Core

Ticket #15928: 15928.6.patch

File 15928.6.patch, 4.7 KB (added by boonebgorges, 10 years ago)
  • src/wp-includes/js/media-views.js

    diff --git src/wp-includes/js/media-views.js src/wp-includes/js/media-views.js
    index 62d2e43..809ccd2 100644
     
    74597459                },
    74607460
    74617461                updateImage: function() {
    7462                         this.$('img').attr( 'src', this.model.get('url') );
     7462                        this.$('img').attr( 'src', this.model.get('src_url') );
    74637463                }
    74647464        });
    74657465
  • src/wp-includes/link-template.php

    diff --git src/wp-includes/link-template.php src/wp-includes/link-template.php
    index 235fa79..72c20cb 100644
    function self_admin_url($path = '', $scheme = 'admin') { 
    30323032 * @since 3.4.0
    30333033 *
    30343034 * @param string $url Absolute url that includes a scheme
    3035  * @param string $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
     3035 * @param string $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login', 'login_post', 'admin', 'relative', or 'network_path'.
    30363036 * @return string $url URL with chosen scheme.
    30373037 */
    30383038function set_url_scheme( $url, $scheme = null ) {
    function set_url_scheme( $url, $scheme = null ) { 
    30423042                $scheme = is_ssl() ? 'https' : 'http';
    30433043        } elseif ( $scheme === 'admin' || $scheme === 'login' || $scheme === 'login_post' || $scheme === 'rpc' ) {
    30443044                $scheme = is_ssl() || force_ssl_admin() ? 'https' : 'http';
    3045         } elseif ( $scheme !== 'http' && $scheme !== 'https' && $scheme !== 'relative' ) {
     3045        } elseif ( $scheme !== 'http' && $scheme !== 'https' && $scheme !== 'relative' && $scheme !== 'network_path' ) {
    30463046                $scheme = is_ssl() ? 'https' : 'http';
    30473047        }
    30483048
    function set_url_scheme( $url, $scheme = null ) { 
    30543054                $url = ltrim( preg_replace( '#^\w+://[^/]*#', '', $url ) );
    30553055                if ( $url !== '' && $url[0] === '/' )
    30563056                        $url = '/' . ltrim($url , "/ \t\n\r\0\x0B" );
     3057        } else if ( 'network_path' == $scheme ) {
     3058                $url = preg_replace( '#^\w+://#', '//', $url );
    30573059        } else {
    30583060                $url = preg_replace( '#^\w+://#', $scheme . '://', $url );
    30593061        }
  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index 0c3fd22..fcce20a 100644
    function wp_prepare_attachment_for_js( $attachment ) { 
    25882588                'title'       => $attachment->post_title,
    25892589                'filename'    => wp_basename( $attachment->guid ),
    25902590                'url'         => $attachment_url,
     2591                'src_url'     => set_url_scheme( $attachment_url, 'network_path' ),
    25912592                'link'        => get_attachment_link( $attachment->ID ),
    25922593                'alt'         => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
    25932594                'author'      => $attachment->post_author,
  • src/wp-includes/post.php

    diff --git src/wp-includes/post.php src/wp-includes/post.php
    index f97318e..4d201b3 100644
    function wp_get_attachment_url( $post_id = 0 ) { 
    49444944                $url = get_the_guid( $post->ID );
    49454945        }
    49464946
     4947        // Match the current scheme.
     4948        $url = set_url_scheme( $url );
     4949
    49474950        /**
    49484951         * Filter the attachment URL.
    49494952         *
  • tests/phpunit/tests/post/attachments.php

    diff --git tests/phpunit/tests/post/attachments.php tests/phpunit/tests/post/attachments.php
    index d079654..fe716e6 100644
    class Tests_Post_Attachments extends WP_UnitTestCase { 
    278278                $this->assertEquals( $attachment->post_parent, $post_id );
    279279        }
    280280
     281        /**
     282         * @ticket 15928
     283         */
     284        public function test_wp_get_attachment_url_on_front_end_with_https_off() {
     285                $filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
     286                $contents = file_get_contents( $filename );
     287
     288                $upload = wp_upload_bits( basename( $filename ), null, $contents );
     289                $this->assertTrue( empty( $upload['error'] ) );
     290
     291                // Set attachment ID
     292                $attachment_id = $this->_make_attachment( $upload );
     293
     294                $is_ssl = is_ssl();
     295                $_SERVER['HTTPS'] = 'off';
     296
     297                // Test non-admin pages
     298                set_current_screen( 'front' );
     299                $url = wp_get_attachment_url( $attachment_id );
     300                $this->assertSame( $url, set_url_scheme( $url, 'http' ) );
     301
     302                $_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off';
     303        }
     304
     305        /**
     306         * @ticket 15928
     307         */
     308        public function test_wp_get_attachment_url_on_front_end_with_https_on() {
     309                $filename = ( DIR_TESTDATA . '/images/test-image.jpg' );
     310                $contents = file_get_contents( $filename );
     311
     312                $upload = wp_upload_bits( basename( $filename ), null, $contents );
     313                $this->assertTrue( empty( $upload['error'] ) );
     314
     315                // Set attachment ID
     316                $attachment_id = $this->_make_attachment( $upload );
     317
     318                $is_ssl = is_ssl();
     319                $_SERVER['HTTPS'] = 'on';
     320
     321                // Test non-admin pages
     322                set_current_screen( 'front' );
     323                $url = wp_get_attachment_url( $attachment_id );
     324                $this->assertSame( $url, set_url_scheme( $url, 'https' ) );
     325
     326                $_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off';
     327        }
    281328}