WordPress.org

Make WordPress Core

Ticket #48207: 48207.diff

File 48207.diff, 5.5 KB (added by dshanske, 7 months ago)
  • src/wp-includes/comment-template.php

    diff --git a/src/tags b/src/tags
    new file mode 100644
    index 0000000000..96da1e59b9
    Binary files /dev/null and b/src/tags differ
    diff --git a/src/wp-includes/comment-template.php b/src/wp-includes/comment-template.php
    index d08f5cf62e..225714b21e 100644
    a b function get_comment_class( $class = '', $comment_id = null, $post_id = null ) { 
    549549 */
    550550function get_comment_date( $d = '', $comment_ID = 0 ) {
    551551        $comment = get_comment( $comment_ID );
     552
    552553        if ( '' == $d ) {
    553                 $date = mysql2date( get_option( 'date_format' ), $comment->comment_date );
     554                $date = get_comment_time( get_option( 'date_format' ), false, true, $comment );
    554555        } else {
    555                 $date = mysql2date( $d, $comment->comment_date );
     556                $date = get_comment_time( $d, false, true, $comment );
    556557        }
     558
    557559        /**
    558560         * Filters the returned comment date.
    559561         *
    function comment_text( $comment_ID = 0, $args = array() ) { 
    10041006}
    10051007
    10061008/**
    1007  * Retrieve the comment time of the current comment.
     1009 * Retrieve comment published time as a `DateTimeImmutable` object instance.
     1010 *
     1011 * The object will be set to the timezone from WordPress settings.
     1012 *
     1013 * For legacy reasons, this function allows to choose to instantiate from local or UTC time in database.
     1014 * Normally this should make no difference to the result. However, the values might get out of sync in database,
     1015 * typically because of timezone setting changes. The parameter ensures the ability to reproduce backwards
     1016 * compatible behaviors in such cases.
     1017 *
     1018 * @since 5.4.0
     1019 *
     1020 * @param int|WP_Comment $comment   Optional. WP_Comment object or ID. Default is global `$comment` object.
     1021 * @param string         $source Optional. Local or UTC time to use from database. Accepts 'local' or 'gmt'.
     1022 *                            Default 'local'.
     1023 * @return DateTimeImmutable|false Time object on success, false on failure.
     1024 */
     1025function get_comment_datetime( $comment = null, $source = 'local' ) {
     1026        $comment = get_comment( $comment );
     1027
     1028        if ( ! $comment ) {
     1029                return false;
     1030        }
     1031
     1032        $wp_timezone = wp_timezone();
     1033
     1034        if ( 'gmt' === $source ) {
     1035                $time     = $comment->comment_date_gmt;
     1036                $timezone = new DateTimeZone( 'UTC' );
     1037        } else {
     1038                $time     = $comment->comment_date;
     1039                $timezone = $wp_timezone;
     1040        }
     1041
     1042        if ( empty( $time ) || '0000-00-00 00:00:00' === $time ) {
     1043                return false;
     1044        }
     1045
     1046        $datetime = date_create_immutable_from_format( 'Y-m-d H:i:s', $time, $timezone );
     1047
     1048        if ( false === $datetime ) {
     1049                return false;
     1050        }
     1051
     1052        return $datetime->setTimezone( $wp_timezone );
     1053}
     1054
     1055/**
     1056 * Retrieve comment published or modified time as a Unix timestamp.
     1057 *
     1058 * Note that this function returns a true Unix timestamp, not summed with timezone offset
     1059 * like older WP functions.
     1060 *
     1061 * @since 5.4.0
     1062 *
     1063 * @param int|WP_Comment $comment  Optional. WP_Comment object or ID. Default is global `$comment` object.
     1064* @return int|false Unix timestamp on success, false on failure.
     1065 */
     1066function get_comment_timestamp( $comment = null ) {
     1067        $datetime = get_comment_datetime( $comment, $field );
     1068
     1069        if ( false === $datetime ) {
     1070                return false;
     1071        }
     1072
     1073        return $datetime->getTimestamp();
     1074}
     1075
     1076
     1077/**
     1078
     1079
     1080/**
     1081 * Retrieve the comment time for a comment.
    10081082 *
    10091083 * @since 1.5.0
    10101084 *
    function comment_text( $comment_ID = 0, $args = array() ) { 
    10121086 * @param bool   $gmt       Optional. Whether to use the GMT date. Default false.
    10131087 * @param bool   $translate Optional. Whether to translate the time (for use in feeds).
    10141088 *                          Default true.
     1089 * @param int|WP_Comment $comment Optional. WP_Comment object or ID. Default is global `$comment` object.
    10151090 * @return string The formatted time.
    10161091 */
    1017 function get_comment_time( $d = '', $gmt = false, $translate = true ) {
     1092function get_comment_time( $d = '', $gmt = false, $translate = true, $comment = null ) {
    10181093        $comment = get_comment();
    10191094
    1020         $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
    1021         if ( '' == $d ) {
    1022                 $date = mysql2date( get_option( 'time_format' ), $comment_date, $translate );
     1095        $source   = ( $gmt ) ? 'gmt' : 'local';
     1096        $datetime = get_comment_datetime( $comment, $source );
     1097
     1098        if ( false === $datetime ) {
     1099                return false;
     1100        }
     1101
     1102        if ( '' === $d ) {
     1103                $d = get_option( 'time_format' );
     1104        }
     1105
     1106        if ( 'U' === $d || 'G' === $d ) {
     1107                $time = $datetime->getTimestamp();
     1108
     1109                // Returns a sum of timestamp with timezone offset. Ideally should never be used.
     1110                if ( ! $gmt ) {
     1111                        $time += $datetime->getOffset();
     1112                }
     1113        } elseif ( $translate ) {
     1114                $time = wp_date( $d, $datetime->getTimestamp(), $gmt ? new DateTimeZone( 'UTC' ) : null );
    10231115        } else {
    1024                 $date = mysql2date( $d, $comment_date, $translate );
     1116                if ( $gmt ) {
     1117                        $datetime = $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
     1118                }
     1119
     1120                $time = $datetime->format( $d );
    10251121        }
    10261122
    10271123        /**
    function get_comment_time( $d = '', $gmt = false, $translate = true ) { 
    10291125         *
    10301126         * @since 1.5.0
    10311127         *
    1032          * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
     1128         * @param string|int $time      The comment time, formatted as a date string or Unix timestamp.
    10331129         * @param string     $d         Date format.
    10341130         * @param bool       $gmt       Whether the GMT date is in use.
    10351131         * @param bool       $translate Whether the time is translated.
    10361132         * @param WP_Comment $comment   The comment object.
    10371133         */
    1038         return apply_filters( 'get_comment_time', $date, $d, $gmt, $translate, $comment );
     1134        return apply_filters( 'get_comment_time', $time, $d, $gmt, $translate, $comment );
    10391135}
    10401136
    10411137/**