REST API: Introduce date_floating property on status endpoint response objects.
Expose a date_floating property on all status objects to permit clients (including the block editor) to make correct decisions about date handling for posts of varying status. Props mnelson4, earnjam, kadamwhite, jnylen0, nerrad, pento. See #39953. Built from https://develop.svn.wordpress.org/trunk@46252 git-svn-id: http://core.svn.wordpress.org/trunk@46064 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b65ea119bb
commit
ef86b03619
|
@ -337,14 +337,15 @@ function create_initial_post_types() {
|
|||
register_post_status(
|
||||
'draft',
|
||||
array(
|
||||
'label' => _x( 'Draft', 'post status' ),
|
||||
'protected' => true,
|
||||
'_builtin' => true, /* internal use only. */
|
||||
'label' => _x( 'Draft', 'post status' ),
|
||||
'protected' => true,
|
||||
'_builtin' => true, /* internal use only. */
|
||||
/* translators: %s: Number of draft posts. */
|
||||
'label_count' => _n_noop(
|
||||
'label_count' => _n_noop(
|
||||
'Draft <span class="count">(%s)</span>',
|
||||
'Drafts <span class="count">(%s)</span>'
|
||||
),
|
||||
'date_floating' => true,
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -394,9 +395,10 @@ function create_initial_post_types() {
|
|||
register_post_status(
|
||||
'auto-draft',
|
||||
array(
|
||||
'label' => 'auto-draft',
|
||||
'internal' => true,
|
||||
'_builtin' => true, /* internal use only. */
|
||||
'label' => 'auto-draft',
|
||||
'internal' => true,
|
||||
'_builtin' => true, /* internal use only. */
|
||||
'date_floating' => true,
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -1018,6 +1020,8 @@ function _wp_privacy_statuses() {
|
|||
* the top of the edit listings,
|
||||
* e.g. All (12) | Published (9) | My Custom Status (2)
|
||||
* Default is value of $internal.
|
||||
* @type bool $date_floating Whether the post has a floating creation date.
|
||||
* Default to false.
|
||||
* }
|
||||
* @return object
|
||||
*/
|
||||
|
@ -1041,6 +1045,7 @@ function register_post_status( $post_status, $args = array() ) {
|
|||
'publicly_queryable' => null,
|
||||
'show_in_admin_status_list' => null,
|
||||
'show_in_admin_all_list' => null,
|
||||
'date_floating' => null,
|
||||
);
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
$args = (object) $args;
|
||||
|
@ -1085,6 +1090,10 @@ function register_post_status( $post_status, $args = array() ) {
|
|||
$args->show_in_admin_status_list = ! $args->internal;
|
||||
}
|
||||
|
||||
if ( null === $args->date_floating ) {
|
||||
$args->date_floating = false;
|
||||
}
|
||||
|
||||
if ( false === $args->label ) {
|
||||
$args->label = $post_status;
|
||||
}
|
||||
|
|
|
@ -234,6 +234,10 @@ class WP_REST_Post_Statuses_Controller extends WP_REST_Controller {
|
|||
$data['slug'] = $status->name;
|
||||
}
|
||||
|
||||
if ( in_array( 'date_floating', $fields, true ) ) {
|
||||
$data['date_floating'] = $status->date_floating;
|
||||
}
|
||||
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
|
@ -277,48 +281,54 @@ class WP_REST_Post_Statuses_Controller extends WP_REST_Controller {
|
|||
'title' => 'status',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'name' => array(
|
||||
'name' => array(
|
||||
'description' => __( 'The title for the status.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'embed', 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'private' => array(
|
||||
'private' => array(
|
||||
'description' => __( 'Whether posts with this status should be private.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'protected' => array(
|
||||
'protected' => array(
|
||||
'description' => __( 'Whether posts with this status should be protected.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'public' => array(
|
||||
'public' => array(
|
||||
'description' => __( 'Whether posts of this status should be shown in the front end of the site.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'queryable' => array(
|
||||
'queryable' => array(
|
||||
'description' => __( 'Whether posts with this status should be publicly-queryable.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'show_in_list' => array(
|
||||
'show_in_list' => array(
|
||||
'description' => __( 'Whether to include posts in the edit listing for their post type.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'slug' => array(
|
||||
'slug' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the status.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'embed', 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'date_floating' => array(
|
||||
'description' => __( 'Whether posts of this status may have floating published dates.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -1021,16 +1021,18 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
|
||||
// Post date.
|
||||
if ( ! empty( $schema['properties']['date'] ) && ! empty( $request['date'] ) ) {
|
||||
$date_data = rest_get_date_with_gmt( $request['date'] );
|
||||
$current_date = isset( $prepared_post->ID ) ? get_post( $prepared_post->ID )->post_date : false;
|
||||
$date_data = rest_get_date_with_gmt( $request['date'] );
|
||||
|
||||
if ( ! empty( $date_data ) ) {
|
||||
if ( ! empty( $date_data ) && $current_date !== $date_data[0] ) {
|
||||
list( $prepared_post->post_date, $prepared_post->post_date_gmt ) = $date_data;
|
||||
$prepared_post->edit_date = true;
|
||||
}
|
||||
} elseif ( ! empty( $schema['properties']['date_gmt'] ) && ! empty( $request['date_gmt'] ) ) {
|
||||
$date_data = rest_get_date_with_gmt( $request['date_gmt'], true );
|
||||
$current_date = isset( $prepared_post->ID ) ? get_post( $prepared_post->ID )->post_date_gmt : false;
|
||||
$date_data = rest_get_date_with_gmt( $request['date_gmt'], true );
|
||||
|
||||
if ( ! empty( $date_data ) ) {
|
||||
if ( ! empty( $date_data ) && $current_date !== $date_data[1] ) {
|
||||
list( $prepared_post->post_date, $prepared_post->post_date_gmt ) = $date_data;
|
||||
$prepared_post->edit_date = true;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.3-alpha-46251';
|
||||
$wp_version = '5.3-alpha-46252';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue