Ticket #44541: 44541.diff
File 44541.diff, 15.9 KB (added by , 5 years ago) |
---|
-
src/wp-admin/includes/dashboard.php
diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php index ad02909c74..62cd5a014f 100644
a b function wp_dashboard_recent_drafts( $drafts = false ) { 584 584 } 585 585 echo '<h2 class="hide-if-no-js">' . __( 'Your Recent Drafts' ) . "</h2>\n<ul>"; 586 586 587 /* translators: Maximum number of words used in a preview of a draft on the dashboard. */ 588 $draft_length = intval( _x( '10', 'draft_length' ) ); 589 587 590 $drafts = array_slice( $drafts, 0, 3 ); 588 591 foreach ( $drafts as $draft ) { 589 592 $url = get_edit_post_link( $draft->ID ); … … function wp_dashboard_recent_drafts( $drafts = false ) { 592 595 /* translators: %s: post title */ 593 596 echo '<div class="draft-title"><a href="' . esc_url( $url ) . '" aria-label="' . esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ) . '">' . esc_html( $title ) . '</a>'; 594 597 echo '<time datetime="' . get_the_time( 'c', $draft ) . '">' . get_the_time( __( 'F j, Y' ), $draft ) . '</time></div>'; 595 if ( $the_content = wp_trim_words( $draft->post_content, 10) ) {598 if ( $the_content = wp_trim_words( $draft->post_content, $draft_length ) ) { 596 599 echo '<p>' . $the_content . '</p>'; 597 600 } 598 601 echo "</li>\n"; -
src/wp-includes/comment-template.php
diff --git a/src/wp-includes/comment-template.php b/src/wp-includes/comment-template.php index 41031cba93..300bdac992 100644
a b function comment_date( $d = '', $comment_ID = 0 ) { 577 577 } 578 578 579 579 /** 580 * Retrieve the excerpt of the currentcomment.580 * Retrieves the excerpt of the given comment. 581 581 * 582 * Will cut each word and only output the first 20 words with '…' at the end. 583 * If the word count is less than 20, then no truncating is done and no '…' 584 * will appear. 582 * Returns a maximum of 20 words with an ellipsis appended if necessary. 585 583 * 586 584 * @since 1.5.0 587 585 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object. 588 586 * 589 587 * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to get the excerpt. 590 588 * Default current comment. 591 * @return string The maybe truncated comment with 20 words or less.589 * @return string The possibly truncated comment excerpt. 592 590 */ 593 591 function get_comment_excerpt( $comment_ID = 0 ) { 594 592 $comment = get_comment( $comment_ID ); 595 593 $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) ); 596 $words = explode( ' ', $comment_text ); 594 595 /* translators: Maximum number of words used in a comment excerpt. */ 596 $comment_excerpt_length = intval( _x( '20', 'comment_excerpt_length' ) ); 597 597 598 598 /** 599 * Filters the amountof words used in the comment excerpt.599 * Filters the maximum number of words used in the comment excerpt. 600 600 * 601 601 * @since 4.4.0 602 602 * 603 603 * @param int $comment_excerpt_length The amount of words you want to display in the comment excerpt. 604 604 */ 605 $comment_excerpt_length = apply_filters( 'comment_excerpt_length', 20);605 $comment_excerpt_length = apply_filters( 'comment_excerpt_length', $comment_excerpt_length ); 606 606 607 $use_ellipsis = count( $words ) > $comment_excerpt_length; 608 if ( $use_ellipsis ) { 609 $words = array_slice( $words, 0, $comment_excerpt_length ); 610 } 607 $excerpt = wp_trim_words( $comment_text, $comment_excerpt_length, '…' ); 611 608 612 $excerpt = trim( join( ' ', $words ) );613 if ( $use_ellipsis ) {614 $excerpt .= '…';615 }616 609 /** 617 610 * Filters the retrieved comment excerpt. 618 611 * -
src/wp-includes/formatting.php
diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index 7d73481eab..36ec85e0d1 100644
a b function human_time_diff( $from, $to = '' ) { 3680 3680 /** 3681 3681 * Generates an excerpt from the content, if needed. 3682 3682 * 3683 * The excerpt word amount will be 55 words and if the amount is greater than 3684 * that, then the string ' […]' will be appended to the excerpt. If the string 3685 * is less than 55 words, then the content will be returned as is. 3683 * Returns a maximum of 55 words with an ellipsis appended if necessary. 3686 3684 * 3687 3685 * The 55 word limit can be modified by plugins/themes using the {@see 'excerpt_length'} filter 3688 3686 * The ' […]' string can be modified by plugins/themes using the {@see 'excerpt_more'} filter … … function wp_trim_excerpt( $text = '', $post = null ) { 3707 3705 $text = apply_filters( 'the_content', $text ); 3708 3706 $text = str_replace( ']]>', ']]>', $text ); 3709 3707 3708 /* translators: Maximum number of words used in a post excerpt. */ 3709 $excerpt_length = intval( _x( '55', 'excerpt_length' ) ); 3710 3710 3711 /** 3711 * Filters the number of words in anexcerpt.3712 * Filters the maximum number of words in a post excerpt. 3712 3713 * 3713 3714 * @since 2.7.0 3714 3715 * 3715 * @param int $number The number of words. Default 55.3716 * @param int $number The maximum number of words. Default 55. 3716 3717 */ 3717 $excerpt_length = apply_filters( 'excerpt_length', 55 ); 3718 $excerpt_length = apply_filters( 'excerpt_length', $excerpt_length ); 3719 3718 3720 /** 3719 3721 * Filters the string in the "more" link displayed after a trimmed excerpt. 3720 3722 * … … function wp_trim_excerpt( $text = '', $post = null ) { 3725 3727 $excerpt_more = apply_filters( 'excerpt_more', ' ' . '[…]' ); 3726 3728 $text = wp_trim_words( $text, $excerpt_length, $excerpt_more ); 3727 3729 } 3730 3728 3731 /** 3729 3732 * Filters the trimmed excerpt string. 3730 3733 * -
tests/phpunit/data/languages/ja_JP.po
diff --git a/tests/phpunit/data/languages/ja_JP.po b/tests/phpunit/data/languages/ja_JP.po index f71a737714..bd9cd17a95 100644
a b msgstr "number_format_thousands_sep" 40 40 #: wp-includes/script-loader.php:620 41 41 msgid "Update %s now" 42 42 msgstr "今すぐ %s を更新" 43 44 #. translators: If your word count is based on single characters (e.g. East 45 #. Asian characters), enter 'characters_excluding_spaces' or 46 #. 'characters_including_spaces'. Otherwise, enter 'words'. Do not translate 47 #. into your own language. 48 #: wp-includes/formatting.php:3372 wp-includes/script-loader.php:1100 49 msgctxt "Word count type. Do not translate!" 50 msgid "words" 51 msgstr "characters_including_spaces" 52 53 #. translators: Maximum number of words used in a post excerpt. 54 #: wp-includes/formatting.php:3640 55 msgctxt "excerpt_length" 56 msgid "55" 57 msgstr "110" 58 59 #. translators: Maximum number of words used in a comment excerpt. 60 #: wp-includes/comment-template.ph:599 61 msgctxt "comment_excerpt_length" 62 msgid "20" 63 msgstr "40" 64 65 #. translators: Maximum number of words used in a preview of a draft on the dashboard. 66 #: wp-admin/includes/dashboard.php:591 67 msgctxt "draft_length" 68 msgid "10" 69 msgstr "40" -
tests/phpunit/tests/formatting/WPTrimWords.php
diff --git a/tests/phpunit/tests/formatting/WPTrimWords.php b/tests/phpunit/tests/formatting/WPTrimWords.php index 7f2a27fc05..fab62372f7 100644
a b 4 4 * @group formatting 5 5 */ 6 6 class Tests_Formatting_WPTrimWords extends WP_UnitTestCase { 7 8 /** 9 * Long Dummy Text. 10 * 11 * @since 5.0.0 12 * 13 * @var string $long_text 14 */ 7 15 private $long_text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce varius lacinia vehicula. Etiam sapien risus, ultricies ac posuere eu, convallis sit amet augue. Pellentesque urna massa, lacinia vel iaculis eget, bibendum in mauris. Aenean eleifend pulvinar ligula, a convallis eros gravida non. Suspendisse potenti. Pellentesque et odio tortor. In vulputate pellentesque libero, sed dapibus velit mollis viverra. Pellentesque id urna euismod dolor cursus sagittis.'; 8 16 9 17 function test_trims_to_55_by_default() { … … class Tests_Formatting_WPTrimWords extends WP_UnitTestCase { 42 50 $text = 'This is some short text.'; 43 51 $this->assertEquals( $text, wp_trim_words( $text ) ); 44 52 } 53 54 /** 55 * @ticket 44541 56 */ 57 function test_trims_to_20_counted_by_chars() { 58 switch_to_locale( 'ja_JP' ); 59 $expected = substr( $this->long_text, 0, 20 ) . '…'; 60 $actual = wp_trim_words( $this->long_text, 20 ); 61 restore_previous_locale(); 62 $this->assertEquals( $expected, $actual ); 63 } 64 65 /** 66 * @ticket 44541 67 */ 68 function test_trims_to_20_counted_by_chars_with_double_width_chars() { 69 switch_to_locale( 'ja_JP' ); 70 $text = str_repeat( 'あ', 100 ); 71 $expected = str_repeat( 'あ', 19 ) . '…'; 72 $actual = wp_trim_words( $text, 19 ); 73 restore_previous_locale(); 74 $this->assertEquals( $expected, $actual ); 75 } 45 76 } -
tests/phpunit/tests/l10n.php
diff --git a/tests/phpunit/tests/l10n.php b/tests/phpunit/tests/l10n.php index 45a6008363..7b34d32b4e 100644
a b 6 6 */ 7 7 class Tests_L10n extends WP_UnitTestCase { 8 8 9 /** 10 * Long Dummy Text. 11 * 12 * @since 5.0.0 13 * 14 * @var string $long_text 15 */ 16 private $long_text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'; 17 9 18 /** 10 19 * @ticket 35961 11 20 */ … … class Tests_L10n extends WP_UnitTestCase { 260 269 $this->assertNotEmpty( $array['Project-Id-Version'] ); 261 270 $this->assertNotEmpty( $array['X-Generator'] ); 262 271 } 272 273 /** 274 * @ticket 44541 275 */ 276 function test_length_of_excerpt_should_be_counted_by_words() { 277 global $post; 278 279 switch_to_locale( 'en_US' ); 280 281 $args = array( 282 'post_content' => $this->long_text, 283 'post_excerpt' => '', 284 ); 285 286 $post = $this->factory()->post->create_and_get( $args ); 287 setup_postdata( $post ); 288 289 $expect = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat […]</p>\n"; 290 the_excerpt(); 291 292 restore_previous_locale(); 293 294 $this->expectOutputString( $expect ); 295 } 296 297 /** 298 * @ticket 44541 299 */ 300 function test_length_of_excerpt_should_be_counted_by_chars() { 301 global $post; 302 303 switch_to_locale( 'ja_JP' ); 304 305 $args = array( 306 'post_content' => $this->long_text, 307 'post_excerpt' => '', 308 ); 309 310 $post = $this->factory()->post->create_and_get( $args ); 311 setup_postdata( $post ); 312 313 $expect = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore […]</p>\n"; 314 the_excerpt(); 315 316 restore_previous_locale(); 317 318 $this->expectOutputString( $expect ); 319 } 320 321 /** 322 * @ticket 44541 323 */ 324 function test_length_of_excerpt_should_be_counted_by_chars_in_japanese() { 325 global $post; 326 327 switch_to_locale( 'ja_JP' ); 328 329 $args = array( 330 'post_content' => str_repeat( 'あ', 200 ), 331 'post_excerpt' => '', 332 ); 333 334 $post = $this->factory()->post->create_and_get( $args ); 335 setup_postdata( $post ); 336 337 $expect = '<p>' . str_repeat( 'あ', 110 ) . " […]</p>\n"; 338 the_excerpt(); 339 340 restore_previous_locale(); 341 342 $this->expectOutputString( $expect ); 343 } 344 345 /** 346 * @ticket 44541 347 */ 348 function test_length_of_excerpt_rss_should_be_counted_by_words() { 349 global $post; 350 351 switch_to_locale( 'en_US' ); 352 353 $args = array( 354 'post_content' => $this->long_text, 355 'post_excerpt' => '', 356 ); 357 358 $post = $this->factory()->post->create_and_get( $args ); 359 setup_postdata( $post ); 360 361 $expect = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat […]'; 362 the_excerpt_rss(); 363 364 restore_previous_locale(); 365 366 $this->expectOutputString( $expect ); 367 } 368 369 /** 370 * @ticket 44541 371 */ 372 function test_length_of_excerpt_rss_should_be_counted_by_chars() { 373 global $post; 374 375 switch_to_locale( 'ja_JP' ); 376 377 $args = array( 378 'post_content' => $this->long_text, 379 'post_excerpt' => '', 380 ); 381 382 $post = $this->factory()->post->create_and_get( $args ); 383 setup_postdata( $post ); 384 385 $expect = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore […]'; 386 387 the_excerpt_rss(); 388 389 restore_previous_locale(); 390 391 $this->expectOutputString( $expect ); 392 } 393 394 /** 395 * @ticket 44541 396 */ 397 function test_length_of_draft_should_be_counted_by_words() { 398 require_once ABSPATH . 'wp-admin/includes/dashboard.php'; 399 400 switch_to_locale( 'en_US' ); 401 402 $args = array( 403 'post_content' => $this->long_text, 404 'post_excerpt' => '', 405 'post_status' => 'draft', 406 ); 407 408 $this->factory()->post->create( $args ); 409 410 $expect = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do…'; 411 wp_dashboard_recent_drafts(); 412 413 restore_previous_locale(); 414 415 $this->expectOutputRegex( '/' . $expect . '/' ); 416 } 417 418 /** 419 * @ticket 44541 420 */ 421 function test_length_of_draft_should_be_counted_by_chars() { 422 require_once ABSPATH . 'wp-admin/includes/dashboard.php'; 423 424 switch_to_locale( 'ja_JP' ); 425 426 $args = array( 427 'post_content' => $this->long_text, 428 'post_excerpt' => '', 429 'post_status' => 'draft', 430 ); 431 432 $post = $this->factory()->post->create( $args ); 433 434 $expect = 'Lorem ipsum dolor sit amet, consectetur …'; 435 wp_dashboard_recent_drafts(); 436 437 restore_previous_locale(); 438 439 $this->expectOutputRegex( '/' . $expect . '/' ); 440 } 441 442 /** 443 * @ticket 44541 444 */ 445 function test_length_of_draft_should_be_counted_by_chars_in_japanese() { 446 require_once ABSPATH . 'wp-admin/includes/dashboard.php'; 447 448 switch_to_locale( 'ja_JP' ); 449 450 $args = array( 451 'post_content' => str_repeat( 'あ', 200 ), 452 'post_excerpt' => '', 453 'post_status' => 'draft', 454 ); 455 456 $this->factory()->post->create( $args ); 457 458 $expect = str_repeat( 'あ', 40 ) . '…'; 459 wp_dashboard_recent_drafts(); 460 461 restore_previous_locale(); 462 463 $this->expectOutputRegex( '/' . $expect . '/' ); 464 } 465 466 /** 467 * @ticket 44541 468 */ 469 function test_length_of_comment_excerpt_should_be_counted_by_words() { 470 switch_to_locale( 'en_US' ); 471 472 $args = array( 473 'comment_content' => $this->long_text, 474 ); 475 $comment_id = $this->factory()->comment->create( $args ); 476 $expect = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut…'; 477 $comment_excerpt = get_comment_excerpt( $comment_id ); 478 479 restore_previous_locale(); 480 481 $this->assertSame( $expect, $comment_excerpt ); 482 } 483 484 /** 485 * @ticket 44541 486 */ 487 function test_length_of_comment_excerpt_should_be_counted_by_chars() { 488 switch_to_locale( 'ja_JP' ); 489 490 $args = array( 491 'comment_content' => $this->long_text, 492 ); 493 $comment_id = $this->factory()->comment->create( $args ); 494 $expect = 'Lorem ipsum dolor sit amet, consectetur …'; 495 $comment_excerpt = get_comment_excerpt( $comment_id ); 496 497 restore_previous_locale(); 498 499 $this->assertSame( $expect, $comment_excerpt ); 500 } 501 502 /** 503 * @ticket 44541 504 */ 505 function test_length_of_comment_excerpt_should_be_counted_by_chars_in_Japanese() { 506 switch_to_locale( 'ja_JP' ); 507 508 $args = array( 509 'comment_content' => str_repeat( 'あ', 200 ), 510 ); 511 $comment_id = $this->factory()->comment->create( $args ); 512 $expect = str_repeat( 'あ', 40 ) . '…'; 513 $comment_excerpt = get_comment_excerpt( $comment_id ); 514 515 restore_previous_locale(); 516 517 $this->assertSame( $expect, $comment_excerpt ); 518 } 263 519 }