Prevent fatal error when previewing unpublished liveblog posts (2.x)#922
Merged
Conversation
Previewing an unpublished liveblog post (draft, pending or auto-draft) triggered a fatal: get_post_datetime() returns false for the 0000-00-00 00:00:00 GMT date such posts carry, and MetadataPresenter called format() on that false value directly. Guard both the published and modified datetime lookups so the date-derived schema properties are simply omitted when no valid date is available, leaving behaviour unchanged for published, private and scheduled posts. Add integration coverage for the draft case and a companion assertion that published posts still expose the dates. This ports the develop-branch fix (#921) to 2.x, where the metadata builder now lives in MetadataPresenter. Fixes VIPPLUG-24 for 2.x.
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
This ports the develop-branch fix in #921 to the 2.x line, which carries the same defect in its refactored form.
Viewing an unpublished liveblog post could take the whole page down with a fatal:
In 2.x the schema metadata is assembled by
MetadataPresenter, which deriveddatePublishedanddateModifiedby callingget_post_datetime( $post, …, 'gmt' )->format( 'c' ). WordPress stores a0000-00-00 00:00:00GMT date for drafts, pending and auto-draft posts, and for that valueget_post_datetime()returnsfalse. Callingformat()onfalsethrew, and because the metadata is printed duringwp_head, the error surfaced for anyone previewing such a post.Each datetime is now looked up first, and the corresponding schema properties (
datePublished/coverageStartTimeanddateModified/coverageEndTime) are only set when a valid object is returned. The date-derived fields are omitted when no published date exists yet, which is the correct outcome for a post that has not been published. Behaviour is unchanged for published, private and scheduled posts, which all carry real GMT dates.The accompanying integration tests mirror those added on develop: a draft post now generates its metadata without fatalling and without the date keys, while a published post continues to expose them.
Since 2.x has not yet shipped, this is a pre-release fix rather than a hotfix. Resolves VIPPLUG-24 for the 2.x line.
Test plan
SchemaMetadataTestcases