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 );
}
/**
@@ -1084,12 +1100,15 @@
* Display the comment type of the current comment.
*
* @since 0.71
+ * @since 4.9.7 Added the `$comment_ID` parameter.
*
* @param string $commenttxt Optional. String to display for comment type. Default false.
* @param string $trackbacktxt Optional. String to display for trackback type. Default false.
* @param string $pingbacktxt Optional. String to display for pingback type. Default false.
+ * @param int|WP_Comment $comment_ID WP_Comment or ID of the comment for which to print the text.
+ * Default current comment.
*/
-function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false ) {
+function comment_type( $commenttxt = false, $trackbacktxt = false, $pingbacktxt = false, $comment_ID = 0 ) {
if ( false === $commenttxt ) {
$commenttxt = _x( 'Comment', 'noun' );
}
@@ -1099,7 +1118,7 @@
if ( false === $pingbacktxt ) {
$pingbacktxt = __( 'Pingback' );
}
- $type = get_comment_type();
+ $type = get_comment_type( $comment_ID );
switch ( $type ) {
case 'trackback':
echo $trackbacktxt;
@@ -1120,14 +1139,20 @@
* current post is used and appended to the correct page to go to.
*
* @since 1.5.0
+ * @since 4.9.7 Added the `$post_id` parameter.
*
+ * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
* @return string The trackback URL after being filtered.
*/
-function get_trackback_url() {
+function get_trackback_url( $post_id = 0 ) {
+ if ( empty( $post_id ) ) {
+ $post_id = get_the_ID();
+ }
+
if ( '' != get_option( 'permalink_structure' ) ) {
- $tb_url = trailingslashit( get_permalink() ) . user_trailingslashit( 'trackback', 'single_trackback' );
+ $tb_url = trailingslashit( get_permalink( $post_id ) ) . user_trailingslashit( 'trackback', 'single_trackback' );
} else {
- $tb_url = get_option( 'siteurl' ) . '/wp-trackback.php?p=' . get_the_ID();
+ $tb_url = get_option( 'siteurl' ) . '/wp-trackback.php?p=' . $post_id;
}
/**
@@ -1144,12 +1169,14 @@
* Display the current post's trackback URL.
*
* @since 0.71
+ * @since 4.9.7 Added the `$post_id` parameter.
*
* @param bool $deprecated_echo Not used.
+ * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
* @return void|string Should only be used to echo the trackback URL, use get_trackback_url()
* for the result instead.
*/
-function trackback_url( $deprecated_echo = true ) {
+function trackback_url( $deprecated_echo = true, $post_id = 0 ) {
if ( true !== $deprecated_echo ) {
_deprecated_argument(
__FUNCTION__, '2.5.0',
@@ -1162,9 +1189,9 @@
}
if ( $deprecated_echo ) {
- echo get_trackback_url();
+ echo get_trackback_url( $post_id );
} else {
- return get_trackback_url();
+ return get_trackback_url( $post_id );
}
}
@@ -1174,10 +1201,12 @@
* Deprecated in 3.0.0, and restored in 3.0.1.
*
* @since 0.71
+ * @since 4.9.7 Added the `$post_id` parameter.
*
* @param int $deprecated Not used (Was $timezone = 0).
+ * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
*/
-function trackback_rdf( $deprecated = '' ) {
+function trackback_rdf( $deprecated = '', $post_id = 0 ) {
if ( ! empty( $deprecated ) ) {
_deprecated_argument( __FUNCTION__, '2.5.0' );
}
@@ -1186,17 +1215,21 @@
return;
}
+ if ( empty( $post_id ) ) {
+ $post_id = get_the_ID();
+ }
+
echo '
\n";
+ echo ' dc:title="' . str_replace( '--', '--', wptexturize( strip_tags( get_the_title( $post_id ) ) ) ) . '"' . "\n";
+ echo ' trackback:ping="' . get_trackback_url( $post_id ) . '"' . " />\n";
echo '';
}
@@ -1273,11 +1306,22 @@
* Backported to 2.0.10.
*
* @since 2.1.3
+ * @since 4.9.7 Added the `$post_id` parameter.
+ *
+ * @param int|WP_Post $post_id Optional. Post ID or WP_Post object. Default is global $post.
*/
-function wp_comment_form_unfiltered_html_nonce() {
- $post = get_post();
- $post_id = $post ? $post->ID : 0;
+function wp_comment_form_unfiltered_html_nonce( $post_id = 0 ) {
+ if ( empty( $post_id ) ) {
+ $post_id = get_the_ID();
+ }
+ if ( false === $post_id ) {
+ $post_id = 0;
+ } else {
+ $post = get_post( $post_id );
+ $post_id = $post ? $post->ID : 0;
+ }
+
if ( current_user_can( 'unfiltered_html' ) ) {
wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false );
echo "\n";
@@ -1514,6 +1558,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 +1568,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 +1601,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 +1613,7 @@
echo '';
- comments_number( $zero, $one, $more );
+ comments_number( $zero, $one, $more, '', $id );
echo '';
}