WordPress.org

Make WordPress Core

Ticket #10984: 10984.6.diff

File 10984.6.diff, 5.9 KB (added by swissspidy, 5 years ago)
  • src/wp-includes/feed.php

    diff --git src/wp-includes/feed.php src/wp-includes/feed.php
    index feb690d..ce5f045 100644
    function get_the_content_feed($feed_type = null) { 
    186186                $feed_type = get_default_feed();
    187187
    188188        /** This filter is documented in wp-includes/post-template.php */
    189         $content = apply_filters( 'the_content', get_the_content() );
     189        $content = apply_filters( 'the_content', get_the_content( null, false, true ) );
    190190        $content = str_replace(']]>', ']]>', $content);
    191191        /**
    192192         * Filter the post content for use in feeds.
  • src/wp-includes/post-template.php

    diff --git src/wp-includes/post-template.php src/wp-includes/post-template.php
    index 5ceed59..81fa34e 100644
    function get_the_guid( $post = 0 ) { 
    223223 * Display the post content.
    224224 *
    225225 * @since 0.71
     226 * @since 4.5.0 Added the `$ignore_pagination` parameter.
    226227 *
    227  * @param string $more_link_text Optional. Content for when there is more text.
    228  * @param bool   $strip_teaser   Optional. Strip teaser content before the more text. Default is false.
     228 * @param string $more_link_text    Optional. Content for when there is more text.
     229 * @param bool   $strip_teaser      Optional. Strip teaser content before the more text. Default is false.
     230 * @param bool   $ignore_pagination Optional. Return full text, ignoring pagination. Default is false.
    229231 */
    230 function the_content( $more_link_text = null, $strip_teaser = false) {
    231         $content = get_the_content( $more_link_text, $strip_teaser );
     232function the_content( $more_link_text = null, $strip_teaser = false, $ignore_pagination = false ) {
     233        $content = get_the_content( $more_link_text, $strip_teaser, $ignore_pagination );
    232234
    233235        /**
    234236         * Filter the post content.
    function the_content( $more_link_text = null, $strip_teaser = false) { 
    246248 * Retrieve the post content.
    247249 *
    248250 * @since 0.71
     251 * @since 4.5.0 Added the `$ignore_pagination` parameter.
    249252 *
    250253 * @global int   $page
    251254 * @global int   $more
    function the_content( $more_link_text = null, $strip_teaser = false) { 
    253256 * @global array $pages
    254257 * @global int   $multipage
    255258 *
    256  * @param string $more_link_text Optional. Content for when there is more text.
    257  * @param bool   $strip_teaser   Optional. Strip teaser content before the more text. Default is false.
    258  * @return string
     259 * @param string $more_link_text    Optional. Content for when there is more text.
     260 * @param bool   $strip_teaser      Optional. Strip teaser content before the more text. Default is false.
     261 * @param bool   $ignore_pagination Optional. Return full text, ignoring pagination. Default is false.
     262 * @return string The post content.
    259263 */
    260 function get_the_content( $more_link_text = null, $strip_teaser = false ) {
     264function get_the_content( $more_link_text = null, $strip_teaser = false, $ignore_pagination = false ) {
    261265        global $page, $more, $preview, $pages, $multipage;
    262266
    263267        $post = get_post();
    function get_the_content( $more_link_text = null, $strip_teaser = false ) { 
    275279        if ( $page > count( $pages ) ) // if the requested page doesn't exist
    276280                $page = count( $pages ); // give them the highest numbered page that DOES exist
    277281
    278         $content = $pages[$page - 1];
     282        if ( $ignore_pagination ) {
     283                $content = implode( "\n", $pages );
     284        } else {
     285                $content = $pages[ $page - 1 ];
     286        }
     287
    279288        if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
    280289                $content = explode( $matches[0], $content, 2 );
    281290                if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) )
  • tests/phpunit/tests/feed/rss2.php

    diff --git tests/phpunit/tests/feed/rss2.php tests/phpunit/tests/feed/rss2.php
    index edd42a5..4217487 100644
    class Tests_Feeds_RSS2 extends WP_UnitTestCase { 
    264264                remove_filter( 'comments_open', '__return_false' );
    265265        }
    266266
     267        /**
     268         * @ticket 10984
     269         */
     270        function test_items_ignore_pagination() {
     271                self::$posts[] = $new_post = $this->factory()->post->create( array(
     272                        'post_author'  => self::$user_id,
     273                        'post_content' => 'Page 1 <!--nextpage--> Page 2 <!--nextpage--> Page 3',
     274                        'post_excerpt' => 'Excerpt',
     275                ) );
     276
     277                $this->go_to( '/?feed=rss2' );
     278                $feed = $this->do_rss2();
     279                $xml = xml_to_array( $feed );
     280
     281                // Get all the <item> child elements of the <channel> element
     282                $items = xml_find( $xml, 'rss', 'channel', 'item' );
     283
     284                $items = array_slice( $items, 0, 1 );
     285
     286                // Check each of the desired entries against the known post data
     287                foreach ( $items as $key => $item ) {
     288                        // Get post for comparison
     289                        $guid = xml_find( $items[ $key ]['child'], 'guid' );
     290                        preg_match( '/\?p=(\d+)/', $guid[0]['content'], $matches );
     291                        $post = get_post( $matches[1] );
     292
     293                        $this->assertEquals( $new_post, $matches[1] );
     294
     295                        // Post content
     296                        if ( ! $this->excerpt_only ) {
     297                                $content = xml_find( $items[ $key ]['child'], 'content:encoded' );
     298                                $this->assertEquals( "<p>Page 1<br />\n Page 2<br />\n Page 3</p>", trim( $content[0]['content'] ) );
     299                        }
     300                }
     301
     302                array_pop(self::$posts);
     303                reset(self::$posts);
     304        }
    267305}
  • tests/phpunit/tests/post/output.php

    diff --git tests/phpunit/tests/post/output.php tests/phpunit/tests/post/output.php
    index 6026a2b..ac00f26 100644
    EOF; 
    217217                $post_id = self::factory()->post->create( array( 'post_excerpt' => 'Bar' ) );
    218218                $this->assertSame( 'Bar', get_the_excerpt( $post_id ) );
    219219        }
     220
     221        /**
     222         * @ticket 10984
     223         */
     224        function test_get_the_content_ignore_pagination() {
     225                $post_id = self::factory()->post->create( array(
     226                        'post_content' => 'Page 1 <!--nextpage--> Page 2 <!--nextpage--> Page 3',
     227                ) );
     228
     229                $this->go_to( get_permalink( $post_id ) );
     230                $this->assertQueryTrue( 'is_singular', 'is_single' );
     231                setup_postdata( get_post( $post_id ) );
     232
     233                $this->assertEquals( 'Page 1 ', get_the_content() );
     234                $this->assertEquals( "Page 1 \n Page 2 \n Page 3", get_the_content( null, false, true ) );
     235        }
    220236}