[wp-trac] [WordPress Trac] #38155: get_page_of_comment filter can't be used in some cases because has not comment_ID parameter

WordPress Trac noreply at wordpress.org
Sat Sep 24 21:26:27 UTC 2016


#38155: get_page_of_comment filter can't be used in some cases because has not
comment_ID parameter
--------------------------+-----------------------------
 Reporter:  zhildzik      |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  4.6.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 In WP 4.6.1: wp-includes/comment.php line 969:

 {{{#!php
 <?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
 <?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
 }

 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/38155>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list