Make WordPress Core

Opened 7 years ago

Closed 4 years ago

#41009 closed enhancement (fixed)

Add filter to comment form class

Reported by: cjbj's profile cjbj Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.5 Priority: normal
Severity: normal Version:
Component: Comments Keywords: has-patch
Focuses: Cc:

Description

Almost all html of the comment_form function can be customized using filters, except for this line (current 2285 in comment-template.php), which is the wrapping div of the comment form:

<div id="respond" class="comment-respond">

I feel there are legitimate reasons for wanting at least the class to be filterable. For instance if you are using the clearfix class throughout your design to clear floats. So I would like to propose changing this line to this:

$respond_class = 'comment-respond';
$respond_class = apply_filters ('comment_form_respond_class' ,$respond_class);
echo '<div id="respond" class="' . esc_attr($respond_class) . '">';

Attachments (2)

41009.patch (677 bytes) - added by yahil 7 years ago.
41009.diff (2.1 KB) - added by mayankmajeji 4 years ago.
Comment respond class "class_repond" added to "comment-template.php" file.

Download all attachments as: .zip

Change History (9)

#1 @cjbj
7 years ago

  • Keywords has-patch added
  • Type changed from feature request to enhancement

@yahil
7 years ago

#2 @earnjam
5 years ago

  • Version 4.7 deleted

#3 @andraganescu
5 years ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to Future Release

I have tested this patch and it works very well. Allowing a filter for the class of the comment wrapper is indeed a minor enhancement, but nevertheless a logical one considering that almost all the other parts of that form are filterable.

#4 follow-up: @SergeyBiryukov
5 years ago

  • Keywords needs-patch added; has-patch commit removed
  • Milestone changed from Future Release to 5.5
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

Thanks for the patch!

Instead of a filter, I think this would make more sense as a new argument for the comment_form() function, for consistency with the existing class_form and class_submit arguments.

#5 @cjbj
5 years ago

That makes sense. It would still be filterable through 'comment_form_defaults' for less experienced developers.

@mayankmajeji
4 years ago

Comment respond class "class_repond" added to "comment-template.php" file.

#6 in reply to: ↑ 4 @mayankmajeji
4 years ago

  • Keywords has-patch added; needs-patch removed

I've added an argument "class_respond" to the comment_form() function. I hope this should do.

Replying to SergeyBiryukov:

Thanks for the patch!

Instead of a filter, I think this would make more sense as a new argument for the comment_form() function, for consistency with the existing class_form and class_submit arguments.

#7 @SergeyBiryukov
4 years ago

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

In 48393:

Comments: Allow passing a custom class to the form container element in comment_form().

Props cjbj, yahil, mayankmajeji, andraganescu, SergeyBiryukov.
Fixes #41009.

Note: See TracTickets for help on using tickets.