From 343e99259ef7d68dd2d1f9603b477db589238c05 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Tue, 24 Nov 2026 20:25:57 +0000 Subject: [PATCH 1/2] Abilities API: Return content query dates at the Unix epoch. The `core/content-query` ability returned `null` for a `date` or `modified` value of exactly 1970-01-01 00:00:00 GMT, because `rest_parse_date()` returns `0` for it. The date check now compares against `false`, the same way the users query ability does. --- .../abilities/class-wp-abilities-content.php | 2 +- .../wpRegisterCoreContentAbility.php | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/abilities/class-wp-abilities-content.php b/src/wp-includes/abilities/class-wp-abilities-content.php index a8d9954e30965..f5a7e881b1c95 100644 --- a/src/wp-includes/abilities/class-wp-abilities-content.php +++ b/src/wp-includes/abilities/class-wp-abilities-content.php @@ -1770,7 +1770,7 @@ private function format_date( WP_Post $post, string $field, bool $gmt ): ?string */ $date = ( $gmt ? $datetime->setTimezone( new DateTimeZone( 'UTC' ) ) : $datetime )->format( 'c' ); - return rest_parse_date( $date ) ? $date : null; + return false !== rest_parse_date( $date ) ? $date : null; } /** diff --git a/tests/phpunit/tests/abilities-api/wpRegisterCoreContentAbility.php b/tests/phpunit/tests/abilities-api/wpRegisterCoreContentAbility.php index cf537f5cf0911..d8c0ba22493d4 100644 --- a/tests/phpunit/tests/abilities-api/wpRegisterCoreContentAbility.php +++ b/tests/phpunit/tests/abilities-api/wpRegisterCoreContentAbility.php @@ -5689,6 +5689,42 @@ public function test_malformed_date_is_null( string $field, string $column ): vo $this->assertNull( $result['items'][0][ $object ][ $key ], 'A malformed date should be null.' ); } + /** + * A stored date at the Unix epoch is returned: a timestamp of zero is a date, not a + * date that could not be parsed. + * + * @ticket 00000 + * @since 7.3.0 + * + * @dataProvider data_date_fields + * + * @param string $field The field path to request, such as `date.site`. + * @param string $column The cached post column to set to the Unix epoch. + */ + public function test_date_at_the_unix_epoch_is_returned( string $field, string $column ): void { + $this->login_as( 'administrator' ); + $this->register_ability(); + + $post_id = self::factory()->post->create( array( 'post_status' => 'publish' ) ); + + $this->replace_cached_post_date_columns( $post_id, array( $column => '1970-01-01 00:00:00' ) ); + + list( $object, $key ) = explode( '.', $field ); + + $result = wp_get_ability( 'core/content-query' )->execute( + array( + 'where' => array( + 'type' => 'post', + 'ids' => array( $post_id ), + ), + 'fields' => array( 'id', $field ), + ) + ); + + $this->assertIsArray( $result, 'A date at the Unix epoch should pass output validation.' ); + $this->assertSame( '1970-01-01T00:00:00+00:00', $result['items'][0][ $object ][ $key ] ?? null, 'A date at the Unix epoch should be returned.' ); + } + /** * Returns `where.author` values that are not an object holding an ID or a slug: values * that are not objects, empty values, and objects with an unknown property. From 1e300e425e4ce2e157685530301a8c4fb7b41412 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Tue, 24 Nov 2026 20:27:33 +0000 Subject: [PATCH 2/2] Tests: Reference the ticket in the Unix epoch date test. See #66812. --- .../tests/abilities-api/wpRegisterCoreContentAbility.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/abilities-api/wpRegisterCoreContentAbility.php b/tests/phpunit/tests/abilities-api/wpRegisterCoreContentAbility.php index d8c0ba22493d4..f1378aa13cfb7 100644 --- a/tests/phpunit/tests/abilities-api/wpRegisterCoreContentAbility.php +++ b/tests/phpunit/tests/abilities-api/wpRegisterCoreContentAbility.php @@ -5693,7 +5693,7 @@ public function test_malformed_date_is_null( string $field, string $column ): vo * A stored date at the Unix epoch is returned: a timestamp of zero is a date, not a * date that could not be parsed. * - * @ticket 00000 + * @ticket 66812 * @since 7.3.0 * * @dataProvider data_date_fields