Make WordPress Core

Ticket #44485: comment-template.php.patch

File comment-template.php.patch, 6.7 KB (added by tristanleboss, 5 years ago)

Patch for some functions in comments-template.php

  • wp-includes/comment-template.php

     
    824824 * Display the link to the current post comments.
    825825 *
    826826 * @since 0.71
     827 * @since 4.9.7 Added the `$post_id` parameter.
    827828 *
    828829 * @param string $deprecated   Not Used.
    829830 * @param string $deprecated_2 Not Used.
     831 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
    830832 */
    831 function comments_link( $deprecated = '', $deprecated_2 = '' ) {
     833function comments_link( $deprecated = '', $deprecated_2 = '', $post_id = 0 ) {
    832834        if ( ! empty( $deprecated ) ) {
    833835                _deprecated_argument( __FUNCTION__, '0.72' );
    834836        }
     
    835837        if ( ! empty( $deprecated_2 ) ) {
    836838                _deprecated_argument( __FUNCTION__, '1.3.0' );
    837839        }
    838         echo esc_url( get_comments_link() );
     840        echo esc_url( get_comments_link( $post_id ) );
    839841}
    840842
    841843/**
     
    872874 * Display the language string for the number of comments the current post has.
    873875 *
    874876 * @since 0.71
     877 * @since 4.9.7 Added the `$post_id` parameter.
    875878 *
    876879 * @param string $zero       Optional. Text for no comments. Default false.
    877880 * @param string $one        Optional. Text for one comment. Default false.
    878881 * @param string $more       Optional. Text for more than one comment. Default false.
    879882 * @param string $deprecated Not used.
     883 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
    880884 */
    881 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
     885function comments_number( $zero = false, $one = false, $more = false, $deprecated = '', $post_id = 0 ) {
    882886        if ( ! empty( $deprecated ) ) {
    883887                _deprecated_argument( __FUNCTION__, '1.3.0' );
    884888        }
    885         echo get_comments_number_text( $zero, $one, $more );
     889        echo get_comments_number_text( $zero, $one, $more, $post_id );
    886890}
    887891
    888892/**
     
    889893 * Display the language string for the number of comments the current post has.
    890894 *
    891895 * @since 4.0.0
     896 * @since 4.9.7 Added the `$post_id` parameter.
    892897 *
    893898 * @param string $zero Optional. Text for no comments. Default false.
    894899 * @param string $one  Optional. Text for one comment. Default false.
    895900 * @param string $more Optional. Text for more than one comment. Default false.
     901 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
    896902 */
    897 function get_comments_number_text( $zero = false, $one = false, $more = false ) {
    898         $number = get_comments_number();
     903function get_comments_number_text( $zero = false, $one = false, $more = false, $post_id = 0 ) {
     904        $number = get_comments_number( $post_id );
    899905
    900906        if ( $number > 1 ) {
    901907                if ( false === $more ) {
     
    10091015 * Retrieve the comment time of the current comment.
    10101016 *
    10111017 * @since 1.5.0
     1018 * @since 4.9.7 Added the `$comment_ID` parameter.
    10121019 *
    10131020 * @param string $d         Optional. The format of the time. Default user's settings.
    10141021 * @param bool   $gmt       Optional. Whether to use the GMT date. Default false.
    10151022 * @param bool   $translate Optional. Whether to translate the time (for use in feeds).
    10161023 *                          Default true.
     1024 * @param int|WP_Comment  $comment_ID WP_Comment or ID of the comment for which to retrieve the text.
     1025 *                                    Default current comment.
    10171026 * @return string The formatted time.
    10181027 */
    1019 function get_comment_time( $d = '', $gmt = false, $translate = true ) {
    1020         $comment = get_comment();
     1028function get_comment_time( $d = '', $gmt = false, $translate = true, $comment_ID = 0 ) {
     1029        $comment = get_comment( $comment_ID );
    10211030
     1031        if ( null === $comment ) {
     1032                return '';
     1033        }
     1034
    10221035        $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
    10231036        if ( '' == $d ) {
    10241037                $date = mysql2date( get_option( 'time_format' ), $comment_date, $translate );
     
    10441057 * Display the comment time of the current comment.
    10451058 *
    10461059 * @since 0.71
     1060 * @since 4.9.7 Added the `$comment_ID` parameter.
    10471061 *
    10481062 * @param string $d Optional. The format of the time. Default user's settings.
     1063 * @param int|WP_Comment  $comment_ID WP_Comment or ID of the comment for which to print the text.
     1064 *                                    Default current comment.
    10491065 */
    1050 function comment_time( $d = '' ) {
    1051         echo get_comment_time( $d );
     1066function comment_time( $d = '', $comment_ID = 0 ) {
     1067        echo get_comment_time( $d, false, true, $comment_ID );
    10521068}
    10531069
    10541070/**
     
    15141530 * Displays the link to the comments for the current post ID.
    15151531 *
    15161532 * @since 0.71
     1533 * @since 4.9.7 Added the `$post_id` parameter.
    15171534 *
    15181535 * @param string $zero      Optional. String to display when no comments. Default false.
    15191536 * @param string $one       Optional. String to display when only one comment is available.
     
    15231540 * @param string $css_class Optional. CSS class to use for comments. Default empty.
    15241541 * @param string $none      Optional. String to display when comments have been turned off.
    15251542 *                          Default false.
     1543 * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
    15261544 */
    1527 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
    1528         $id     = get_the_ID();
    1529         $title  = get_the_title();
     1545function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false, $post_id = 0 ) {
     1546        if ( empty( $post_id ) ) {
     1547                $id = get_the_ID();
     1548        } else {
     1549                $id = $post_id;
     1550        }
     1551
     1552        $title  = get_the_title( $id );
    15301553        $number = get_comments_number( $id );
    15311554
    15321555        if ( false === $zero ) {
     
    15501573                $none = sprintf( __( 'Comments Off<span class="screen-reader-text"> on %s</span>' ), $title );
    15511574        }
    15521575
    1553         if ( 0 == $number && ! comments_open() && ! pings_open() ) {
     1576        if ( 0 == $number && ! comments_open( $id ) && ! pings_open( $id ) ) {
    15541577                echo '<span' . ( ( ! empty( $css_class ) ) ? ' class="' . esc_attr( $css_class ) . '"' : '' ) . '>' . $none . '</span>';
    15551578                return;
    15561579        }
    15571580
    1558         if ( post_password_required() ) {
     1581        if ( post_password_required( $id ) ) {
    15591582                _e( 'Enter your password to view comments.' );
    15601583                return;
    15611584        }
     
    15621585
    15631586        echo '<a href="';
    15641587        if ( 0 == $number ) {
    1565                 $respond_link = get_permalink() . '#respond';
     1588                $respond_link = get_permalink( $id ) . '#respond';
    15661589                /**
    15671590                 * Filters the respond link when a post has no comments.
    15681591                 *
     
    15731596                 */
    15741597                echo apply_filters( 'respond_link', $respond_link, $id );
    15751598        } else {
    1576                 comments_link();
     1599                comments_link( '', '', $id );
    15771600        }
    15781601        echo '"';
    15791602
     
    15921615        echo apply_filters( 'comments_popup_link_attributes', $attributes );
    15931616
    15941617        echo '>';
    1595         comments_number( $zero, $one, $more );
     1618        comments_number( $zero, $one, $more, '', $id );
    15961619        echo '</a>';
    15971620}
    15981621