Make WordPress Core

Ticket #40143: 40143.patch

File 40143.patch, 30.2 KB (added by SergeyBiryukov, 8 years ago)
  • src/wp-includes/comment-template.php

     
    1919 *
    2020 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to retrieve the author.
    2121 *                                                                       Default current comment.
    22  * @return string The comment author
     22 * @return string The comment author.
    2323 */
    2424function get_comment_author( $comment_ID = 0 ) {
    2525        $comment = get_comment( $comment_ID );
    2626
    27         if ( empty( $comment->comment_author ) ) {
    28                 if ( $comment->user_id && $user = get_userdata( $comment->user_id ) )
     27        if ( $comment ) {
     28                if ( $comment->comment_author ) {
     29                        $author = $comment->comment_author;
     30                } elseif ( $comment->user_id && $user = get_userdata( $comment->user_id ) ) {
    2931                        $author = $user->display_name;
    30                 else
    31                         $author = __('Anonymous');
     32                } else {
     33                        $author = __( 'Anonymous' );
     34                }
    3235        } else {
    33                 $author = $comment->comment_author;
     36                $author = '';
    3437        }
    3538
     39        $comment_ID = ( $comment ) ? $comment->comment_ID : $comment_ID;
     40
    3641        /**
    3742         * Filters the returned comment author name.
    3843         *
     
    3944         * @since 1.5.0
    4045         * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
    4146         *
    42          * @param string     $author     The comment author's username.
    43          * @param int        $comment_ID The comment ID.
    44          * @param WP_Comment $comment    The comment object.
     47         * @param string          $author     The comment author's username.
     48         * @param int             $comment_ID The comment ID.
     49         * @param WP_Comment|null $comment    The comment object.
    4550         */
    46         return apply_filters( 'get_comment_author', $author, $comment->comment_ID, $comment );
     51        return apply_filters( 'get_comment_author', $author, $comment_ID, $comment );
    4752}
    4853
    4954/**
     
    5661 *                                                                       Default current comment.
    5762 */
    5863function comment_author( $comment_ID = 0 ) {
    59         $comment = get_comment( $comment_ID );
    60         $author  = get_comment_author( $comment );
     64        $comment    = get_comment( $comment_ID );
     65        $author     = ( $comment ) ? get_comment_author( $comment ) : '';
     66        $comment_ID = ( $comment ) ? $comment->comment_ID : $comment_ID;
    6167
    6268        /**
    6369         * Filters the comment author's name for display.
     
    6874         * @param string $author     The comment author's username.
    6975         * @param int    $comment_ID The comment ID.
    7076         */
    71         echo apply_filters( 'comment_author', $author, $comment->comment_ID );
     77        echo apply_filters( 'comment_author', $author, $comment_ID );
    7278}
    7379
    7480/**
     
    7985 *
    8086 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's email.
    8187 *                                                                       Default current comment.
    82  * @return string The current comment author's email
     88 * @return string The current comment author's email.
    8389 */
    8490function get_comment_author_email( $comment_ID = 0 ) {
    85         $comment = get_comment( $comment_ID );
     91        $comment      = get_comment( $comment_ID );
     92        $author_email = ( $comment ) ? $comment->comment_author_email : '';
     93        $comment_ID   = ( $comment ) ? $comment->comment_ID : $comment_ID;
    8694
    8795        /**
    8896         * Filters the comment author's returned email address.
     
    9098         * @since 1.5.0
    9199         * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
    92100         *
    93          * @param string     $comment_author_email The comment author's email address.
    94          * @param int        $comment_ID           The comment ID.
    95          * @param WP_Comment $comment              The comment object.
     101         * @param string          $author_email The comment author's email address.
     102         * @param int             $comment_ID   The comment ID.
     103         * @param WP_Comment|null $comment      The comment object.
    96104         */
    97         return apply_filters( 'get_comment_author_email', $comment->comment_author_email, $comment->comment_ID, $comment );
     105        return apply_filters( 'get_comment_author_email', $author_email, $comment_ID, $comment );
    98106}
    99107
    100108/**
     
    114122 */
    115123function comment_author_email( $comment_ID = 0 ) {
    116124        $comment      = get_comment( $comment_ID );
    117         $author_email = get_comment_author_email( $comment );
     125        $author_email = ( $comment ) ? get_comment_author_email( $comment ) : '';
     126        $comment_ID   = ( $comment ) ? $comment->comment_ID : $comment_ID;
    118127
    119128        /**
    120129         * Filters the comment author's email for display.
     
    125134         * @param string $author_email The comment author's email address.
    126135         * @param int    $comment_ID   The comment ID.
    127136         */
    128         echo apply_filters( 'author_email', $author_email, $comment->comment_ID );
     137        echo apply_filters( 'author_email', $author_email, $comment_ID );
    129138}
    130139
    131140/**
     
    173182 *                via the {@see 'comment_email'} filter with antispambot().
    174183 */
    175184function get_comment_author_email_link( $linktext = '', $before = '', $after = '', $comment = null ) {
    176         $comment = get_comment( $comment );
     185        $comment      = get_comment( $comment );
     186        $author_email = ( $comment ) ? $comment->comment_author_email : '';
    177187
    178188        /**
    179189         * Filters the comment author's email for display.
     
    184194         * @since 1.2.0
    185195         * @since 4.1.0 The `$comment` parameter was added.
    186196         *
    187          * @param string     $comment_author_email The comment author's email address.
    188          * @param WP_Comment $comment              The comment object.
     197         * @param string          $author_email The comment author's email address.
     198         * @param WP_Comment|null $comment      The comment object.
    189199         */
    190         $email = apply_filters( 'comment_email', $comment->comment_author_email, $comment );
     200        $email = apply_filters( 'comment_email', $author_email, $comment );
    191201
    192         if ((!empty($email)) && ($email != '@')) {
    193         $display = ($linktext != '') ? $linktext : $email;
     202        if ( $email && '@' !== $email ) {
     203                $display = ( $linktext ) ? $linktext : $email;
    194204                $return  = $before;
    195205                $return .= sprintf( '<a href="%1$s">%2$s</a>', esc_url( 'mailto:' . $email ), esc_html( $display ) );
    196206                $return .= $after;
     
    214224 * @return string The comment author name or HTML link for author's URL.
    215225 */
    216226function get_comment_author_link( $comment_ID = 0 ) {
    217         $comment = get_comment( $comment_ID );
    218         $url     = get_comment_author_url( $comment );
    219         $author  = get_comment_author( $comment );
     227        $comment    = get_comment( $comment_ID );
     228        $url        = ( $comment ) ? get_comment_author_url( $comment ) : '';
     229        $author     = ( $comment ) ? get_comment_author( $comment ) : '';
     230        $comment_ID = ( $comment ) ? $comment->comment_ID : $comment_ID;
    220231
    221232        if ( empty( $url ) || 'http://' == $url )
    222233                $return = $author;
     
    234245         * @param string $author     The comment author's username.
    235246         * @param int    $comment_ID The comment ID.
    236247         */
    237         return apply_filters( 'get_comment_author_link', $return, $author, $comment->comment_ID );
     248        return apply_filters( 'get_comment_author_link', $return, $author, $comment_ID );
    238249}
    239250
    240251/**
     
    261272 * @return string Comment author's IP address.
    262273 */
    263274function get_comment_author_IP( $comment_ID = 0 ) {
    264         $comment = get_comment( $comment_ID );
     275        $comment    = get_comment( $comment_ID );
     276        $author_IP  = ( $comment ) ? $comment->comment_author_IP : '';
     277        $comment_ID = ( $comment ) ? $comment->comment_ID : $comment_ID;
    265278
    266279        /**
    267280         * Filters the comment author's returned IP address.
     
    269282         * @since 1.5.0
    270283         * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
    271284         *
    272          * @param string     $comment_author_IP The comment author's IP address.
    273          * @param int        $comment_ID        The comment ID.
    274          * @param WP_Comment $comment           The comment object.
     285         * @param string          $author_IP The comment author's IP address.
     286         * @param int             $comment_ID The comment ID.
     287         * @param WP_Comment|null $comment    The comment object.
    275288         */
    276         return apply_filters( 'get_comment_author_IP', $comment->comment_author_IP, $comment->comment_ID, $comment );
     289        return apply_filters( 'get_comment_author_IP', $author_IP, $comment_ID, $comment );
    277290}
    278291
    279292/**
     
    301314 */
    302315function get_comment_author_url( $comment_ID = 0 ) {
    303316        $comment = get_comment( $comment_ID );
    304         $url = '';
    305         $id = 0;
    306         if ( ! empty( $comment ) ) {
    307                 $author_url = ( 'http://' == $comment->comment_author_url ) ? '' : $comment->comment_author_url;
    308                 $url = esc_url( $author_url, array( 'http', 'https' ) );
    309                 $id = $comment->ID;
     317
     318        if ( $comment && 'http://' !== $comment->comment_author_url ) {
     319                $author_url = esc_url( $comment->comment_author_url, array( 'http', 'https' ) );
     320        } else {
     321                $author_url = '';
    310322        }
    311323
     324        $comment_ID = ( $comment ) ? $comment->comment_ID : $comment_ID;
     325
    312326        /**
    313327         * Filters the comment author's URL.
    314328         *
     
    315329         * @since 1.5.0
    316330         * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
    317331         *
    318          * @param string     $url        The comment author's URL.
    319          * @param int        $comment_ID The comment ID.
    320          * @param WP_Comment $comment    The comment object.
     332         * @param string          $author_url The comment author's URL.
     333         * @param int             $comment_ID The comment ID.
     334         * @param WP_Comment|null $comment    The comment object.
    321335         */
    322         return apply_filters( 'get_comment_author_url', $url, $id, $comment );
     336        return apply_filters( 'get_comment_author_url', $author_url, $comment_ID, $comment );
    323337}
    324338
    325339/**
     
    333347 */
    334348function comment_author_url( $comment_ID = 0 ) {
    335349        $comment    = get_comment( $comment_ID );
    336         $author_url = get_comment_author_url( $comment );
     350        $author_url = ( $comment ) ? get_comment_author_url( $comment ) : '';
     351        $comment_ID = ( $comment ) ? $comment->comment_ID : $comment_ID;
    337352
    338353        /**
    339354         * Filters the comment author's URL for display.
     
    344359         * @param string $author_url The comment author's URL.
    345360         * @param int    $comment_ID The comment ID.
    346361         */
    347         echo apply_filters( 'comment_url', $author_url, $comment->comment_ID );
     362        echo apply_filters( 'comment_url', $author_url, $comment_ID );
    348363}
    349364
    350365/**
     
    372387 */
    373388function get_comment_author_url_link( $linktext = '', $before = '', $after = '', $comment = 0 ) {
    374389        $url = get_comment_author_url( $comment );
    375         $display = ($linktext != '') ? $linktext : $url;
     390
     391        $display = ( $linktext ) ? $linktext : $url;
    376392        $display = str_replace( 'http://www.', '', $display );
    377393        $display = str_replace( 'http://', '', $display );
    378394
    379         if ( '/' == substr($display, -1) ) {
    380                 $display = substr($display, 0, -1);
     395        if ( '/' == substr( $display, -1 ) ) {
     396                $display = substr( $display, 0, -1 );
    381397        }
    382398
    383399        $return = "$before<a href='$url' rel='external'>$display</a>$after";
     
    531547 * @since 1.5.0
    532548 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
    533549 *
    534  * @param string          $d          Optional. The format of the date. Default user's setting.
    535  * @param int|WP_Comment  $comment_ID WP_Comment or ID of the comment for which to get the date.
    536  *                                    Default current comment.
     550 * @param string          $date_format Optional. The format of the date. Default user's setting.
     551 * @param int|WP_Comment  $comment_ID  WP_Comment or ID of the comment for which to get the date.
     552 *                                     Default current comment.
    537553 * @return string The comment's date.
    538554 */
    539 function get_comment_date( $d = '', $comment_ID = 0 ) {
     555function get_comment_date( $date_format = '', $comment_ID = 0 ) {
    540556        $comment = get_comment( $comment_ID );
    541         if ( '' == $d )
    542                 $date = mysql2date(get_option('date_format'), $comment->comment_date);
    543         else
    544                 $date = mysql2date($d, $comment->comment_date);
     557
     558        if ( $comment ) {
     559                if ( ! $date_format ) {
     560                        $date = mysql2date( get_option( 'date_format' ), $comment->comment_date );
     561                } else {
     562                        $date = mysql2date( $date_format, $comment->comment_date );
     563                }
     564        } else {
     565                $date = '';
     566        }
     567
    545568        /**
    546569         * Filters the returned comment date.
    547570         *
    548571         * @since 1.5.0
    549572         *
    550          * @param string|int $date    Formatted date string or Unix timestamp.
    551          * @param string     $d      The format of the date.
    552          * @param WP_Comment $comment The comment object.
     573         * @param string|int      $date        Formatted date string or Unix timestamp.
     574         * @param string          $date_format The format of the date.
     575         * @param WP_Comment|null $comment    The comment object.
    553576         */
    554         return apply_filters( 'get_comment_date', $date, $d, $comment );
     577        return apply_filters( 'get_comment_date', $date, $date_format, $comment );
    555578}
    556579
    557580/**
     
    560583 * @since 0.71
    561584 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
    562585 *
    563  * @param string         $d          Optional. The format of the date. Default user's settings.
    564  * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the date.
    565  *                                   Default current comment.
     586 * @param string         $date_format Optional. The format of the date. Default user's settings.
     587 * @param int|WP_Comment $comment_ID  WP_Comment or ID of the comment for which to print the date.
     588 *                                    Default current comment.
    566589 */
    567 function comment_date( $d = '', $comment_ID = 0 ) {
    568         echo get_comment_date( $d, $comment_ID );
     590function comment_date( $date_format = '', $comment_ID = 0 ) {
     591        echo get_comment_date( $date_format, $comment_ID );
    569592}
    570593
    571594/**
     
    583606 * @return string The maybe truncated comment with 20 words or less.
    584607 */
    585608function get_comment_excerpt( $comment_ID = 0 ) {
    586         $comment = get_comment( $comment_ID );
    587         $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment->comment_content ) );
     609        $comment      = get_comment( $comment_ID );
     610        $comment_text = ( $comment ) ? $comment->comment_content : '';
     611        $comment_ID   = ( $comment ) ? $comment->comment_ID : $comment_ID;
     612
     613        $comment_text = strip_tags( str_replace( array( "\n", "\r" ), ' ', $comment_text ) );
     614
    588615        $words = explode( ' ', $comment_text );
    589616
    590617        /**
     
    611638         * @since 1.5.0
    612639         * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
    613640         *
    614          * @param string     $excerpt    The comment excerpt text.
    615          * @param int        $comment_ID The comment ID.
    616          * @param WP_Comment $comment    The comment object.
     641         * @param string          $excerpt    The comment excerpt text.
     642         * @param int             $comment_ID The comment ID.
     643         * @param WP_Comment|null $comment    The comment object.
    617644         */
    618         return apply_filters( 'get_comment_excerpt', $excerpt, $comment->comment_ID, $comment );
     645        return apply_filters( 'get_comment_excerpt', $excerpt, $comment_ID, $comment );
    619646}
    620647
    621648/**
     
    629656 */
    630657function comment_excerpt( $comment_ID = 0 ) {
    631658        $comment         = get_comment( $comment_ID );
    632         $comment_excerpt = get_comment_excerpt( $comment );
     659        $comment_excerpt = ( $comment ) ? get_comment_excerpt( $comment ) : '';
     660        $comment_ID      = ( $comment ) ? $comment->comment_ID : $comment_ID;
    633661
    634662        /**
    635663         * Filters the comment excerpt for display.
     
    640668         * @param string $comment_excerpt The comment excerpt text.
    641669         * @param int    $comment_ID      The comment ID.
    642670         */
    643         echo apply_filters( 'comment_excerpt', $comment_excerpt, $comment->comment_ID );
     671        echo apply_filters( 'comment_excerpt', $comment_excerpt, $comment_ID );
    644672}
    645673
    646674/**
     
    651679 * @return int The comment ID.
    652680 */
    653681function get_comment_ID() {
    654         $comment = get_comment();
     682        $comment    = get_comment();
     683        $comment_ID = ( $comment ) ? $comment->comment_ID : 0;
    655684
    656685        /**
    657686         * Filters the returned comment ID.
     
    659688         * @since 1.5.0
    660689         * @since 4.1.0 The `$comment_ID` parameter was added.
    661690         *
    662          * @param int        $comment_ID The current comment ID.
    663          * @param WP_Comment $comment    The comment object.
     691         * @param int             $comment_ID The current comment ID.
     692         * @param WP_Comment|null $comment    The comment object.
    664693         */
    665         return apply_filters( 'get_comment_ID', $comment->comment_ID, $comment );
     694        return apply_filters( 'get_comment_ID', $comment_ID, $comment );
    666695}
    667696
    668697/**
     
    702731function get_comment_link( $comment = null, $args = array() ) {
    703732        global $wp_rewrite, $in_comment_loop;
    704733
    705         $comment = get_comment($comment);
     734        $comment = get_comment( $comment );
    706735
    707736        // Back-compat.
    708737        if ( ! is_array( $args ) ) {
     
    718747        );
    719748        $args = wp_parse_args( $args, $defaults );
    720749
    721         $link = get_permalink( $comment->comment_post_ID );
     750        $link = ( $comment ) ? get_permalink( $comment->comment_post_ID ) : '';
    722751
    723752        // The 'cpage' param takes precedence.
    724753        if ( ! is_null( $args['cpage'] ) ) {
     
    742771                                $cpage = get_query_var( 'cpage' );
    743772                        } else {
    744773                                // Requires a database hit, so we only do it when we can't figure out from context.
    745                                 $cpage = get_page_of_comment( $comment->comment_ID, $args );
     774                                $cpage = ( $comment ) ? get_page_of_comment( $comment->comment_ID, $args ) : 0;
    746775                        }
    747776                }
    748777
     
    768797
    769798        }
    770799
    771         if ( $wp_rewrite->using_permalinks() ) {
     800        if ( $link && $wp_rewrite->using_permalinks() ) {
    772801                $link = user_trailingslashit( $link, 'comment' );
    773802        }
    774803
    775         $link = $link . '#comment-' . $comment->comment_ID;
     804        $link = ( $link ) ? $link . '#comment-' . $comment->comment_ID : '';
    776805
    777806        /**
    778807         * Filters the returned single comment permalink.
     
    782811         *
    783812         * @see get_page_of_comment()
    784813         *
    785          * @param string     $link    The comment permalink with '#comment-$id' appended.
    786          * @param WP_Comment $comment The current comment object.
    787          * @param array      $args    An array of arguments to override the defaults.
    788          * @param int        $cpage   The calculated 'cpage' value.
     814         * @param string          $link    The comment permalink with '#comment-$id' appended.
     815         * @param WP_Comment|null $comment The current comment object.
     816         * @param array           $args    An array of arguments to override the defaults.
     817         * @param int             $cpage   The calculated 'cpage' value.
    789818         */
    790819        return apply_filters( 'get_comment_link', $link, $comment, $args, $cpage );
    791820}
     
    949978 * @return string The comment content.
    950979 */
    951980function get_comment_text( $comment_ID = 0, $args = array() ) {
    952         $comment = get_comment( $comment_ID );
     981        $comment      = get_comment( $comment_ID );
     982        $comment_text = ( $comment ) ? $comment->comment_content : '';
    953983
    954984        /**
    955985         * Filters the text of a comment.
     
    958988         *
    959989         * @see Walker_Comment::comment()
    960990         *
    961          * @param string     $comment_content Text of the comment.
    962          * @param WP_Comment $comment         The comment object.
    963          * @param array      $args            An array of arguments.
     991         * @param string          $comment_content Text of the comment.
     992         * @param WP_Comment|null $comment         The comment object.
     993         * @param array           $args            An array of arguments.
    964994         */
    965         return apply_filters( 'get_comment_text', $comment->comment_content, $comment, $args );
     995        return apply_filters( 'get_comment_text', $comment_text, $comment, $args );
    966996}
    967997
    968998/**
     
    9781008 * @param array           $args       Optional. An array of arguments. Default empty array. Default empty.
    9791009 */
    9801010function comment_text( $comment_ID = 0, $args = array() ) {
    981         $comment = get_comment( $comment_ID );
     1011        $comment      = get_comment( $comment_ID );
     1012        $comment_text = ( $comment ) ? get_comment_text( $comment, $args ) : '';
    9821013
    983         $comment_text = get_comment_text( $comment, $args );
    9841014        /**
    9851015         * Filters the text of a comment to be displayed.
    9861016         *
     
    9881018         *
    9891019         * @see Walker_Comment::comment()
    9901020         *
    991          * @param string     $comment_text Text of the current comment.
    992          * @param WP_Comment $comment      The comment object.
    993          * @param array      $args         An array of arguments.
     1021         * @param string          $comment_text Text of the current comment.
     1022         * @param WP_Comment|null $comment      The comment object.
     1023         * @param array           $args         An array of arguments.
    9941024         */
    9951025        echo apply_filters( 'comment_text', $comment_text, $comment, $args );
    9961026}
     
    10001030 *
    10011031 * @since 1.5.0
    10021032 *
    1003  * @param string $d        Optional. The format of the time. Default user's settings.
    1004  * @param bool   $gmt       Optional. Whether to use the GMT date. Default false.
    1005  * @param bool   $translate Optional. Whether to translate the time (for use in feeds).
    1006  *                          Default true.
     1033 * @param string $time_format Optional. The format of the time. Default user's settings.
     1034 * @param bool   $gmt         Optional. Whether to use the GMT date. Default false.
     1035 * @param bool   $translate   Optional. Whether to translate the time (for use in feeds).
     1036 *                            Default true.
    10071037 * @return string The formatted time.
    10081038 */
    1009 function get_comment_time( $d = '', $gmt = false, $translate = true ) {
     1039function get_comment_time( $time_format = '', $gmt = false, $translate = true ) {
    10101040        $comment = get_comment();
    10111041
    1012         $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
    1013         if ( '' == $d )
    1014                 $date = mysql2date(get_option('time_format'), $comment_date, $translate);
    1015         else
    1016                 $date = mysql2date($d, $comment_date, $translate);
     1042        if ( $comment ) {
     1043                $comment_time = ( $gmt ) ? $comment->comment_date_gmt : $comment->comment_date;
     1044                if ( ! $time_format ) {
     1045                        $time = mysql2date( get_option( 'time_format' ), $comment_time, $translate );
     1046                } else {
     1047                        $time = mysql2date( $time_format, $comment_time, $translate );
     1048                }
     1049        } else {
     1050                $time = '';
     1051        }
    10171052
    10181053        /**
    10191054         * Filters the returned comment time.
     
    10201055         *
    10211056         * @since 1.5.0
    10221057         *
    1023          * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
    1024          * @param string     $d         Date format.
    1025          * @param bool       $gmt       Whether the GMT date is in use.
    1026          * @param bool       $translate Whether the time is translated.
    1027          * @param WP_Comment $comment   The comment object.
     1058         * @param string|int      $time        The comment time, formatted as a date string or Unix timestamp.
     1059         * @param string          $time_format Time format.
     1060         * @param bool            $gmt         Whether the GMT date is in use.
     1061         * @param bool            $translate  Whether the time is translated.
     1062         * @param WP_Comment|null $comment     The comment object.
    10281063         */
    1029         return apply_filters( 'get_comment_time', $date, $d, $gmt, $translate, $comment );
     1064        return apply_filters( 'get_comment_time', $time, $time_format, $gmt, $translate, $comment );
    10301065}
    10311066
    10321067/**
     
    10341069 *
    10351070 * @since 0.71
    10361071 *
    1037  * @param string $d Optional. The format of the time. Default user's settings.
     1072 * @param string $time_format Optional. The format of the time. Default user's settings.
    10381073 */
    1039 function comment_time( $d = '' ) {
    1040         echo get_comment_time($d);
     1074function comment_time( $time_format = '' ) {
     1075        echo get_comment_time( $time_format );
    10411076}
    10421077
    10431078/**
     
    10521087 */
    10531088function get_comment_type( $comment_ID = 0 ) {
    10541089        $comment = get_comment( $comment_ID );
    1055         if ( '' == $comment->comment_type )
    1056                 $comment->comment_type = 'comment';
    10571090
     1091        if ( $comment ) {
     1092                $comment_type = ( $comment->comment_type ) ? $comment->comment_type : 'comment';
     1093        } else {
     1094                $comment_type = '';
     1095        }
     1096
     1097        $comment_ID = ( $comment ) ? $comment->comment_ID : $comment_ID;
     1098
    10581099        /**
    10591100         * Filters the returned comment type.
    10601101         *
     
    10611102         * @since 1.5.0
    10621103         * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
    10631104         *
    1064          * @param string     $comment_type The type of comment, such as 'comment', 'pingback', or 'trackback'.
    1065          * @param int        $comment_ID   The comment ID.
    1066          * @param WP_Comment $comment      The comment object.
     1105         * @param string          $comment_type The type of comment, such as 'comment', 'pingback', or 'trackback'.
     1106         * @param int             $comment_ID   The comment ID.
     1107         * @param WP_Comment|null $comment      The comment object.
    10671108         */
    1068         return apply_filters( 'get_comment_type', $comment->comment_type, $comment->comment_ID, $comment );
     1109        return apply_filters( 'get_comment_type', $comment_type, $comment_ID, $comment );
    10691110}
    10701111
    10711112/**
     
    16091650
    16101651        $comment = get_comment( $comment );
    16111652
    1612         if ( empty( $post ) ) {
     1653        if ( ! $post && $comment ) {
    16131654                $post = $comment->comment_post_ID;
    16141655        }
    16151656
     
    16241665         *
    16251666         * @since 4.1.0
    16261667         *
    1627          * @param array      $args    Comment reply link arguments. See get_comment_reply_link()
    1628          *                            for more information on accepted arguments.
    1629          * @param WP_Comment $comment The object of the comment being replied to.
    1630          * @param WP_Post    $post    The WP_Post object.
     1668         * @param array           $args    Comment reply link arguments. See get_comment_reply_link()
     1669         *                                 for more information on accepted arguments.
     1670         * @param WP_Comment|null $comment The object of the comment being replied to.
     1671         * @param WP_Post         $post    The WP_Post object.
    16311672         */
    16321673        $args = apply_filters( 'comment_reply_link_args', $args, $comment, $post );
    16331674
     
    16361677                        esc_url( wp_login_url( get_permalink() ) ),
    16371678                        $args['login_text']
    16381679                );
    1639         } else {
     1680        } elseif ( $comment ) {
    16401681                $onclick = sprintf( 'return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )',
    16411682                        $args['add_below'], $comment->comment_ID, $args['respond_id'], $post->ID
    16421683                );
     
    16471688                        esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ),
    16481689                        $args['reply_text']
    16491690                );
     1691        } else {
     1692                $link = '';
    16501693        }
    16511694
    16521695        /**
     
    16541697         *
    16551698         * @since 2.7.0
    16561699         *
    1657          * @param string  $link    The HTML markup for the comment reply link.
    1658          * @param array   $args    An array of arguments overriding the defaults.
    1659          * @param object  $comment The object of the comment being replied.
    1660          * @param WP_Post $post    The WP_Post object.
     1700         * @param string          $link    The HTML markup for the comment reply link.
     1701         * @param array           $args    An array of arguments overriding the defaults.
     1702         * @param WP_Comment|null $comment The object of the comment being replied to.
     1703         * @param WP_Post         $post    The WP_Post object.
    16611704         */
    16621705        return apply_filters( 'comment_reply_link', $args['before'] . $link . $args['after'], $args, $comment, $post );
    16631706}
  • tests/phpunit/tests/comment/getCommentCount.php

     
    11<?php
    22
     3/**
     4 * @group comment
     5 */
    36class Tests_Get_Comment_Count extends WP_UnitTestCase {
    47
    58        public function test_get_comment_count() {
  • tests/phpunit/tests/comment/getCommentExcerpt.php

     
    11<?php
    22
     3/**
     4 * @group comment
     5 */
    36class Tests_Get_Comment_Excerpt extends WP_UnitTestCase {
    47        protected static $bacon_comment;
    58
     
    2326                $this->assertEquals( 20, count( explode( ' ', $excerpt ) ) );
    2427        }
    2528
     29        public function test_get_comment_excerpt_with_non_existing_id() {
     30                $comment_id = self::factory()->comment->create( array(
     31                        'comment_content' => self::$bacon_comment
     32                ) );
     33
     34                $this->assertEquals( '', get_comment_excerpt( -1 ) );
     35        }
     36
    2637        public function test_get_comment_excerpt_filtered() {
    2738                $comment_id = self::factory()->comment->create( array(
    2839                        'comment_content' => self::$bacon_comment
  • tests/phpunit/tests/comment/getCommentText.php

     
     1<?php
     2
     3/**
     4 * @group comment
     5 */
     6class Tests_Get_Comment_Text extends WP_UnitTestCase {
     7        protected static $bacon_comment;
     8
     9        public static function setUpBeforeClass() {
     10                parent::setUpBeforeClass();
     11
     12                self::$bacon_comment = 'Bacon ipsum dolor amet porchetta capicola sirloin prosciutto brisket shankle jerky. Ham hock filet mignon boudin ground round, prosciutto alcatra spare ribs meatball turducken pork beef ribs ham beef. Bacon pastrami short loin, venison tri-tip ham short ribs doner swine. Tenderloin pig tongue pork jowl doner. Pork loin rump t-bone, beef strip steak flank drumstick tri-tip short loin capicola jowl. Cow filet mignon hamburger doner rump. Short loin jowl drumstick, tongue tail beef ribs pancetta flank brisket landjaeger chuck venison frankfurter turkey.
     13
     14Brisket shank rump, tongue beef ribs swine fatback turducken capicola meatball picanha chicken cupim meatloaf turkey. Bacon biltong shoulder tail frankfurter boudin cupim turkey drumstick. Porchetta pig shoulder, jerky flank pork tail meatball hamburger. Doner ham hock ribeye tail jerky swine. Leberkas ribeye pancetta, tenderloin capicola doner turducken chicken venison ground round boudin pork chop. Tail pork loin pig spare ribs, biltong ribeye brisket pork chop cupim. Short loin leberkas spare ribs jowl landjaeger tongue kevin flank bacon prosciutto.
     15
     16Shankle pork chop prosciutto ribeye ham hock pastrami. T-bone shank brisket bacon pork chop. Cupim hamburger pork loin short loin. Boudin ball tip cupim ground round ham shoulder. Sausage rump cow tongue bresaola pork pancetta biltong tail chicken turkey hamburger. Kevin flank pork loin salami biltong. Alcatra landjaeger pastrami andouille kielbasa ham tenderloin drumstick sausage turducken tongue corned beef.';
     17        }
     18
     19        public function test_get_comment_text() {
     20                $comment_id = self::factory()->comment->create( array(
     21                        'comment_content' => self::$bacon_comment
     22                ) );
     23
     24                $this->assertEquals( self::$bacon_comment, get_comment_text( $comment_id ) );
     25        }
     26
     27        public function test_get_comment_text_with_non_existing_id() {
     28                $comment_id = self::factory()->comment->create( array(
     29                        'comment_content' => self::$bacon_comment
     30                ) );
     31
     32                $this->assertEquals( '', get_comment_text( -1 ) );
     33        }
     34}
  • tests/phpunit/tests/comment/metaCache.php

     
    11<?php
    22
     3/**
     4 * @group comment
     5 */
    36class Tests_Comment_Meta_Cache extends WP_UnitTestCase {
    47        protected $i = 0;
    58        protected $queries = 0;
  • tests/phpunit/tests/comment/wpCountComments.php

     
    11<?php
    22
     3/**
     4 * @group comment
     5 */
    36class Tests_WP_Count_Comments extends WP_UnitTestCase {
    47
    58        public function test_wp_count_comments() {