plugin updates

This commit is contained in:
Tony Volpe
2024-09-05 11:04:01 -04:00
parent ed6b060261
commit 50cd64dd3d
925 changed files with 16918 additions and 13003 deletions

View File

@@ -228,4 +228,19 @@ final class OrderUtil {
return $count_per_status;
}
/**
* Removes the 'wc-' prefix from status.
*
* @param string $status The status to remove the prefix from.
*
* @return string The status without the prefix.
* @since 9.2.0
*/
public static function remove_status_prefix( string $status ): string {
if ( strpos( $status, 'wc-' ) === 0 ) {
$status = substr( $status, 3 );
}
return $status;
}
}

View File

@@ -5,6 +5,7 @@
namespace Automattic\WooCommerce\Utilities;
use Automattic\WooCommerce\Internal\Features\FeaturesController;
use Automattic\WooCommerce\Internal\Traits\AccessiblePrivateMethods;
use Automattic\WooCommerce\Internal\Utilities\PluginInstaller;
use Automattic\WooCommerce\Proxies\LegacyProxy;
@@ -66,6 +67,34 @@ class PluginUtil {
require_once ABSPATH . WPINC . '/plugin.php';
}
/**
* Wrapper for WP's private `wp_get_active_and_valid_plugins` and `wp_get_active_network_plugins` functions.
*
* This combines the results of the two functions to get a list of all plugins that are active within a site.
* It's more useful than just retrieving the option values because it also validates that the plugin files exist.
* This wrapper is also a hedge against backward-incompatible changes since both of the WP methods are marked as
* being "@access private", so if need be we can update our methods here to preserve functionality.
*
* Note that the doc block for `wp_get_active_and_valid_plugins` says it returns "Array of paths to plugin files
* relative to the plugins directory", but it actually returns absolute paths.
*
* @return string[] Array of absolute paths to plugin files.
*/
public function get_all_active_valid_plugins() {
$local = wp_get_active_and_valid_plugins();
if ( is_multisite() ) {
require_once ABSPATH . WPINC . '/ms-load.php';
$network = wp_get_active_network_plugins();
} else {
$network = array();
}
$all = array_merge( $local, $network );
return array_unique( $all );
}
/**
* Get a list with the names of the WordPress plugins that are WooCommerce aware
* (they have a "WC tested up to" header).
@@ -189,13 +218,12 @@ class PluginUtil {
* the Legacy REST API and HPOS are active.
*
* @param string $feature_id Feature id.
* @param array $plugin_feature_info Array of plugin feature info. See FeaturesControllers->get_compatible_plugins_for_feature() for details.
* @param array $plugin_feature_info Array of plugin feature info, as provided by FeaturesController->get_compatible_plugins_for_feature().
*
* @return string Warning string.
*/
public function generate_incompatible_plugin_feature_warning( string $feature_id, array $plugin_feature_info ): string {
$feature_warning = '';
$incompatibles = array_merge( $plugin_feature_info['incompatible'], $plugin_feature_info['uncertain'] );
$incompatibles = $this->get_items_considered_incompatible( $feature_id, $plugin_feature_info );
$incompatibles = array_filter( $incompatibles, 'is_plugin_active' );
$incompatibles = array_values( array_diff( $incompatibles, $this->get_plugins_excluded_from_compatibility_ui() ) );
$incompatible_count = count( $incompatibles );
@@ -268,7 +296,8 @@ class PluginUtil {
),
admin_url( 'plugins.php' )
);
$feature_warnings[] = sprintf(
$feature_warnings[] = sprintf(
/* translators: %1$s opening link tag %2$s closing link tag. */
__( '%1$sView and manage%2$s', 'woocommerce' ),
'<a href="' . esc_url( $incompatible_plugins_url ) . '">',
@@ -279,6 +308,23 @@ class PluginUtil {
return str_replace( "\n", '<br>', implode( "\n", $feature_warnings ) );
}
/**
* Filter plugin/feature compatibility info, returning the names of the plugins/features that are considered incompatible.
* "Uncertain" information will be included or not depending on the value of the value of the 'plugins_are_incompatible_by_default'
* flag in the feature definition (default is true).
*
* @param string $feature_id Feature id.
* @param array $compatibility_info Array containing "compatible', 'incompatible' and 'uncertain' keys.
* @return array Items in 'incompatible' and 'uncertain' if plugins are incompatible by default with the feature; only items in 'incompatible' otherwise.
*/
public function get_items_considered_incompatible( string $feature_id, array $compatibility_info ): array {
$incompatible_by_default = wc_get_container()->get( FeaturesController::class )->get_plugins_are_incompatible_by_default( $feature_id );
return $incompatible_by_default ?
array_merge( $compatibility_info['incompatible'], $compatibility_info['uncertain'] ) :
$compatibility_info['incompatible'];
}
/**
* Get the names of the plugins that are excluded from the feature compatibility UI.
* These plugins won't be considered as incompatible with any existing feature for the purposes