Make WordPress Core

Changeset 60891


Ignore:
Timestamp:
10/02/2025 09:46:07 PM (12 months ago)
Author:
joedolson
Message:

Privacy: A11y: Show time of privacy request status change.

Add the date and time of privacy request status changes in the privacy requests table. Previously, human_time_diff() was used in the first 24 hours, and only the date after 24 hours. Change the output to display both date and time after 24 hours, using the format used for comments.

Props birgire, desrosj, afercia, xkon, tz-media, garrett-eclipse, sirlouen, sukhendu2002, sajjad67, fakhriaz, joedolson.
Fixes #44267.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/css/forms.css

    r60885 r60891  
    14541454}
    14551455
     1456.privacy_requests .status-date {
     1457        display: block;
     1458        font-weight: 400;
     1459}
     1460
    14561461.wp-privacy-request-form {
    14571462        clear: both;
  • trunk/src/wp-admin/includes/class-wp-privacy-requests-table.php

    r60072 r60891  
    462462
    463463                if ( $timestamp ) {
    464                         echo ' (' . $this->get_timestamp_as_date( $timestamp ) . ')';
     464                        echo '<span class="status-date">' . $this->get_timestamp_as_date( $timestamp ) . '</span>';
    465465                }
    466466
    … …  
    488488                }
    489489
    490                 return date_i18n( get_option( 'date_format' ), $timestamp );
     490                return sprintf(
     491                        /* translators: 1: privacy request date format, 2: privacy request time format. */
     492                        __( '%1$s at %2$s' ),
     493                        /* translators: privacy request date format. See https://www.php.net/manual/en/datetime.format.php */
     494                        date_i18n( __( 'Y/m/d' ), $timestamp ),
     495                        /* translators: privacy request time format. See https://www.php.net/manual/en/datetime.format.php */
     496                        date_i18n( __( 'g:i a' ), $timestamp )
     497                );
    491498        }
    492499
  • trunk/tests/phpunit/tests/admin/wpPrivacyRequestsTable.php

    r60729 r60891  
    210210                $this->assertSame( $expected, $this->get_mocked_class_instance()->get_views() );
    211211        }
     212
     213        /**
     214         * Test the get_timestamp_as_date method formats timestamps correctly.
     215         *
     216         * @ticket 44267
     217         *
     218         * @covers WP_Privacy_Requests_Table::get_timestamp_as_date
     219         */
     220        public function test_get_timestamp_as_date() {
     221                $table = $this->get_mocked_class_instance();
     222
     223                $reflection = new ReflectionClass( $table );
     224                $method     = $reflection->getMethod( 'get_timestamp_as_date' );
     225                $method->setAccessible( true );
     226
     227                $date_format = __( 'Y/m/d' );
     228                $time_format = __( 'g:i a' );
     229
     230                $current_time = time();
     231
     232                $this->assertSame( '', $method->invoke( $table, '' ) );
     233
     234                // Test recent timestamp (less than 24 hours ago).
     235                $recent_time = $current_time - HOUR_IN_SECONDS;
     236                $result      = $method->invoke( $table, $recent_time );
     237                $this->assertStringContainsString( 'ago', $result );
     238
     239                $old_time = $current_time - 2 * DAY_IN_SECONDS;
     240                $result   = $method->invoke( $table, $old_time );
     241
     242                $date_part = date_i18n( $date_format, $old_time );
     243                $time_part = date_i18n( $time_format, $old_time );
     244
     245                $this->assertStringContainsString( $date_part, $result );
     246                $this->assertStringContainsString( 'at', $result );
     247                $this->assertStringContainsString( $time_part, $result );
     248        }
    212249}
Note: See TracChangeset for help on using the changeset viewer.