From ae6c278e532bd2e1e002e1675a8e57ac52ea1a59 Mon Sep 17 00:00:00 2001 From: "Jorge A. Torres" Date: Thu, 22 Aug 2024 20:06:49 -0300 Subject: [PATCH] Cherry-pick PR#50881 into trunk (#50897) * Revert "PluginUtil: Add method to get active valid plugins (#48709)" This reverts commit 4d68cd486e07b3dabffe307157ddfe3737eb39c5. * Reintroduce get_all_active_valid_plugins public function after revert (#50885) Retroduce get_all_active_valid_plugins public function after revert --------- Co-authored-by: Naman Malhotra --- plugins/woocommerce/includes/class-wc-install.php | 5 ++--- .../class-wc-rest-system-status-v2-controller.php | 15 ++++++++++----- .../src/Internal/Utilities/PluginInstaller.php | 11 ++--------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/plugins/woocommerce/includes/class-wc-install.php b/plugins/woocommerce/includes/class-wc-install.php index e6d591d8d11..a5915ec3172 100644 --- a/plugins/woocommerce/includes/class-wc-install.php +++ b/plugins/woocommerce/includes/class-wc-install.php @@ -17,7 +17,7 @@ use Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories\Synchro use Automattic\WooCommerce\Internal\Utilities\DatabaseUtil; use Automattic\WooCommerce\Internal\WCCom\ConnectionHelper as WCConnectionHelper; use Automattic\WooCommerce\Internal\Traits\AccessiblePrivateMethods; -use Automattic\WooCommerce\Utilities\{ OrderUtil, PluginUtil }; +use Automattic\WooCommerce\Utilities\OrderUtil; use Automattic\WooCommerce\Internal\Utilities\PluginInstaller; defined( 'ABSPATH' ) || exit; @@ -1283,8 +1283,7 @@ class WC_Install { return; } - $active_valid_plugins = wc_get_container()->get( PluginUtil::class )->get_all_active_valid_plugins(); - if ( in_array( $legacy_api_plugin, $active_valid_plugins, true ) ) { + if ( in_array( $legacy_api_plugin, wp_get_active_and_valid_plugins(), true ) ) { return; } diff --git a/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php b/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php index 0d663686c33..8c5caec0bd6 100644 --- a/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php +++ b/plugins/woocommerce/includes/rest-api/Controllers/Version2/class-wc-rest-system-status-v2-controller.php @@ -13,7 +13,7 @@ defined( 'ABSPATH' ) || exit; use Automattic\WooCommerce\Internal\WCCom\ConnectionHelper; use Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories\Register as Download_Directories; use Automattic\WooCommerce\Internal\DataStores\Orders\DataSynchronizer as Order_DataSynchronizer; -use Automattic\WooCommerce\Utilities\{ LoggingUtil, OrderUtil, PluginUtil }; +use Automattic\WooCommerce\Utilities\{ LoggingUtil, OrderUtil }; /** * System status controller class. @@ -1044,11 +1044,16 @@ class WC_REST_System_Status_V2_Controller extends WC_REST_Controller { return array(); } - $active_valid_plugins = wc_get_container()->get( PluginUtil::class )->get_all_active_valid_plugins(); - $active_plugins_data = array(); + $active_plugins = (array) get_option( 'active_plugins', array() ); + if ( is_multisite() ) { + $network_activated_plugins = array_keys( get_site_option( 'active_sitewide_plugins', array() ) ); + $active_plugins = array_merge( $active_plugins, $network_activated_plugins ); + } - foreach ( $active_valid_plugins as $plugin ) { - $data = get_plugin_data( $plugin ); + $active_plugins_data = array(); + + foreach ( $active_plugins as $plugin ) { + $data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); $active_plugins_data[] = $this->format_plugin_data( $plugin, $data ); } diff --git a/plugins/woocommerce/src/Internal/Utilities/PluginInstaller.php b/plugins/woocommerce/src/Internal/Utilities/PluginInstaller.php index c3acb6ba4a9..c1985ca81d3 100644 --- a/plugins/woocommerce/src/Internal/Utilities/PluginInstaller.php +++ b/plugins/woocommerce/src/Internal/Utilities/PluginInstaller.php @@ -4,7 +4,7 @@ namespace Automattic\WooCommerce\Internal\Utilities; use Automattic\WooCommerce\Internal\RegisterHooksInterface; use Automattic\WooCommerce\Internal\Traits\AccessiblePrivateMethods; -use Automattic\WooCommerce\Utilities\{ PluginUtil, StringUtil }; +use Automattic\WooCommerce\Utilities\StringUtil; /** * This class allows installing a plugin programmatically. @@ -206,14 +206,7 @@ class PluginInstaller implements RegisterHooksInterface { * @return bool True if WooCommerce is installed and active in the current blog, false otherwise. */ private static function woocommerce_is_active_in_current_site(): bool { - $active_valid_plugins = wc_get_container()->get( PluginUtil::class )->get_all_active_valid_plugins(); - - return ! empty( - array_filter( - $active_valid_plugins, - fn( $plugin ) => substr_compare( $plugin, '/woocommerce.php', -strlen( '/woocommerce.php' ) ) === 0 - ) - ); + return ! empty( array_filter( wp_get_active_and_valid_plugins(), fn( $plugin ) => substr_compare( $plugin, '/woocommerce.php', -strlen( '/woocommerce.php' ) ) === 0 ) ); } /**