Skip to content

fix(content-distribution): keep node post in status_on_publish when hub schedules#302

Merged
wil-gerken merged 5 commits intotrunkfrom
fix/future-post-status-bypasses-status-on-publish
Mar 6, 2026
Merged

fix(content-distribution): keep node post in status_on_publish when hub schedules#302
wil-gerken merged 5 commits intotrunkfrom
fix/future-post-status-bypasses-status-on-publish

Conversation

@wil-gerken
Copy link
Contributor

@wil-gerken wil-gerken commented Mar 5, 2026

All Submissions:

Changes proposed in this Pull Request:

When a post is distributed to a node as a draft and the hub later schedules it, the node was auto-publishing the post regardless of the status_on_publish setting.

The root cause: post_status = 'future' fell through to the else branch in Incoming_Post::insert(), bypassing the status_on_publish check.

Once a node post has a future status, WordPress schedules the publish_future_post cron event, which then calls wp_publish_post() directly. This bypasses class-incoming-post.php and the status_on_publish logic.

This change adds a future branch that checks status_on_publish before applying the status.

If status_on_publish is a non-publish value (e.g. draft, pending), the node post stays in that status and the WP cron never schedules publication.

If status_on_publish is publish or unset, the node mirrors the hub's future status so both sites publish on the same schedule.

Hub sends status_on_publish Node result
future draft draft <-- fixes the bug
future pending pending
future publish future (mirrors hub schedule)
publish any unchanged (existing behaviour)

Closes NPPM-2656

Note: Following Copilot's reviews, I added some defensive guards for missing status_on_publish key across three access points in insert() (status handling, meta storage), plus an additional test covering this unset payload scenario.

How to test the changes in this Pull Request:

Before applying this PR:

  1. On the hub, create a new post with an easy-to-identify headline. Save it as a Draft and distribute it to a node.
  2. On the node, go to All Posts (/wp-admin/edit.php?post_type=post) and wait ~2 minutes for the post to arrive. It will show as Draft as expected.
  3. On the hub, modify the headline slightly for easy identification, then schedule it for tomorrow.
  4. On the node, wait ~2 minutes for the update to pull. The post will be Published <-- this is the bug.

After applying this PR:

  1. On the hub, create a second new post with an easy-to-identify headline. Save it as a Draft and distribute it to a node.
  2. On the node, go to All Posts and wait ~2 minutes. It will show as Draft as expected.
  3. On the hub, modify the headline slightly, then schedule it for tomorrow.
  4. On the node, wait ~2 minutes. The post will remain Draft <-- the bug is fixed.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@wil-gerken wil-gerken requested a review from a team as a code owner March 5, 2026 23:07
@wil-gerken wil-gerken requested review from Copilot and removed request for a team March 5, 2026 23:07
@wil-gerken wil-gerken changed the title fix(content-distribution): keep node post in status_on_publish when h… fix(content-distribution): keep node post in status_on_publish when hub schedules Mar 5, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a content-distribution edge case where hub-scheduled posts (post_status = future) could bypass status_on_publish on nodes, leading to unintended node publication via WordPress scheduling behavior.

Changes:

  • Add explicit future post-status handling in Incoming_Post::insert() to respect status_on_publish.
  • Add unit tests covering future behavior for both non-publish and publish status_on_publish values.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
includes/content-distribution/class-incoming-post.php Adds a future-status branch to apply status_on_publish logic and avoid unintended node scheduling/publishing.
tests/unit-tests/content-distribution/test-incoming-post.php Adds regression tests validating node behavior when receiving future status updates from the hub.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wil-gerken wil-gerken requested a review from a team March 6, 2026 01:00
Copy link
Contributor

@leogermani leogermani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@wil-gerken wil-gerken merged commit 6ed98ad into trunk Mar 6, 2026
12 checks passed
@wil-gerken wil-gerken deleted the fix/future-post-status-bypasses-status-on-publish branch March 6, 2026 19:21
@github-actions
Copy link

github-actions bot commented Mar 6, 2026

Hey @wil-gerken, good job getting this PR merged! 🎉

Now, the needs-changelog label has been added to it.

Please check if this PR needs to be included in the "Upcoming Changes" and "Release Notes" doc. If it doesn't, simply remove the label.

If it does, please add an entry to our shared document, with screenshots and testing instructions if applicable, then remove the label.

Thank you! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants