Make WordPress Core

Opened 8 years ago

Closed 8 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's profile zhildzik Owned by: boonebgorges's profile boonebgorges
Milestone: 4.7 Priority: normal
Severity: normal Version: 4.6.1
Component: Comments Keywords:
Focuses: Cc:

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)

#1 @boonebgorges
8 years ago

  • Component changed from General to Comments
  • Milestone changed from Awaiting Review to 4.7

Hi @zhildzik - Thanks for the ticket, and welcome to WordPress Trac! The fact that $comment_ID is missing here is a very strange oversight. Let's fix it.

#2 @boonebgorges
8 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 38650:

Pass comment ID to get_page_of_comment filter.

Introduced in [34808].

Props zhildzik.
Fixes #38155.

Note: See TracTickets for help on using tickets.