Skip to content

Prevent fatal error when previewing unpublished liveblog posts (2.x)#922

Merged
GaryJones merged 1 commit into
2.xfrom
GaryJones/2.x-fatal-unpublished-posts
Jun 16, 2026
Merged

Prevent fatal error when previewing unpublished liveblog posts (2.x)#922
GaryJones merged 1 commit into
2.xfrom
GaryJones/2.x-fatal-unpublished-posts

Conversation

@GaryJones

Copy link
Copy Markdown
Contributor

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:

PHP Fatal error: Uncaught Error: Call to a member function format() on false

In 2.x the schema metadata is assembled by MetadataPresenter, which derived datePublished and dateModified by calling get_post_datetime( $post, …, 'gmt' )->format( 'c' ). WordPress stores a 0000-00-00 00:00:00 GMT date for drafts, pending and auto-draft posts, and for that value get_post_datetime() returns false. Calling format() on false threw, and because the metadata is printed during wp_head, the error surfaced for anyone previewing such a post.

Each datetime is now looked up first, and the corresponding schema properties (datePublished/coverageStartTime and dateModified/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

  • CI integration suite passes, including the two new SchemaMetadataTest cases
  • Preview an unpublished liveblog-enabled post and confirm the page renders without a fatal

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.
@GaryJones GaryJones requested a review from a team as a code owner June 16, 2026 10:27
@GaryJones GaryJones self-assigned this Jun 16, 2026
@GaryJones GaryJones added Bug type: bug Something isn't working and removed Bug labels Jun 16, 2026
@GaryJones GaryJones merged commit db6bdea into 2.x Jun 16, 2026
10 checks passed
@GaryJones GaryJones deleted the GaryJones/2.x-fatal-unpublished-posts branch June 16, 2026 10:30
@GaryJones GaryJones added this to the 2.0 milestone Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant