Skip to content

Prevent fatal error when previewing unpublished liveblog posts#921

Merged
GaryJones merged 1 commit into
developfrom
GaryJones/liveblog-fatal-unpublished-posts
Jun 16, 2026
Merged

Prevent fatal error when previewing unpublished liveblog posts#921
GaryJones merged 1 commit into
developfrom
GaryJones/liveblog-fatal-unpublished-posts

Conversation

@GaryJones

Copy link
Copy Markdown
Contributor

Summary

Viewing an unpublished liveblog post could take the whole page down with a fatal error:

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

The schema metadata builder 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 then threw, and because the metadata is printed during wp_head, the error surfaced for anyone previewing such a post.

This change looks up each datetime first and only sets the corresponding schema properties (datePublished/coverageStartTime and dateModified/coverageEndTime) when a valid object is returned. The date-derived fields are simply 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, all of which carry real GMT dates.

The accompanying integration tests lock in both halves of the contract: a draft post now generates its metadata without fatalling and without the date keys, while a published post continues to expose them.

Fixes #919. Resolves VIPPLUG-24.

Test plan

  • composer test:integration (or the equivalent wp-env run) passes, including the two new SchemaMetadataTest cases
  • Preview an unpublished liveblog-enabled post and confirm the page renders without a fatal

@GaryJones GaryJones requested a review from a team as a code owner June 16, 2026 06:30
@GaryJones GaryJones self-assigned this Jun 16, 2026
@GaryJones GaryJones added the Bug label Jun 16, 2026
@GaryJones GaryJones added this to the Next 1.x milestone Jun 16, 2026
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 the metadata builder
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.

Fixes VIPPLUG-24.
@GaryJones GaryJones force-pushed the GaryJones/liveblog-fatal-unpublished-posts branch from b535c0f to 98a3c90 Compare June 16, 2026 10:01
@GaryJones GaryJones merged commit 83427f1 into develop Jun 16, 2026
12 checks passed
@GaryJones GaryJones deleted the GaryJones/liveblog-fatal-unpublished-posts branch June 16, 2026 10:12
@GaryJones GaryJones added type: bug Something isn't working and removed Bug labels 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.

Liveblog.php throwing fatal errors when viewing unpublished posts

1 participant