[wp-trac] [WordPress Trac] #23634: New hook for adding content after each comment
WordPress Trac
noreply at wordpress.org
Mon Oct 23 14:56:08 UTC 2017
#23634: New hook for adding content after each comment
--------------------------+-----------------------------
Reporter: lancewillett | Owner: chriscct7
Type: enhancement | Status: assigned
Priority: normal | Milestone: Future Release
Component: Comments | Version:
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
--------------------------+-----------------------------
Comment (by keesiemeijer):
As a proof of concept patch [attachment:23634.4.patch] doesn't add the
hook inside the `WP_WALKER` class. It does add a method `start_el_after`
that the child classes can use to add content after the element. Because
this method is called right after the `start_el` method you can insert
content before the end tag (and child elements if they exist).
{{{
<ol class="comment-list">
<li id="comment-1" class="comment">
<article id="div-comment-31" class="comment-body">
... </article>
<!-- Comment after is inserted here. -->
<ol class="children"> ... </ol><!-- #child
elements-## -->
</li><!-- #comment-## -->
</ol>
}}}
I've added the `start_el_after` method to the `Walker_Comment` class with
a filter to add content. Now you can use the filter like this:
{{{#!php
add_filter( 'after_comment', 'add_content_after_comment', 10, 3 );
function add_content_after_comment( $comment, $depth, $args ) {
return $comment . '<p>Inserted content after comment.</p>';
}
}}}
An alternative is to ditch the extra method (in `WP_WALKER`) and add the
filter directly in the `start_el` method of the `Walker_Comment` class.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/23634#comment:19>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list