Make WordPress Core

Opened 10 years ago

Closed 9 years ago

#27526 closed enhancement (fixed)

Introduce comment excerpt length filter

Reported by: dannydehaan's profile dannydehaan Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.4 Priority: normal
Severity: normal Version: 3.8
Component: Comments Keywords: has-patch
Focuses: Cc:

Description

Hi,

I needed this for a client. I could have created a new function in my functions.php file, but why don't create a filter so it's much simpler to set the length for the comment excerpt.

I've also fixed some strange names in the functions like $blah and use_dotdotdot.

Attachments (6)

27526.diff (1.6 KB) - added by dannydehaan 10 years ago.
Fix for 27526
27526-2.diff (1.2 KB) - added by dannydehaan 10 years ago.
27526-2 - Extra spacing in for loop
27526-3.diff (1.4 KB) - added by dannydehaan 10 years ago.
27526-3 - Added inline doc
27526-4.diff (1.5 KB) - added by dannydehaan 10 years ago.
27526-2 - Fix in excerpt length with \n or \r. Fix for "trailing space"
72526-5.patch (1.6 KB) - added by dannydehaan 10 years ago.
27526-5 - Trim excerpt before adding ellipsis. Correct @since
27526.2.diff (1.4 KB) - added by wonderboymusic 9 years ago.

Download all attachments as: .zip

Change History (18)

@dannydehaan
10 years ago

Fix for 27526

#1 @nacin
10 years ago

Looks good. If we're going to fix spacing, we should add spaces to $i<$k as well.

This will need hook documentation. Also, I'd probably keep "20" in the main function docs, as it's the default.

#2 follow-up: @DrewAPicture
10 years ago

  • Keywords needs-docs added

See existing hook documentation in core for reference, as well as the inline documentation standards for hooks.

@dannydehaan
10 years ago

27526-2 - Extra spacing in for loop

#3 @dannydehaan
10 years ago

Added a new diff. Now with the correct spacing. Thanks @nacin

@dannydehaan
10 years ago

27526-3 - Added inline doc

#4 in reply to: ↑ 2 @dannydehaan
10 years ago

@DrewAPicture
Sorry, i didn't mentioned your comment. Fixed this now. Thanks!

#5 follow-up: @dannydehaan
10 years ago

@nacin,

I did found out, that when your comment is like the default comment from Mr. WordPress, the excerpt length will be 21 words. This is because of the "\n" or "\r" that is in the comment. I've fixed this by replacing the \n \r characters for a space. I've also found an issue when the ellipsis are used, the comment excerpt will look like this:


Hi, this is a comment. To delete a comment, just log in and view the post's comments. There you will …


Notice the space between will and … I've fixed this now by imploding the words with a space so you will not have this behaviour.

@dannydehaan
10 years ago

27526-2 - Fix in excerpt length with \n or \r. Fix for "trailing space"

#6 in reply to: ↑ 5 @SergeyBiryukov
10 years ago

Replying to dannydehaan:

Notice the space between will and … I've fixed this now by imploding the words with a space so you will not have this behaviour.

We can just use trim() before adding the ellipsis (like we did for wp_html_excerpt() in [24214]).

#7 @SergeyBiryukov
10 years ago

@since should use the 3-digit x.x.x style, 3.9.0 in this case.

#8 @SergeyBiryukov
10 years ago

  • Version changed from trunk to 3.8

@dannydehaan
10 years ago

27526-5 - Trim excerpt before adding ellipsis. Correct @since

#9 @dannydehaan
10 years ago

Hi Sergey,

Thank you for your feedback. I've edited the patch like you said.

#10 @dannydehaan
10 years ago

  • Keywords has-patch added; needs-docs removed

#11 @wonderboymusic
9 years ago

  • Milestone changed from Awaiting Review to 4.4
  • Owner set to wonderboymusic
  • Status changed from new to assigned

#12 @wonderboymusic
9 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 34520:

Comments: add a 'comment_excerpt_length' filter to get_comment_excerpt().

Create the first ever unit tests for get_comment_excerpt().

Props dannydehaan, wonderboymusic.
Fixes #27526.

Note: See TracTickets for help on using tickets.