WordPress.org

Make WordPress Core

Ticket #12006: comment_ID.argument.12006.diff

File comment_ID.argument.12006.diff, 9.6 KB (added by filosofo, 8 years ago)
  • wp-includes/comment-template.php

     
    1717 * @since 1.5.0
    1818 * @uses apply_filters() Calls 'get_comment_author' hook on the comment author
    1919 *
     20 * @param int $comment_ID The ID of the comment for which to retrieve the author. Optional.
    2021 * @return string The comment author
    2122 */
    22 function get_comment_author() {
     23function get_comment_author( $comment_ID = 0 ) {
    2324        global $comment;
    24         if ( empty($comment->comment_author) ) {
    25                 if (!empty($comment->user_id)){
    26                         $user=get_userdata($comment->user_id);
     25        $_comment = empty( $comment_ID ) ? $comment : get_comment( $comment_ID );
     26        if ( empty($_comment->comment_author) ) {
     27                if (!empty($_comment->user_id)){
     28                        $user=get_userdata($_comment->user_id);
    2729                        $author=$user->user_login;
    2830                } else {
    2931                        $author = __('Anonymous');
    3032                }
    3133        } else {
    32                 $author = $comment->comment_author;
     34                $author = $_comment->comment_author;
    3335        }
    3436        return apply_filters('get_comment_author', $author);
    3537}
     
    3941 *
    4042 * @since 0.71
    4143 * @uses apply_filters() Calls 'comment_author' on comment author before displaying
     44 *
     45 * @param int $comment_ID The ID of the comment for which to print the author. Optional.
    4246 */
    43 function comment_author() {
    44         $author = apply_filters('comment_author', get_comment_author() );
     47function comment_author( $comment_ID = 0 ) {
     48        $author = apply_filters('comment_author', get_comment_author( $comment_ID ) );
    4549        echo $author;
    4650}
    4751
     
    5256 * @uses apply_filters() Calls the 'get_comment_author_email' hook on the comment author email
    5357 * @uses $comment
    5458 *
     59 * @param int $comment_ID The ID of the comment for which to get the author's email.  Optional.
    5560 * @return string The current comment author's email
    5661 */
    57 function get_comment_author_email() {
     62function get_comment_author_email( $comment_ID = 0 ) {
    5863        global $comment;
    59         return apply_filters('get_comment_author_email', $comment->comment_author_email);
     64        $_comment = empty( $comment_ID ) ? $comment : get_comment( $comment_ID );
     65        return apply_filters('get_comment_author_email', $_comment->comment_author_email);
    6066}
    6167
    6268/**
     
    7076 *
    7177 * @since 0.71
    7278 * @uses apply_filters() Calls 'author_email' hook on the author email
     79 *
     80 * @param int $comment_ID The ID of the comment for which to print the author's email. Optional.
    7381 */
    74 function comment_author_email() {
    75         echo apply_filters('author_email', get_comment_author_email() );
     82function comment_author_email( $comment_ID = 0 ) {
     83        echo apply_filters('author_email', get_comment_author_email( $comment_ID ) );
    7684}
    7785
    7886/**
     
    135143 * @since 1.5.0
    136144 * @uses apply_filters() Calls 'get_comment_author_link' hook on the complete link HTML or author
    137145 *
     146 * @param int $comment_ID The ID of the comment for which to get the author's link.  Optional.
    138147 * @return string Comment Author name or HTML link for author's URL
    139148 */
    140 function get_comment_author_link() {
     149function get_comment_author_link( $comment_ID = 0 ) {
    141150        /** @todo Only call these functions when they are needed. Include in if... else blocks */
    142         $url    = get_comment_author_url();
    143         $author = get_comment_author();
     151        $url    = get_comment_author_url( $comment_ID );
     152        $author = get_comment_author( $comment_ID );
    144153
    145154        if ( empty( $url ) || 'http://' == $url )
    146155                $return = $author;
     
    154163 *
    155164 * @since 0.71
    156165 * @see get_comment_author_link() Echos result
     166 *
     167 * @param int The ID of the comment for which to print the author's link. Optional.
    157168 */
    158 function comment_author_link() {
    159         echo get_comment_author_link();
     169function comment_author_link( $comment_ID = 0 ) {
     170        echo get_comment_author_link( $comment_ID );
    160171}
    161172
    162173/**
     
    166177 * @uses $comment
    167178 * @uses apply_filters()
    168179 *
    169  * @return unknown
     180 * @param int $comment_ID The ID of the comment for which to get the author's IP address. Optional.
     181 * @return string The comment author's IP address.
    170182 */
    171 function get_comment_author_IP() {
     183function get_comment_author_IP( $comment_ID = 0 ) {
    172184        global $comment;
    173         return apply_filters('get_comment_author_IP', $comment->comment_author_IP);
     185        $_comment = empty( $comment_ID ) ? $comment : get_comment( $comment_ID );
     186        return apply_filters('get_comment_author_IP', $_comment->comment_author_IP);
    174187}
    175188
    176189/**
     
    178191 *
    179192 * @since 0.71
    180193 * @see get_comment_author_IP() Echos Result
     194 *
     195 * @param int $comment_ID The ID of the comment for which to print the author's IP address.  Optional.
    181196 */
    182 function comment_author_IP() {
    183         echo get_comment_author_IP();
     197function comment_author_IP( $comment_ID = 0 ) {
     198        echo get_comment_author_IP( $comment_ID );
    184199}
    185200
    186201/**
     
    189204 * @since 1.5.0
    190205 * @uses apply_filters() Calls 'get_comment_author_url' hook on the comment author's URL
    191206 *
     207 * @param int $comment_ID The ID of the comment for which to get the author's URL.  Optional.
    192208 * @return string
    193209 */
    194 function get_comment_author_url() {
     210function get_comment_author_url( $comment_ID = 0 ) {
    195211        global $comment;
    196         $url = ('http://' == $comment->comment_author_url) ? '' : $comment->comment_author_url;
     212        $_comment = empty( $comment_ID ) ? $comment : get_comment( $comment_ID );
     213        $url = ('http://' == $_comment->comment_author_url) ? '' : $_comment->comment_author_url;
    197214        $url = esc_url( $url, array('http', 'https') );
    198215        return apply_filters('get_comment_author_url', $url);
    199216}
     
    204221 * @since 0.71
    205222 * @uses apply_filters()
    206223 * @uses get_comment_author_url() Retrieves the comment author's URL
     224 *
     225 * @param int $comment_ID The ID of the comment for which to print the author's URL. Optional.
    207226 */
    208 function comment_author_url() {
    209         echo apply_filters('comment_url', get_comment_author_url());
     227function comment_author_url( $comment_ID = 0 ) {
     228        echo apply_filters('comment_url', get_comment_author_url( $comment_ID ));
    210229}
    211230
    212231/**
     
    351370 * @uses $comment
    352371 *
    353372 * @param string $d The format of the date (defaults to user's config)
     373 * @param int $comment_ID The ID of the comment for which to get the date. Optional.
    354374 * @return string The comment's date
    355375 */
    356 function get_comment_date( $d = '' ) {
     376function get_comment_date( $d = '', $comment_ID = 0 ) {
    357377        global $comment;
     378        $_comment = empty( $comment_ID ) ? $comment : get_comment( $comment_ID );
    358379        if ( '' == $d )
    359                 $date = mysql2date(get_option('date_format'), $comment->comment_date);
     380                $date = mysql2date(get_option('date_format'), $_comment->comment_date);
    360381        else
    361                 $date = mysql2date($d, $comment->comment_date);
     382                $date = mysql2date($d, $_comment->comment_date);
    362383        return apply_filters('get_comment_date', $date, $d);
    363384}
    364385
     
    368389 * @since 0.71
    369390 *
    370391 * @param string $d The format of the date (defaults to user's config)
     392 * @param int $comment_ID The ID of the comment for which to print the date.  Optional.
    371393 */
    372 function comment_date( $d = '' ) {
    373         echo get_comment_date( $d );
     394function comment_date( $d = '', $comment_ID = 0 ) {
     395        echo get_comment_date( $d, $comment_ID );
    374396}
    375397
    376398/**
     
    384406 * @uses $comment
    385407 * @uses apply_filters() Calls 'get_comment_excerpt' on truncated comment
    386408 *
     409 * @param int $comment_ID The ID of the comment for which to get the excerpt. Optional.
    387410 * @return string The maybe truncated comment with 20 words or less
    388411 */
    389 function get_comment_excerpt() {
     412function get_comment_excerpt( $comment_ID = 0 ) {
    390413        global $comment;
    391         $comment_text = strip_tags($comment->comment_content);
     414        $_comment = empty( $comment_ID ) ? $comment : get_comment( $comment_ID );
     415        $comment_text = strip_tags($_comment->comment_content);
    392416        $blah = explode(' ', $comment_text);
    393417        if (count($blah) > 20) {
    394418                $k = 20;
     
    410434 *
    411435 * @since 1.2.0
    412436 * @uses apply_filters() Calls 'comment_excerpt' hook before displaying excerpt
     437 *
     438 * @param int $comment_ID The ID of the comment for which to print the excerpt. Optional.
    413439 */
    414 function comment_excerpt() {
     440function comment_excerpt( $comment_ID = 0 ) {
    415441        echo apply_filters('comment_excerpt', get_comment_excerpt() );
    416442}
    417443
     
    575601 * @since 1.5.0
    576602 * @uses $comment
    577603 *
     604 * @param int $comment_ID The ID of the comment for which to get the text. Optional.
    578605 * @return string The comment content
    579606 */
    580 function get_comment_text() {
     607function get_comment_text( $comment_ID = 0 ) {
    581608        global $comment;
    582         return apply_filters('get_comment_text', $comment->comment_content);
     609        $_comment = empty( $comment_ID ) ? $comment : get_comment( $comment_ID );
     610        return apply_filters('get_comment_text', $_comment->comment_content);
    583611}
    584612
    585613/**
     
    588616 * @since 0.71
    589617 * @uses apply_filters() Passes the comment content through the 'comment_text' hook before display
    590618 * @uses get_comment_text() Gets the comment content
     619 *
     620 * @param int $comment_ID The ID of the comment for which to print the text. Optional.
    591621 */
    592 function comment_text() {
     622function comment_text( $comment_ID = 0 ) {
    593623        echo apply_filters('comment_text', get_comment_text() );
    594624}
    595625
     
    633663 * @uses $comment
    634664 * @uses apply_filters() Calls the 'get_comment_type' hook on the comment type
    635665 *
     666 * @param int $comment_ID The ID of the comment for which to get the type. Optional.
    636667 * @return string The comment type
    637668 */
    638 function get_comment_type() {
     669function get_comment_type( $comment_ID = 0 ) {
    639670        global $comment;
    640671
    641         if ( '' == $comment->comment_type )
    642                 $comment->comment_type = 'comment';
     672        $_comment = empty( $comment_ID ) ? $comment : get_comment( $comment_ID );
     673        if ( '' == $_comment->comment_type )
     674                $_comment->comment_type = 'comment';
    643675
    644         return apply_filters('get_comment_type', $comment->comment_type);
     676        return apply_filters('get_comment_type', $_comment->comment_type);
    645677}
    646678
    647679/**