Skip to content

Commit

Permalink
Selectively invalidate cached plugin data when needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
barryhughes committed Jun 20, 2023
1 parent 1c2dd45 commit a473a00
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions plugins/woocommerce/src/Internal/Features/FeaturesController.php
Expand Up @@ -134,6 +134,7 @@ public function __construct() {
self::add_filter( 'deactivated_plugin', array( $this, 'handle_plugin_deactivation' ), 10, 1 );
self::add_filter( 'all_plugins', array( $this, 'filter_plugins_list' ), 10, 1 );
self::add_action( 'admin_notices', array( $this, 'display_notices_in_plugins_page' ), 10, 0 );
self::add_action( 'load-plugins.php', array( $this, 'maybe_invalidate_cached_plugin_data' ) );
self::add_action( 'after_plugin_row', array( $this, 'handle_plugin_list_rows' ), 10, 2 );
self::add_action( 'current_screen', array( $this, 'enqueue_script_to_fix_plugin_list_html' ), 10, 1 );
self::add_filter( 'views_plugins', array( $this, 'handle_plugins_page_views_list' ), 10, 1 );
Expand Down Expand Up @@ -911,6 +912,24 @@ private function maybe_display_current_feature_filter_description(): bool {
return true;
}

/**
* If the 'incompatible with features' plugin list is being rendered, invalidate existing cached plugin data.
*
* This heads off a problem in which WordPress's `get_plugins()` function may be called much earlier in the request
* (by third party code, for example), the results of which are cached, and before WooCommerce can modify the list
* to inject useful information of its own.
*
* @see https://github.com/woocommerce/woocommerce/issues/37343
*
* @return void
*/
private function maybe_invalidate_cached_plugin_data(): void {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( ( $_GET['plugin_status'] ?? '' ) === 'incompatible_with_feature' ) {
wp_cache_delete( 'plugins', 'plugins' );
}
}

/**
* Handler for the 'after_plugin_row' action.
* Displays a "This plugin is incompatible with X features" notice if necessary.
Expand Down

0 comments on commit a473a00

Please sign in to comment.