Make WordPress Core

Ticket #15928: 15928.8.patch

File 15928.8.patch, 3.8 KB (added by joemcgill, 9 years ago)
  • src/wp-includes/default-filters.php

    diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php
    index dc0c8f8..adc3840 100644
    add_filter( 'the_content', 'convert_chars' ); 
    134134add_filter( 'the_content', 'wpautop'            );
    135135add_filter( 'the_content', 'shortcode_unautop'  );
    136136add_filter( 'the_content', 'prepend_attachment' );
     137add_filter( 'the_content', 'wp_filter_uploads_scheme' );
    137138
    138139add_filter( 'the_excerpt',     'wptexturize'      );
    139140add_filter( 'the_excerpt',     'convert_smilies'  );
  • src/wp-includes/formatting.php

    diff --git src/wp-includes/formatting.php src/wp-includes/formatting.php
    index 411eaa8..9fd13dc 100644
    function wp_spaces_regexp() { 
    39953995
    39963996        return $spaces;
    39973997}
     3998
     3999/**
     4000 * Returns scheme relative URLs for local URLs contained in a string of text.
     4001 * Created to be a display_filter for $content, but could have other uses.
     4002 *
     4003 * @param string $content A string which might contain a URL.
     4004 * @return string The found URL.
     4005 */
     4006function wp_filter_uploads_scheme( $content ) {
     4007        if ( empty( $content ) ) {
     4008                return false;
     4009        }
     4010       
     4011        // get upload directory and set baseurl
     4012        $upload_dir = wp_upload_dir();
     4013        $upload_url = $upload_dir['baseurl'];
     4014
     4015        // set relative URL scheme for the upload directory
     4016        $rel_upload_url = set_url_scheme( $upload_dir['baseurl'] );
     4017
     4018        // split the upload URL because both schemes might be found in the content
     4019        list( $scheme, $url) = explode( ':', $upload_url, 2 );
     4020       
     4021        $content = preg_replace( "|https?:" . $url ."|", $rel_upload_url, $content );
     4022
     4023        return $content;
     4024}
     4025 No newline at end of file
  • src/wp-includes/post.php

    diff --git src/wp-includes/post.php src/wp-includes/post.php
    index 81cd12a..5f08625 100644
    function wp_get_attachment_url( $post_id = 0 ) { 
    49464946                $url = get_the_guid( $post->ID );
    49474947        }
    49484948
     4949        // Match the current scheme.
     4950        $url = set_url_scheme( $url );
     4951
    49494952        /**
    49504953         * Filter the attachment URL.
    49514954         *
  • tests/phpunit/tests/post/attachments.php

    diff --git tests/phpunit/tests/post/attachments.php tests/phpunit/tests/post/attachments.php
    index d079654..7c4fb06 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_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 that wp_get_attachemt_url returns with http scheme
     298                $url = wp_get_attachment_url( $attachment_id );
     299                $this->assertSame( $url, set_url_scheme( $url, 'http' ) );
     300
     301                // Cleanup
     302                $_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off';
     303        }
     304
     305        /**
     306         * @ticket 15928
     307         */
     308        public function test_wp_get_attachment_url_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 that wp_get_attachemt_url returns with https scheme
     322                $url = wp_get_attachment_url( $attachment_id );
     323                $this->assertSame( $url, set_url_scheme( $url, 'https' ) );
     324
     325                // Cleanup
     326                $_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off';
     327        }
     328
    281329}
     330