Make WordPress Core

Changeset 65827


Ignore:
Timestamp:
11/30/2026 02:12:25 PM (less than one hour ago)
Author:
jorgefilipecosta
Message:

Abilities API: Return core/content-query dates at the Unix epoch.

The core/content-query ability returned null for a date or modified value at exactly the Unix epoch (1970-01-01 00:00:00 GMT). rest_parse_date() returns 0 for that date, and the check treated it as a date that could not be parsed. The check now compares the result against false, the same way core/users-query does, so the Unix epoch is returned like any other date.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/16219.

Follow-up to r64388.

Reviewed by gziolo.

Props jorgefilipecosta, gziolo.
Fixes #66812.

Location:
branches/7.2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/7.2

  • branches/7.2/src/wp-includes/abilities/class-wp-abilities-content.php

    r65724 r65827  
    17711771                $date = ( $gmt ? $datetime->setTimezone( new DateTimeZone( 'UTC' ) ) : $datetime )->format( 'c' );
    17721772
    1773                 return rest_parse_date( $date ) ? $date : null;
     1773                return false !== rest_parse_date( $date ) ? $date : null;
    17741774        }
    17751775
  • branches/7.2/tests/phpunit/tests/abilities-api/wpRegisterCoreContentAbility.php

    r65724 r65827  
    56915691
    56925692        /**
     5693         * A stored date at the Unix epoch is returned: a timestamp of zero is a date, not a
     5694         * date that could not be parsed.
     5695         *
     5696         * @ticket 66812
     5697         * @since 7.2.0
     5698         *
     5699         * @dataProvider data_date_fields
     5700         *
     5701         * @param string $field  The field path to request, such as `date.site`.
     5702         * @param string $column The cached post column to set to the Unix epoch.
     5703         */
     5704        public function test_date_at_the_unix_epoch_is_returned( string $field, string $column ): void {
     5705                $this->login_as( 'administrator' );
     5706                $this->register_ability();
     5707
     5708                $post_id = self::factory()->post->create( array( 'post_status' => 'publish' ) );
     5709
     5710                $this->replace_cached_post_date_columns( $post_id, array( $column => '1970-01-01 00:00:00' ) );
     5711
     5712                list( $object, $key ) = explode( '.', $field );
     5713
     5714                $result = wp_get_ability( 'core/content-query' )->execute(
     5715                        array(
     5716                                'where'  => array(
     5717                                        'type' => 'post',
     5718                                        'ids'  => array( $post_id ),
     5719                                ),
     5720                                'fields' => array( 'id', $field ),
     5721                        )
     5722                );
     5723
     5724                $this->assertIsArray( $result, 'A date at the Unix epoch should pass output validation.' );
     5725                $this->assertSame( '1970-01-01T00:00:00+00:00', $result['items'][0][ $object ][ $key ] ?? null, 'A date at the Unix epoch should be returned.' );
     5726        }
     5727
     5728        /**
    56935729         * Returns `where.author` values that are not an object holding an ID or a slug: values
    56945730         * that are not objects, empty values, and objects with an unknown property.
Note: See TracChangeset for help on using the changeset viewer.