Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/wp-includes/abilities/class-wp-abilities-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -988,12 +988,12 @@ private function get_post_properties(): array {
'type' => 'object',
'additionalProperties' => false,
'properties' => array(
'local' => array(
'site' => array(
'type' => array( 'string', 'null' ),
'format' => 'date-time',
'description' => __( "The publication date, in ISO 8601 format using the site's timezone. Null when the date cannot be resolved." ),
),
'gmt' => array(
'gmt' => array(
'type' => array( 'string', 'null' ),
'format' => 'date-time',
'description' => __( 'The publication date, in ISO 8601 format as GMT. Null when the date cannot be resolved.' ),
Expand All @@ -1005,12 +1005,12 @@ private function get_post_properties(): array {
'type' => 'object',
'additionalProperties' => false,
'properties' => array(
'local' => array(
'site' => array(
'type' => array( 'string', 'null' ),
'format' => 'date-time',
'description' => __( "The last modified date, in ISO 8601 format using the site's timezone. Null when the date cannot be resolved." ),
),
'gmt' => array(
'gmt' => array(
'type' => array( 'string', 'null' ),
'format' => 'date-time',
'description' => __( 'The last modified date, in ISO 8601 format as GMT. Null when the date cannot be resolved.' ),
Expand Down Expand Up @@ -1460,8 +1460,8 @@ private function build_post_fields( WP_Post $post, array $fields, bool $can_edit

foreach ( array( 'date', 'modified' ) as $field ) {
$dates = array();
if ( $this->is_field_requested( "{$field}.local", $fields ) ) {
$dates['local'] = $this->format_date( $post, $field, false );
if ( $this->is_field_requested( "{$field}.site", $fields ) ) {
$dates['site'] = $this->format_date( $post, $field, false );
}
if ( $this->is_field_requested( "{$field}.gmt", $fields ) ) {
$dates['gmt'] = $this->format_date( $post, $field, true );
Expand Down
50 changes: 27 additions & 23 deletions tests/phpunit/tests/abilities-api/wpRegisterCoreContentAbility.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,10 @@ public function test_input_schema_models_a_flat_where(): void {
'type',
'status',
'date',
'date.local',
'date.site',
'date.gmt',
'modified',
'modified.local',
'modified.site',
'modified.gmt',
'slug',
'link',
Expand Down Expand Up @@ -678,7 +678,7 @@ public function test_empty_fields_and_pagination_select_the_defaults(): void {
$this->assertSame( (int) ceil( $result['pagination']['total'] / 10 ), $result['pagination']['total_pages'], 'The page count should follow the default page size.' );
$this->assertSameSets( array( 'id', 'type', 'status', 'date', 'slug', 'title' ), array_keys( $result['items'][0] ), 'An empty fields list should select the default fields.' );
$this->assertSame( array( 'rendered' ), array_keys( $result['items'][0]['title'] ), 'The default fields should hold only the rendered title.' );
$this->assertSameSets( array( 'local', 'gmt' ), array_keys( $result['items'][0]['date'] ), 'The default fields should hold both dates.' );
$this->assertSame( array( 'site', 'gmt' ), array_keys( $result['items'][0]['date'] ), 'The default fields should hold both the site and the GMT date, in that order.' );

$explicit = $ability->execute(
array(
Expand Down Expand Up @@ -740,12 +740,12 @@ public function test_output_schema_describes_query_responses(): void {
$nullable_string = array( 'string', 'null' );
$object_types = array(
'date' => array(
'local' => $nullable_string,
'gmt' => $nullable_string,
'site' => $nullable_string,
'gmt' => $nullable_string,
),
'modified' => array(
'local' => $nullable_string,
'gmt' => $nullable_string,
'site' => $nullable_string,
'gmt' => $nullable_string,
),
'title' => array(
'raw' => 'string',
Expand Down Expand Up @@ -775,9 +775,10 @@ public function test_output_schema_describes_query_responses(): void {
$this->assertSame( $types, wp_list_pluck( $object['properties'], 'type' ), sprintf( 'The %s object should describe each key with its type, in order.', $name ) );
}
foreach ( array( 'date', 'modified' ) as $name ) {
foreach ( array( 'local', 'gmt' ) as $key ) {
foreach ( array( 'site', 'gmt' ) as $key ) {
$this->assertSame( 'date-time', $post_schema['properties'][ $name ]['properties'][ $key ]['format'], sprintf( 'The %s.%s value should use the date-time format.', $name, $key ) );
}
$this->assertStringContainsString( "in ISO 8601 format using the site's timezone.", $post_schema['properties'][ $name ]['properties']['site']['description'], sprintf( 'The %s.site description should say the date uses the site timezone.', $name ) );
}

$this->assertSame( 'object', $pagination['type'], 'The pagination should describe an object.' );
Expand Down Expand Up @@ -2009,11 +2010,14 @@ public function data_sub_field_paths(): array {
'content.rendered' => array(
'field' => 'content.rendered',
),
'date.site' => array(
'field' => 'date.site',
),
'date.gmt' => array(
'field' => 'date.gmt',
),
'modified.local' => array(
'field' => 'modified.local',
'modified.site' => array(
'field' => 'modified.site',
),
'author.name' => array(
'field' => 'author.name',
Expand Down Expand Up @@ -2075,11 +2079,11 @@ public function data_object_fields(): array {
),
'date' => array(
'field' => 'date',
'keys' => array( 'local', 'gmt' ),
'keys' => array( 'site', 'gmt' ),
),
'modified' => array(
'field' => 'modified',
'keys' => array( 'local', 'gmt' ),
'keys' => array( 'site', 'gmt' ),
),
'author' => array(
'field' => 'author',
Expand Down Expand Up @@ -5252,7 +5256,7 @@ public function test_query_keeps_posts_whose_requested_fields_do_not_apply(): vo
}

/**
* Local and GMT date fields report the correct instant and offset on non-UTC sites.
* Site and GMT date fields report the correct instant and offset on non-UTC sites.
*
* @ticket 66268
* @since 7.2.0
Expand Down Expand Up @@ -5289,13 +5293,13 @@ public function test_gmt_dates_are_utc_on_non_utc_sites(): void {
'type' => 'post',
'ids' => array( $post_id ),
),
'fields' => array( 'id', 'date.local', 'date.gmt', 'modified.local', 'modified.gmt' ),
'fields' => array( 'id', 'date.site', 'date.gmt', 'modified.site', 'modified.gmt' ),
)
);

$this->assertSame( '2026-01-15T10:00:00-05:00', $result['items'][0]['date']['local'], 'The local date should carry the site timezone offset.' );
$this->assertSame( '2026-01-15T10:00:00-05:00', $result['items'][0]['date']['site'], 'The site date should carry the site timezone offset.' );
$this->assertSame( '2026-01-15T15:00:00+00:00', $result['items'][0]['date']['gmt'], 'The GMT date should be the UTC instant with a UTC offset.' );
$this->assertSame( '2026-01-16T11:00:00-05:00', $result['items'][0]['modified']['local'], 'The local modified date should carry the site timezone offset.' );
$this->assertSame( '2026-01-16T11:00:00-05:00', $result['items'][0]['modified']['site'], 'The site modified date should carry the site timezone offset.' );
$this->assertSame( '2026-01-16T16:00:00+00:00', $result['items'][0]['modified']['gmt'], 'The GMT modified date should be the UTC instant with a UTC offset.' );
}

Expand Down Expand Up @@ -5508,19 +5512,19 @@ public function test_gmt_date_is_null_when_no_usable_date_exists( string $field,
*/
public function data_date_fields(): array {
return array(
'date.local' => array(
'field' => 'date.local',
'date.site' => array(
'field' => 'date.site',
'column' => 'post_date',
),
'date.gmt' => array(
'date.gmt' => array(
'field' => 'date.gmt',
'column' => 'post_date_gmt',
),
'modified.local' => array(
'field' => 'modified.local',
'modified.site' => array(
'field' => 'modified.site',
'column' => 'post_modified',
),
'modified.gmt' => array(
'modified.gmt' => array(
'field' => 'modified.gmt',
'column' => 'post_modified_gmt',
),
Expand All @@ -5538,7 +5542,7 @@ public function data_date_fields(): array {
*
* @dataProvider data_date_fields
*
* @param string $field The field path to request, such as `date.local`.
* @param string $field The field path to request, such as `date.site`.
* @param string $column The cached post column to corrupt.
*/
public function test_malformed_date_is_null( string $field, string $column ): void {
Expand Down
Loading