Make WordPress Core

Ticket #36934: 36934a.diff

File 36934a.diff, 4.5 KB (added by swissspidy, 8 years ago)
  • src/wp-includes/default-filters.php

    diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php
    index 28d41c7..eb1d23d 100644
    add_filter( 'the_content', 'shortcode_unautop' ); 
    139139add_filter( 'the_content', 'prepend_attachment'                );
    140140add_filter( 'the_content', 'wp_make_content_images_responsive' );
    141141
    142 add_filter( 'the_excerpt',     'wptexturize'      );
    143 add_filter( 'the_excerpt',     'convert_smilies'  );
    144 add_filter( 'the_excerpt',     'convert_chars'    );
    145 add_filter( 'the_excerpt',     'wpautop'          );
    146 add_filter( 'the_excerpt',     'shortcode_unautop');
    147 add_filter( 'get_the_excerpt', 'wp_trim_excerpt'  );
     142add_filter( 'the_excerpt',     'wptexturize'            );
     143add_filter( 'the_excerpt',     'convert_smilies'        );
     144add_filter( 'the_excerpt',     'convert_chars'          );
     145add_filter( 'the_excerpt',     'wpautop'                );
     146add_filter( 'the_excerpt',     'shortcode_unautop'      );
     147add_filter( 'get_the_excerpt', 'wp_trim_excerpt', 10, 2 );
    148148
    149149add_filter( 'the_post_thumbnail_caption', 'wptexturize'     );
    150150add_filter( 'the_post_thumbnail_caption', 'convert_smilies' );
  • src/wp-includes/formatting.php

    diff --git src/wp-includes/formatting.php src/wp-includes/formatting.php
    index 40ac4c2..46bd70e 100644
    function human_time_diff( $from, $to = '' ) { 
    32593259 * The ' […]' string can be modified by plugins/themes using the {@see 'excerpt_more'} filter
    32603260 *
    32613261 * @since 1.5.0
     3262 * @since 4.6.0 Introduced the `$post` parameter.
    32623263 *
    32633264 * @param string $text Optional. The excerpt. If set to empty, an excerpt is generated.
     3265 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
    32643266 * @return string The excerpt.
    32653267 */
    3266 function wp_trim_excerpt( $text = '' ) {
     3268function wp_trim_excerpt( $text = '', $post = null ) {
    32673269        $raw_excerpt = $text;
     3270
    32683271        if ( '' == $text ) {
    3269                 $text = get_the_content('');
     3272                $text = get_the_content( $post, '' );
    32703273
    32713274                $text = strip_shortcodes( $text );
    32723275
  • src/wp-includes/post-template.php

    diff --git src/wp-includes/post-template.php src/wp-includes/post-template.php
    index dd83095..75af941 100644
    function the_content( $more_link_text = null, $strip_teaser = false) { 
    257257 * @param bool   $strip_teaser   Optional. Strip teaser content before the more text. Default is false.
    258258 * @return string
    259259 */
    260 function get_the_content( $more_link_text = null, $strip_teaser = false ) {
     260function get_the_content( $post = null, $more_link_text = null, $strip_teaser = false ) {
    261261        global $page, $more, $preview, $pages, $multipage;
    262262
    263         $post = get_post();
     263        if ( is_bool( $more_link_text ) || is_string( $post ) ) {
     264                $strip_teaser   = $more_link_text;
     265                $more_link_text = $post;
     266                $post           = null;
     267        }
     268
     269        $post = get_post( $post );
    264270
    265271        if ( null === $more_link_text ) {
    266272                $more_link_text = sprintf(
    function get_the_content( $more_link_text = null, $strip_teaser = false ) { 
    281287        if ( post_password_required( $post ) )
    282288                return get_the_password_form( $post );
    283289
     290        setup_postdata( $post );
     291
    284292        if ( $page > count( $pages ) ) // if the requested page doesn't exist
    285293                $page = count( $pages ); // give them the highest numbered page that DOES exist
    286294
    function get_the_content( $more_link_text = null, $strip_teaser = false ) { 
    327335        if ( $preview ) // Preview fix for JavaScript bug with foreign languages.
    328336                $output =       preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output );
    329337
     338        wp_reset_postdata();
     339
    330340        return $output;
    331341}
    332342
  • tests/phpunit/tests/formatting/WpTrimExcerpt.php

    diff --git tests/phpunit/tests/formatting/WpTrimExcerpt.php tests/phpunit/tests/formatting/WpTrimExcerpt.php
    index da508c7..6c615a5 100644
    class Tests_Formatting_WpTrimExcerpt extends WP_UnitTestCase { 
    2626                        while ( $q->have_posts() ) {
    2727                                $q->the_post();
    2828                                $this->assertSame( 'Post 2 Page 1', wp_trim_excerpt() );
     29                                $this->assertSame( 'Post 1 Page 1Post 1 Page 2', wp_trim_excerpt( '', $post1 ) );
    2930                        }
    3031                }
    3132        }
    class Tests_Formatting_WpTrimExcerpt extends WP_UnitTestCase { 
    5152                        while ( $q->have_posts() ) {
    5253                                $q->the_post();
    5354                                $this->assertSame( 'Post 2 Page 1', wp_trim_excerpt() );
     55                                $this->assertSame( 'Post 1 Page 1', wp_trim_excerpt( '', $post1 ) );
    5456                        }
    5557                }
    5658        }