Skip to content

Commit

Permalink
Ignore cached plugin data when checking if plugins are WooCommerce-aw…
Browse files Browse the repository at this point in the history
…are (#38836)
  • Loading branch information
rrennick committed Jun 26, 2023
2 parents 95681d2 + a473a00 commit f44694f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
@@ -0,0 +1,4 @@
Significance: patch
Type: tweak

When detecting which plugins are WooCommerce-aware, improve accuracy by ignoring cached plugin data.
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
3 changes: 3 additions & 0 deletions plugins/woocommerce/src/Utilities/PluginUtil.php
Expand Up @@ -65,6 +65,9 @@ final public function init( LegacyProxy $proxy ) {
*/
public function get_woocommerce_aware_plugins( bool $active_only = false ): array {
if ( is_null( $this->woocommerce_aware_plugins ) ) {
// In case `get_plugins` was called much earlier in the request (before our headers could be injected), we
// invalidate the plugin cache list.
wp_cache_delete( 'plugins', 'plugins' );
$all_plugins = $this->proxy->call_function( 'get_plugins' );

$this->woocommerce_aware_plugins =
Expand Down

0 comments on commit f44694f

Please sign in to comment.