Skip to content

Try to cache the theme json file reading - #3401

Closed
cbravobernal wants to merge 5 commits into
WordPress:trunkfrom
cbravobernal:try/fix-cache-block-styles-theme-json
Closed

Try to cache the theme json file reading#3401
cbravobernal wants to merge 5 commits into
WordPress:trunkfrom
cbravobernal:try/fix-cache-block-styles-theme-json

Conversation

@cbravobernal

@cbravobernalcbravobernal commented Oct 4, 2022

Copy link
Copy Markdown
Contributor

Comment on lines +203 to +204
$theme_json = apply_filters( 'theme_json_theme', new WP_Theme_JSON_Data( $theme_json_data, 'theme' ) );
$theme_json_data = $theme_json->get_data();

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

If we set static::$theme_json_data after these two lines. Then the theme json file does not apply.

static::$theme_json_data = $theme_json_data;
$theme_json = apply_filters( 'theme_json_theme', new WP_Theme_JSON_Data( $theme_json_data, 'theme' ) );
$theme_json_data = $theme_json->get_data();
static::$theme = new WP_Theme_JSON( $theme_json_data );

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

We should test it with child themes.

@cbravobernal

Copy link
Copy Markdown
ContributorAuthor

cc/ @oandregal, would this approach be correct?

@ockham

Copy link
Copy Markdown
Contributor

Rebased.

@ockham
ockhamforce-pushed the try/fix-cache-block-styles-theme-json branch from 4f69396 to e2704abCompareOctober 5, 2022 12:45
@ockham

ockham commented Oct 5, 2022

Copy link
Copy Markdown
Contributor

I think this is working now 🎉

I was about to implement file caching for the parent theme (see #3401 (comment)), but then it occurred to me that we might solve this slightly differently:

We can add a single $theme_json_file_cache static var, and use it from within static::read_json_file().

I'll give that a try.

@cbravobernal

Copy link
Copy Markdown
ContributorAuthor

#3408 does the work, so we can close this one.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@cbravobernal@ockham