Opened 12 years ago
Last modified 7 years ago
#23634 assigned enhancement
New hook for adding content after each comment
Reported by: | lancewillett | Owned by: | chriscct7 |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | |
Component: | Comments | Keywords: | has-patch |
Focuses: | Cc: |
Description
Similar to #18561 (which is for a new "after post" hook) add a hook that fires after each comment output with wp_list_comments
.
Attachments (4)
Change History (23)
#8
@
9 years ago
- Keywords needs-refresh added
- Owner set to chriscct7
- Status changed from new to assigned
#10
@
9 years ago
- Milestone changed from Future Release to 4.4
- Status changed from assigned to accepted
Thanks @mikehansenme
#11
@
9 years ago
- Keywords needs-docs added
@MikeHansenMe We'll need a hook doc to go with the action proposed in 23634.2.diff.
#14
@
9 years ago
- Owner changed from chriscct7 to DrewAPicture
Thanks @MikeHansenMe, I'll take a look.
#15
@
9 years ago
I'm not sure about the placement of the hook. In comment:1 @codeclarified mentioned that it was the only reliable place to put it, and if that's the case, then this really doesn't fire after a comment has been displayed.
#16
@
9 years ago
- Owner changed from DrewAPicture to chriscct7
- Status changed from accepted to assigned
#18
@
8 years ago
Okay if you apply the patch from @MikeHansenMe and add a echo "Hello Name";. It will just echo out on the parent itself rather then displaying on the child. So it seems like adding in a after_element action into class-wp-walker.php woukld make more sense. So that it could be used for menus and comments etc. Thoughts?
#19
@
7 years ago
As a proof of concept patch 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:
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.
Added a hook to class-wp-walker.php - due to the callback functions on comments this was the only reliable location I could find to add such a hook without worrying about it being dropped due to a custom callback, and still keeping a nested reply from duplicating the content after the levels start closing