Ticket #36934: 36934.diff
File 36934.diff, 12.4 KB (added by , 8 years ago) |
---|
-
src/wp-includes/class-wp-post.php
diff --git src/wp-includes/class-wp-post.php src/wp-includes/class-wp-post.php index a21776f..9c345dd 100644
17 17 * @property-read array $ancestors 18 18 * @property-read int $post_category 19 19 * @property-read string $tag_input 20 * 20 * @property-read array $pages 21 * @property-read int $multipage 21 22 */ 22 23 final class WP_Post { 23 24 … … final class WP_Post { 262 263 if ( 'tags_input' == $key ) 263 264 return true; 264 265 266 if ( 'pages' == $key ) { 267 return true; 268 } 269 270 if ( 'multipage' == $key ) { 271 return true; 272 } 273 265 274 return metadata_exists( 'post', $this->ID, $key ); 266 275 } 267 276 … … final class WP_Post { 296 305 return wp_list_pluck( $terms, 'name' ); 297 306 } 298 307 308 if ( 'pages' === $key ) { 309 $content = $this->post_content; 310 if ( false !== strpos( $content, '<!--nextpage-->' ) ) { 311 $content = str_replace( "\n<!--nextpage-->\n", '<!--nextpage-->', $content ); 312 $content = str_replace( "\n<!--nextpage-->", '<!--nextpage-->', $content ); 313 $content = str_replace( "<!--nextpage-->\n", '<!--nextpage-->', $content ); 314 315 // Ignore nextpage at the beginning of the content. 316 if ( 0 === strpos( $content, '<!--nextpage-->' ) ) 317 $content = substr( $content, 15 ); 318 319 $pages = explode('<!--nextpage-->', $content); 320 } else { 321 $pages = array( $this->post_content ); 322 } 323 324 /** 325 * Filters the "pages" derived from splitting the post content. 326 * 327 * "Pages" are determined by splitting the post content based on the presence 328 * of `<!-- nextpage -->` tags. 329 * 330 * @since 4.4.0 331 * 332 * @param array $pages Array of "pages" derived from the post content. 333 * of `<!-- nextpage -->` tags.. 334 * @param WP_Post $post Current post object. 335 */ 336 return apply_filters( 'content_pagination', $pages, $this ); 337 } 338 339 if ( 'multipage' === $key ) { 340 $numpages = count( $this->pages ); 341 342 return ( $numpages > 1 ) ? 1 : 0; 343 } 344 299 345 // Rest of the values need filtering. 300 346 if ( 'ancestors' == $key ) 301 347 $value = get_post_ancestors( $this ); -
src/wp-includes/class-wp-query.php
diff --git src/wp-includes/class-wp-query.php src/wp-includes/class-wp-query.php index 9590406..36d8067 100644
class WP_Query { 3996 3996 $more = 0; 3997 3997 } 3998 3998 3999 $content = $post->post_content; 4000 if ( false !== strpos( $content, '<!--nextpage-->' ) ) { 4001 $content = str_replace( "\n<!--nextpage-->\n", '<!--nextpage-->', $content ); 4002 $content = str_replace( "\n<!--nextpage-->", '<!--nextpage-->', $content ); 4003 $content = str_replace( "<!--nextpage-->\n", '<!--nextpage-->', $content ); 4004 4005 // Ignore nextpage at the beginning of the content. 4006 if ( 0 === strpos( $content, '<!--nextpage-->' ) ) 4007 $content = substr( $content, 15 ); 4008 4009 $pages = explode('<!--nextpage-->', $content); 4010 } else { 4011 $pages = array( $post->post_content ); 4012 } 4013 4014 /** 4015 * Filters the "pages" derived from splitting the post content. 4016 * 4017 * "Pages" are determined by splitting the post content based on the presence 4018 * of `<!-- nextpage -->` tags. 4019 * 4020 * @since 4.4.0 4021 * 4022 * @param array $pages Array of "pages" derived from the post content. 4023 * of `<!-- nextpage -->` tags.. 4024 * @param WP_Post $post Current post object. 4025 */ 4026 $pages = apply_filters( 'content_pagination', $pages, $post ); 4027 3999 $pages = $post->pages; 4028 4000 $numpages = count( $pages ); 4001 $multipage = $post->multipage; 4029 4002 4030 if ( $numpages > 1 ) { 4031 if ( $page > 1 ) { 4032 $more = 1; 4033 } 4034 $multipage = 1; 4035 } else { 4036 $multipage = 0; 4003 if ( $numpages > 1 && $page > 1 ) { 4004 $more = 1; 4037 4005 } 4038 4006 4039 4007 /** -
src/wp-includes/default-filters.php
diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php index 3402e48..d0e8763 100644
add_filter( 'the_content', 'shortcode_unautop' ); 139 139 add_filter( 'the_content', 'prepend_attachment' ); 140 140 add_filter( 'the_content', 'wp_make_content_images_responsive' ); 141 141 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' 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', 10, 2 ); 148 148 149 149 add_filter( 'the_post_thumbnail_caption', 'wptexturize' ); 150 150 add_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 13fd350..3710692 100644
function human_time_diff( $from, $to = '' ) { 3259 3259 * The ' […]' string can be modified by plugins/themes using the {@see 'excerpt_more'} filter 3260 3260 * 3261 3261 * @since 1.5.0 3262 * @since 4.7.0 Introduced the `$post` parameter. 3262 3263 * 3263 3264 * @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. 3264 3266 * @return string The excerpt. 3265 3267 */ 3266 function wp_trim_excerpt( $text = '' ) {3268 function wp_trim_excerpt( $text = '', $post = null ) { 3267 3269 $raw_excerpt = $text; 3270 3268 3271 if ( '' == $text ) { 3269 $text = get_the_content( '');3272 $text = get_the_content( $post, array( 'more_link_text' => '' ) ); 3270 3273 3271 3274 $text = strip_shortcodes( $text ); 3272 3275 -
src/wp-includes/post-template.php
diff --git src/wp-includes/post-template.php src/wp-includes/post-template.php index 7994f89..e4c9c51 100644
function the_content( $more_link_text = null, $strip_teaser = false) { 250 250 * @global int $page 251 251 * @global int $more 252 252 * @global bool $preview 253 * @global array $pages254 * @global int $multipage255 253 * 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. 254 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. 255 ** @param array $args { 256 * Array of arguments. 257 * 258 * @type string $more_link_text Optional. Content for when there is more text. Default null. 259 * @type bool $strip_teaser Optional. Strip teaser content before the more text. Default is false. 260 * } 258 261 * @return string 259 262 */ 260 function get_the_content( $more_link_text = null, $strip_teaser = false ) { 261 global $page, $more, $preview, $pages, $multipage; 263 function get_the_content( $post = null, $args = null ) { 264 global $page, $more, $preview; 265 266 $more_link_text = sprintf( 267 '<span aria-label="%1$s">%2$s</span>', 268 sprintf( 269 /* translators: %s: Name of current post */ 270 __( 'Continue reading %s' ), 271 the_title_attribute( array( 'echo' => false ) ) 272 ), 273 __( '(more…)' ) 274 ); 262 275 263 $post = get_post(); 276 $defaults = array( 277 'more_link_text' => $more_link_text, 278 'strip_teaser' => false, 279 ); 264 280 265 if ( null === $more_link_text ) { 266 $more_link_text = sprintf( 267 '<span aria-label="%1$s">%2$s</span>', 268 sprintf( 269 /* translators: %s: Name of current post */ 270 __( 'Continue reading %s' ), 271 the_title_attribute( array( 'echo' => false ) ) 272 ), 273 __( '(more…)' ) 281 // Backward compatibility for the old function signature. 282 if ( is_bool( $args ) || is_string( $post ) ) { 283 $args = array( 284 'more_link_text' => $post, 285 'strip_teaser' => $args, 274 286 ); 287 $post = null; 275 288 } 276 289 290 $args = wp_parse_args( $args, $defaults ); 291 292 $post = get_post( $post ); 293 277 294 $output = ''; 278 295 $has_teaser = false; 279 296 … … function get_the_content( $more_link_text = null, $strip_teaser = false ) { 281 298 if ( post_password_required( $post ) ) 282 299 return get_the_password_form( $post ); 283 300 284 if ( $page > count( $pages ) ) // if the requested page doesn't exist 285 $page = count( $pages ); // give them the highest numbered page that DOES exist 301 setup_postdata( $post ); 302 303 if ( $page > count( $post->pages ) ) // if the requested page doesn't exist 304 $page = count( $post->pages ); // give them the highest numbered page that DOES exist 286 305 287 $content = $p ages[$page - 1];306 $content = $post->pages[$page - 1]; 288 307 if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) { 289 308 $content = explode( $matches[0], $content, 2 ); 290 if ( ! empty( $matches[1] ) && ! empty( $ more_link_text) )291 $ more_link_text= strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );309 if ( ! empty( $matches[1] ) && ! empty( $args['more_link_text'] ) ) 310 $args['more_link_text'] = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) ); 292 311 293 312 $has_teaser = true; 294 313 } else { 295 314 $content = array( $content ); 296 315 } 297 316 298 if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $multipage || $page == 1 ) ) 299 $strip_teaser = true; 317 if ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ! $post->multipage || $page == 1 ) ) { 318 $args['strip_teaser'] = true; 319 } 300 320 301 321 $teaser = $content[0]; 302 322 303 if ( $more && $ strip_teaser && $has_teaser )323 if ( $more && $args['strip_teaser'] && $has_teaser ) { 304 324 $teaser = ''; 325 } 305 326 306 327 $output .= $teaser; 307 328 … … function get_the_content( $more_link_text = null, $strip_teaser = false ) { 309 330 if ( $more ) { 310 331 $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1]; 311 332 } else { 312 if ( ! empty( $more_link_text ) ) 333 if ( ! empty( $args['more_link_text'] ) ) { 334 $more_link = sprintf( 335 ' <a href="%s#more-%d" class="more-link">%s</a>', 336 get_permalink(), 337 $post->ID, 338 $args['more_link_text'] 339 ); 313 340 314 341 /** 315 342 * Filters the Read More link text. … … function get_the_content( $more_link_text = null, $strip_teaser = false ) { 319 346 * @param string $more_link_element Read More link element. 320 347 * @param string $more_link_text Read More text. 321 348 */ 322 $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text ); 349 $output .= apply_filters( 'the_content_more_link', $more_link, $args['more_link_text'] ); 350 } 323 351 $output = force_balance_tags( $output ); 324 352 } 325 353 } … … function get_the_content( $more_link_text = null, $strip_teaser = false ) { 327 355 if ( $preview ) // Preview fix for JavaScript bug with foreign languages. 328 356 $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output ); 329 357 358 wp_reset_postdata(); 359 330 360 return $output; 331 361 } 332 362 -
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 { 26 26 while ( $q->have_posts() ) { 27 27 $q->the_post(); 28 28 $this->assertSame( 'Post 2 Page 1', wp_trim_excerpt() ); 29 $this->assertSame( 'Post 1 Page 1Post 1 Page 2', wp_trim_excerpt( '', $post1 ) ); 29 30 } 30 31 } 31 32 } … … class Tests_Formatting_WpTrimExcerpt extends WP_UnitTestCase { 51 52 while ( $q->have_posts() ) { 52 53 $q->the_post(); 53 54 $this->assertSame( 'Post 2 Page 1', wp_trim_excerpt() ); 55 $this->assertSame( 'Post 1 Page 1', wp_trim_excerpt( '', $post1 ) ); 54 56 } 55 57 } 56 58 } -
tests/phpunit/tests/post/output.php
diff --git tests/phpunit/tests/post/output.php tests/phpunit/tests/post/output.php index 6026a2b..ddd5e05 100644
EOF; 217 217 $post_id = self::factory()->post->create( array( 'post_excerpt' => 'Bar' ) ); 218 218 $this->assertSame( 'Bar', get_the_excerpt( $post_id ) ); 219 219 } 220 221 /** 222 * @ticket 37519 223 */ 224 public function test_the_excerpt_specific_post_should_use_generated_excerpt() { 225 $GLOBALS['post'] = self::factory()->post->create_and_get( array( 'post_excerpt' => 'Foo' ) ); 226 $post_id = self::factory()->post->create( array( 'post_content' => 'Bar', 'post_excerpt' => '' ) ); 227 $this->assertSame( 'Bar', get_the_excerpt( $post_id ) ); 228 } 220 229 }