Skip to content

Meta Description: SEO plugin detection cache never expires and skips the "no plugin" case #970

Description

@hbhalodia

Description

SEO_Integration::detect_active_plugin() caches the active SEO plugin (to pick the meta-description meta key) in the wpai_active_seo_plugin transient,

  1. The positive result is stored with no expiry and is only cleared on deactivated_plugin - a hook that's registered only while the Meta Description experiment is enabled. So the cache can go stale and never self-heal.
  2. The "no SEO plugin active" result is never cached, so a full plugin scan runs on every call, including the front-end output_meta_description() path.

Code

includes/Abilities/Meta_Description/SEO_Integration.php:78-96

$active_plugin = get_transient( 'wpai_active_seo_plugin' );
if ( ! empty( $active_plugin ) ) {
	return $active_plugin;
}
// ...
foreach ( self::get_supported_plugins() as $slug => $info ) {
	if ( is_plugin_active( $info['file'] ) ) {
		set_transient( 'wpai_active_seo_plugin', $slug ); // no expiry
		return $slug;
	}
}
return null; // never cached

Invalidation (only when the experiment is on): includes/Experiments/Meta_Description/Meta_Description.php:60 (deactivated_plugin) and :165 (delete_transient). No activated_plugin handling.

Step-by-step reproduction instructions

  1. Activate a supported SEO plugin (e.g. Yoast) + enable the Meta Description experiment; trigger meta handling once to cache the slug.
  2. Disable the Meta Description experiment.
  3. Deactivate the SEO plugin.
  4. Re-enable the experiment → detection still returns the deactivated plugin's slug, and never corrects itself (no expiry).

Impact

  • Stale cache: if the SEO plugin changes while the experiment is disabled (so the clear hook isn't registered), the cached slug persists forever, and meta descriptions are read/written under the wrong meta key.
  • Performance: sites with no supported SEO plugin re-scan all plugins (is_plugin_active()) on every meta-description call.

Affected files

  • includes/Abilities/Meta_Description/SEO_Integration.php (78-96)
  • includes/Experiments/Meta_Description/Meta_Description.php (60, 165)

Suggested fix

  • Give the positive transient a TTL (e.g. DAY_IN_SECONDS).
  • Cache the "none detected" result too (sentinel value + TTL).
  • Also invalidate on activated_plugin, or make invalidation independent of the experiment toggle.

Screenshots, screen recording, code snippet

Screen.Recording.2026-08-24.at.9.07.02.PM.mov

Environment info

  • WordPress Latest.
  • AI plugin develop branch

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except the AI plugin.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Activity

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

Metadata

Metadata

Assignees

Labels

[Type] BugSomething isn't working

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions