Skip to content

Conversation

@srtfisher
Copy link

As titled.

@GaryJones GaryJones changed the base branch from main to develop November 13, 2025 15:58
@GaryJones
Copy link
Contributor

Thanks for the PR! You're right that get_post_status_object() can return null and we should handle that case.

Why this happens:

get_post_status_object() returns null when the status isn't registered. This can occur in several scenarios:

  • Posts imported from another system with custom statuses that aren't registered in the current install
  • Posts orphaned after a plugin (like Edit Flow) is deactivated, leaving posts with statuses like pitch or assigned that no longer exist
  • Race conditions during plugin activation/deactivation
  • Database inconsistencies

Issue with the current fix:

The current code returns early without a value:

if ( ! is_object( $post_status ) ) {
    return;
}

This effectively returns null, which breaks the display_post_states filter chain. The filter expects $post_states (an array) to be returned so other filters can continue processing. Returning null would cause issues for any subsequent filters.

Suggested fix:

if ( ! is_object( $post_status ) ) {
    return $post_states;
}

This preserves the filter chain while safely skipping our custom status display when the status object isn't available.

Add a null check for the return value of get_post_status_object() to
prevent PHP notices when the function returns null for invalid or
deleted post statuses.

The original PR returned nothing on null, which would break the
display_post_states filter chain. This fix correctly returns
$post_states to maintain filter compatibility.

🤖 Generated with [Claude Code](https://claude.ai/claude-code)

Co-Authored-By: Sean Fisher <sean@sean-fisher.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@GaryJones GaryJones requested a review from a team as a code owner December 19, 2025 01:07
@GaryJones GaryJones added this to the Next (minor) milestone Dec 19, 2025
@GaryJones GaryJones merged commit ed670f2 into Automattic:develop Dec 19, 2025
4 checks passed
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.

2 participants