Make WordPress Core

#64434 closed defect (bug) (fixed)

Theme_JSON_Resolver throws fatals in some scenarios

Reported by: oandregal Owned by: oandregal
Priority: normal Milestone: 7.0
Component: Editor Version: 7.0
Severity: normal Keywords: has-patch commit
Cc: Focuses:

Description

## Description

In certain scenarios, when the Theme_JSON_Resolver gets a post to prepare the user styles, it's null.

For example, in [this line ​https://github.com/WordPress/wordpress-develop/blob/44f1517e8f6dd72710a143420c3a0c2bae1a3766/src/wp-includes/class-wp-theme-json-resolver.php#L535], get_post function returns null after the wp_insert_post function is called. Although the post is saved, it's assumed that it can be immediately accessed, which is not always true.

## How to reproduce

Unfortunately, there's no steps to reproduce it consistently. We've just seen reports by hosts that this happens occassionally in certain transition states for the site (creation, migration, etc.).

Change History (5)

This ticket was mentioned in ​PR #10648 on ​WordPress/wordpress-develop by ​@oandregal.


11 months ago
#1

Trac ticket: https://core.trac.wordpress.org/ticket/64434
Backports ​https://github.com/WordPress/gutenberg/pull/74124

## What?

This PR adds defensive checks to prevent some errors we've seen in hosts.

In certain scenarios, get_post function returns null after the wp_insert_post function is called. Although the post is saved, it's assumed that it can be immediately accessed, which is not always true.

## Why?

See ​https://github.com/WordPress/gutenberg/issues/70161

## How?

Check if it's an object before passing it to get_object_vars.

#3 @mcsf
11 months ago

  • Keywords commit added

I had approved the Gutenberg PR and have now tested this patch too. Let's get it in.

​@mcsf commented on ​PR #10648:


11 months ago
#4

I think it's better to be explicit that it's a WP_Post.

Good point, agreed.

#5 @oandregal
11 months ago

  • Resolution → fixed
  • Status assigned → closed

In 61400:

Theme_JSON_Resolver: check for WP_Post in query.

Props oandregal, mcsf, westonruter, mukesh27.
Fixes #64434.

Note: See TracTickets for help on using tickets.