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.



git-svn-id: https://develop.svn.wordpress.org/trunk@46252 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
K. Adam White
2019-09-23 17:39:36 +00:00
parent f2b03e208a
commit 42e5e4d5d5
6 changed files with 163 additions and 20 deletions

View File

@@ -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;
}