Show "Immediately" for custom status posts in block editor#938
Merged
Show "Immediately" for custom status posts in block editor#938
Conversation
WP core's REST controller only nulls date_gmt for 'draft' and 'pending',
so posts in Edit Flow custom statuses were serialised with a concrete ISO
date derived from post_date. The block editor then displayed that date in
the Publish field instead of "Immediately", confusing editorial users who
expect the same behaviour as a draft.
Add a rest_prepare_{post_type} filter, registered for each post type that
supports custom statuses, that restores parity with core's draft/pending
handling when post_date_gmt is '0000-00-00 00:00:00'.
Fixes #925
Nulling date_gmt alone proved insufficient in practice. Gutenberg's isEditedPostDateFloating selector hardcodes the status whitelist to 'draft', 'auto-draft', and 'pending', so for any custom Edit Flow status it short-circuits to false and the Publish field renders the concrete date rather than "Immediately". Nulling date in addition pushes Gutenberg's label renderer into its "Immediately" branch (triggered when date itself is null), which avoids modifying core behaviour or shipping a JS workaround. The database post_date is unaffected because Gutenberg only sends changed fields on save, so a nulled date in the response does not propagate back unless the user actively edits the schedule.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #925.
When a post sits in an Edit Flow custom status (Pitch, Assigned, In Progress, and so on), the block editor's Publish field displays a concrete date like "Today at 2:44 pm" rather than "Immediately". Without Edit Flow active, the same underlying post correctly shows "Immediately" — so this is a regression introduced by the REST API round-trip, not the database layer.
The root cause lives in WP core.
WP_REST_Posts_Controller::prepare_item_for_response()only returnsnullfordate_gmtwhen a post's status isdraftorpending. Any other status — including every Edit Flow custom status — falls through to the branch that converts0000-00-00 00:00:00into a concrete ISO 8601 date derived frompost_date. The block editor reads that value, interprets it literally, and renders the confusing concrete date.The existing
fix_custom_status_timestamp()already preserves0000-00-00 00:00:00in the database on save, andupdate_post_date_on_publish_from_custom_status()handles the publish transition correctly, so posts do publish at the right time. The bug is purely cosmetic — but it still undermines editorial trust in what the Publish field is telling them.The fix adds a
rest_prepare_{post_type}filter, registered for every post type that supports custom statuses, which restores parity with core's draft/pending handling. When the post is in a custom status andpost_date_gmtis unset, the response'sdate_gmtis nulled so Gutenberg'sPostScheduleLabelfalls back to "Immediately". Posts with an explicitly scheduled GMT date are left alone, and draft/pending posts continue to flow through core's own logic untouched.A new integration test file (
CustomStatusRestApiDateTest) covers the happy path plus the obvious regression traps: published posts keeping their concrete date, draft posts still getting null from core, scheduled pitches preserving their explicit GMT date, and pending posts remaining unaffected.Test plan