[wp-trac] [WordPress Trac] #35651: No longer any consistent way to add content to bottom of comments form

WordPress Trac noreply at wordpress.org
Mon Aug 19 01:44:06 UTC 2019


#35651: No longer any consistent way to add content to bottom of comments form
---------------------------------------------------+---------------------
 Reporter:  smerriman                              |       Owner:  (none)
     Type:  defect (bug)                           |      Status:  new
 Priority:  normal                                 |   Milestone:
Component:  Comments                               |     Version:  4.4
 Severity:  normal                                 |  Resolution:
 Keywords:  2nd-opinion has-patch has-screenshots  |     Focuses:
---------------------------------------------------+---------------------
Changes (by donmhico):

 * keywords:  2nd-opinion needs-patch => 2nd-opinion has-patch has-
               screenshots


Comment:

 A new hook action seems like reasonable now. As @smerriman mentioned, the
 workaround provided in #26395 isn't applicable anymore.
 > Related: #27080
 >
 > You can use `comment_form_defaults` filter to prepend your text to
 `$args['comment_notes_after']`:
 > {{{
 > function comment_form_after_comment_26395( $defaults ) {
 >       $defaults['comment_notes_after'] = '<p>SAMPLE COMMENTS NOTES
 AFTER</p>' . $defaults['comment_notes_after'];
 >       return $defaults;
 > }
 > add_filter( 'comment_form_defaults', 'comment_form_after_comment_26395'
 );
 > }}}
 This is because `comment_notes_after` is no longer rendered directly at
 the top of the submit button. See the attached screenshot to see how the
 code above works.

 [[Image(https://core.trac.wordpress.org/raw-
 attachment/ticket/35651/comment_notes_after_invalid_workaround.png)]]

 Using the `comment_form` action
 (https://codex.wordpress.org/Plugin_API/Action_Reference/comment_form)
 won't do good as well because it is hooked after the submit button is
 rendered.

 For now, the only way is to use the `comment_form_submit_field` filter
 (https://developer.wordpress.org/reference/hooks/comment_form_submit_field/)
 and just append what we want there. But IMHO this is not good as that
 filter should really just be about the submit button itself.

 In my attached patch,
 [https://core.trac.wordpress.org/attachment/ticket/35651/35651.diff
 35651.diff], I introduced a new action called
 `before_comment_form_submit_field` which hooked directly above the submit
 button.

 Sample Usage:

 {{{#!php
 function test_action_before_submit_field( $post_id, $args ) {
         echo 'PERFORM ACTIONS ABOVE THE SUBMIT BUTTON';
  }
  add_action( 'before_comment_form_submit_field',
 'test_action_before_submit_field', 10, 2 );
 }}}

 The code above will result to

 [[Image(https://core.trac.wordpress.org/raw-
 attachment/ticket/35651/before_comment_form_submit_field.jpg)]]

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/35651#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list