Skip to content

Fix: Clear theme cache after adding extra_theme_headers - #495

Open
CookieDarb wants to merge 2 commits into
WordPress:trunkfrom
CookieDarb:fix/active-theme-license-headers
Open

CookieDarb wants to merge 2 commits into
WordPress:trunkfrom
CookieDarb:fix/active-theme-license-headers

Conversation

@CookieDarb

Copy link
Copy Markdown

What?

Closes #494

This PR ensures that the "License" and "License URI" fields are correctly displayed in the Theme Info summary box when checking the currently active theme.

Why?

When Theme Check is run against the currently active theme, the "License" and "License URI" fields are missing from the visual summary box at the top of the WP Admin page. This occurs because WordPress caches the active theme's WP_Theme object early during initialization, long before Theme Check hooks into the extra_theme_headers filter to register these license fields.

How?

This PR:

  1. Adds a call to wp_clean_themes_cache( false ); immediately after registering the extra_theme_headers filter in theme-check.php.
  2. This busts the WordPress theme cache and forces wp_get_theme() to re-parse the active theme, successfully capturing the new headers.

Testing Instructions

  1. Activate a theme on your site that has License: and License URI: defined in its style.css
  2. Navigate to Appearance > Theme Check.
  3. Select the currently active theme from the dropdown and click Check it!.
  4. Look at the Theme Info summary box at the top of the results page.
  5. Verify that both the License and License URI fields are now correctly displayed in the summary box.

@jamesbregenzer

Copy link
Copy Markdown

At Theme Check’s themecheck_do_page() at this PR head, wp_clean_themes_cache( false ) runs before the code checks whether a theme was submitted. In WordPress Core at commit 3d870848, this refreshes theme-directory discovery and clears each theme returned by wp_get_themes(); false only skips the theme-update transient. So the cache clear runs on an ordinary page visit as well as a submitted check, and covers all discovered themes.

Could the refresh run only for a submitted check and be limited to the selected theme? A matched active-theme test would help confirm that the License fields still appear with the narrower scope. I have not measured runtime cost or tested this in WordPress, so this is a question about cache scope, not evidence of a performance regression.

@CookieDarb

Copy link
Copy Markdown
Author

Thanks for the feedback!

I've updated the PR to address both the points:

  • Removed wp_clean_themes_cache() from themecheck_do_page(), so no cache clearing runs on plain page visits.
  • Narrowed the scope by calling $theme->cache_delete() inside check_main(), which only runs on submission and limits the cache refresh strictly to the selected theme.

@jamesbregenzer

Copy link
Copy Markdown

Thanks for narrowing the refresh. I tested the active-theme case against base b726fc5 and head bc08cd0 on disposable WordPress 7.1.4 sites. After warming the theme before Theme Check registered its extra headers, the base submission omitted License and License URI from the generated Theme Info HTML; the updated submission included both. A plain visit at the updated head left the warmed fields untouched, and a second warmed theme’s License remained absent in all three cases.

This exercised the plugin’s admin-page and check methods with synthetic themes using PHP 8.4.27 via WebAssembly and SQLite. I didn’t test browser rendering, native hosting, or performance.

Sign up for free to 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.

Bug: "License" and "License URI" are missing from Theme Info summary when checking the active theme

2 participants