Opened 10 years ago
Closed 10 years ago
#38155 closed defect (bug) (fixed)
get_page_of_comment filter can't be used in some cases because has not comment_ID parameter
| Reported by: | zhildzik | Owned by: | boonebgorges |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.7 |
| Component: | Comments | Version: | 4.6.1 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
In WP 4.6.1: wp-includes/comment.php line 969:
<?php return apply_filters( 'get_page_of_comment', (int) $page, $args, $original_args );
This filter has no parameter comment_ID so it's impossible to get comment and calculate page outside of Wordpress get_page_of_comment function. It's possible to pass comment_ID parameter in $args when calling get_page_of_comment function but when this function called from Wordpress core function, it's impossible to get current comment.
For example, if we use get_comment_link() function, it's impossible to override result of get_page_of_comment() which called from get_comment_link().
Example:
<?php add_filter('get_page_of_comment', 'theme_reverse_page_comment', 10, 3); $recent_comments = get_comments(array( 'orderby' => 'comment_date', 'order' => 'DESC', 'status' => array('approve'), 'number' => 6 )); foreach ($recent_comments as $rc) { $link = get_comment_link($recent_comment); } function theme_reverse_page_comment($page, $args, $original_args) { // hook triggered from get_page_of_comment() function called in get_comment_link() // in this function - $recent_comment or ID of comment passed to get_comment_link() isn't available }
Change History (2)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Hi @zhildzik - Thanks for the ticket, and welcome to WordPress Trac! The fact that
$comment_IDis missing here is a very strange oversight. Let's fix it.