Skip to content

Commit 8a2902d

Browse files
committed
Comments: Allow to pass $comment_ID parameter to get_comment_time().
Props spacedmonkey, travisaxton, SergeyBiryukov, d-signed, audrasjb, rudlinkon, h4l9k, mukesh27, costdev. Fixes #52322. git-svn-id: https://develop.svn.wordpress.org/trunk@55284 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 6fc77d2 commit 8a2902d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/wp-includes/comment-template.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,15 +1031,22 @@ function comment_text( $comment_ID = 0, $args = array() ) {
10311031
* Retrieves the comment time of the current comment.
10321032
*
10331033
* @since 1.5.0
1034+
* @since 6.2.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
10341035
*
1035-
* @param string $format Optional. PHP time format. Defaults to the 'time_format' option.
1036-
* @param bool $gmt Optional. Whether to use the GMT date. Default false.
1037-
* @param bool $translate Optional. Whether to translate the time (for use in feeds).
1038-
* Default true.
1036+
* @param string $format Optional. PHP date format. Defaults to the 'time_format' option.
1037+
* @param bool $gmt Optional. Whether to use the GMT date. Default false.
1038+
* @param bool $translate Optional. Whether to translate the time (for use in feeds).
1039+
* Default true.
1040+
* @param int|WP_Comment $comment_ID Optional. WP_Comment or ID of the comment for which to get the date.
1041+
* Default is 0, or the global comment.
10391042
* @return string The formatted time.
10401043
*/
1041-
function get_comment_time( $format = '', $gmt = false, $translate = true ) {
1042-
$comment = get_comment();
1044+
function get_comment_time( $format = '', $gmt = false, $translate = true, $comment_ID = 0 ) {
1045+
$comment = get_comment( $comment_ID );
1046+
1047+
if ( null === $comment ) {
1048+
return '';
1049+
}
10431050

10441051
$comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
10451052

0 commit comments

Comments
 (0)