Index: wp-includes/comment-template.php
===================================================================
--- wp-includes/comment-template.php (revision 43212)
+++ wp-includes/comment-template.php (working copy)
@@ -824,11 +824,13 @@
* Display the link to the current post comments.
*
* @since 0.71
+ * @since 4.9.7 Added the `$post_id` parameter.
*
* @param string $deprecated Not Used.
* @param string $deprecated_2 Not Used.
+ * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
*/
-function comments_link( $deprecated = '', $deprecated_2 = '' ) {
+function comments_link( $deprecated = '', $deprecated_2 = '', $post_id = 0 ) {
if ( ! empty( $deprecated ) ) {
_deprecated_argument( __FUNCTION__, '0.72' );
}
@@ -835,7 +837,7 @@
if ( ! empty( $deprecated_2 ) ) {
_deprecated_argument( __FUNCTION__, '1.3.0' );
}
- echo esc_url( get_comments_link() );
+ echo esc_url( get_comments_link( $post_id ) );
}
/**
@@ -872,17 +874,19 @@
* Display the language string for the number of comments the current post has.
*
* @since 0.71
+ * @since 4.9.7 Added the `$post_id` parameter.
*
* @param string $zero Optional. Text for no comments. Default false.
* @param string $one Optional. Text for one comment. Default false.
* @param string $more Optional. Text for more than one comment. Default false.
* @param string $deprecated Not used.
+ * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
*/
-function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
+function comments_number( $zero = false, $one = false, $more = false, $deprecated = '', $post_id = 0 ) {
if ( ! empty( $deprecated ) ) {
_deprecated_argument( __FUNCTION__, '1.3.0' );
}
- echo get_comments_number_text( $zero, $one, $more );
+ echo get_comments_number_text( $zero, $one, $more, $post_id );
}
/**
@@ -889,13 +893,15 @@
* Display the language string for the number of comments the current post has.
*
* @since 4.0.0
+ * @since 4.9.7 Added the `$post_id` parameter.
*
* @param string $zero Optional. Text for no comments. Default false.
* @param string $one Optional. Text for one comment. Default false.
* @param string $more Optional. Text for more than one comment. Default false.
+ * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
*/
-function get_comments_number_text( $zero = false, $one = false, $more = false ) {
- $number = get_comments_number();
+function get_comments_number_text( $zero = false, $one = false, $more = false, $post_id = 0 ) {
+ $number = get_comments_number( $post_id );
if ( $number > 1 ) {
if ( false === $more ) {
@@ -1009,16 +1015,23 @@
* Retrieve the comment time of the current comment.
*
* @since 1.5.0
+ * @since 4.9.7 Added the `$comment_ID` parameter.
*
* @param string $d Optional. The format of the time. Default user's settings.
* @param bool $gmt Optional. Whether to use the GMT date. Default false.
* @param bool $translate Optional. Whether to translate the time (for use in feeds).
* Default true.
+ * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to retrieve the text.
+ * Default current comment.
* @return string The formatted time.
*/
-function get_comment_time( $d = '', $gmt = false, $translate = true ) {
- $comment = get_comment();
+function get_comment_time( $d = '', $gmt = false, $translate = true, $comment_ID = 0 ) {
+ $comment = get_comment( $comment_ID );
+ if ( null === $comment ) {
+ return '';
+ }
+
$comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
if ( '' == $d ) {
$date = mysql2date( get_option( 'time_format' ), $comment_date, $translate );
@@ -1044,11 +1057,14 @@
* Display the comment time of the current comment.
*
* @since 0.71
+ * @since 4.9.7 Added the `$comment_ID` parameter.
*
* @param string $d Optional. The format of the time. Default user's settings.
+ * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the text.
+ * Default current comment.
*/
-function comment_time( $d = '' ) {
- echo get_comment_time( $d );
+function comment_time( $d = '', $comment_ID = 0 ) {
+ echo get_comment_time( $d, false, true, $comment_ID );
}
/**
@@ -1514,6 +1530,7 @@
* Displays the link to the comments for the current post ID.
*
* @since 0.71
+ * @since 4.9.7 Added the `$post_id` parameter.
*
* @param string $zero Optional. String to display when no comments. Default false.
* @param string $one Optional. String to display when only one comment is available.
@@ -1523,10 +1540,16 @@
* @param string $css_class Optional. CSS class to use for comments. Default empty.
* @param string $none Optional. String to display when comments have been turned off.
* Default false.
+ * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
*/
-function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
- $id = get_the_ID();
- $title = get_the_title();
+function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false, $post_id = 0 ) {
+ if ( empty( $post_id ) ) {
+ $id = get_the_ID();
+ } else {
+ $id = $post_id;
+ }
+
+ $title = get_the_title( $id );
$number = get_comments_number( $id );
if ( false === $zero ) {
@@ -1550,12 +1573,12 @@
$none = sprintf( __( 'Comments Off on %s' ), $title );
}
- if ( 0 == $number && ! comments_open() && ! pings_open() ) {
+ if ( 0 == $number && ! comments_open( $id ) && ! pings_open( $id ) ) {
echo '' . $none . '';
return;
}
- if ( post_password_required() ) {
+ if ( post_password_required( $id ) ) {
_e( 'Enter your password to view comments.' );
return;
}
@@ -1562,7 +1585,7 @@
echo '';
- comments_number( $zero, $one, $more );
+ comments_number( $zero, $one, $more, '', $id );
echo '';
}