$compatibles = $this->compatibility_info_by_feature[ $feature ][ FeaturePluginCompatibility::COMPATIBLE ];
$this->compatibility_info_by_feature[ $feature ][ FeaturePluginCompatibility::COMPATIBLE ] = array_diff( $compatibles, array( $plugin_name ) );
$incompatibles = $this->compatibility_info_by_feature[ $feature ][ FeaturePluginCompatibility::INCOMPATIBLE ];
$this->compatibility_info_by_feature[ $feature ][ FeaturePluginCompatibility::INCOMPATIBLE ] = array_diff( $incompatibles, array( $plugin_name ) );
* Handler for the all_plugins filter.
* Returns the list of plugins incompatible with a given plugin
* if we are in the plugins page and the query string of the current request
* looks like '?plugin_status=incompatible_with_feature&feature_id=<feature id>'.
* @param array $plugin_list The original list of plugins.
* @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
public function filter_plugins_list( $plugin_list ): array {
if ( ! $this->verify_did_woocommerce_init() ) {
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput
if ( ! function_exists( 'get_current_screen' ) ||
( get_current_screen() && 'plugins' !== get_current_screen()->id ) ||
'incompatible_with_feature' !== ArrayUtil::get_value_or_default( $_GET, 'plugin_status' ) ) {
$feature_id = $_GET['feature_id'] ?? 'all';
if ( 'all' !== $feature_id && ! $this->feature_exists( $feature_id ) ) {
return $this->get_incompatible_plugins( $feature_id, $plugin_list );
* Returns the list of plugins incompatible with a given feature.
* @param string $feature_id ID of the feature. Can also be `all` to denote all features.
* @param array $plugin_list List of plugins to filter.
* @return array List of plugins incompatible with the given feature.
public function get_incompatible_plugins( $feature_id, $plugin_list ) {
$incompatibles = array();
$plugin_list = array_diff_key( $plugin_list, array_flip( $this->plugins_excluded_from_compatibility_ui ) );
$feature_ids = 'all' === $feature_id ? array_keys( $this->get_feature_definitions() ) : array( $feature_id );
$only_enabled_features = 'all' === $feature_id;
// phpcs:enable WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput
foreach ( array_keys( $plugin_list ) as $plugin_name ) {
if ( ! $this->plugin_util->is_woocommerce_aware_plugin( $plugin_name ) || ! $this->proxy->call_function( 'is_plugin_active', $plugin_name ) ) {
$compatibility_info = $this->get_compatible_features_for_plugin( $plugin_name );
foreach ( $feature_ids as $feature_id ) {
$features_considered_incompatible = array_filter(
$this->plugin_util->get_items_considered_incompatible( $feature_id, $compatibility_info ),
fn( $id ) => $this->feature_is_enabled( $id ) && ! $this->should_skip_compatibility_checks( $id ) :
fn( $id ) => ! $this->should_skip_compatibility_checks( $id )
if ( in_array( $feature_id, $features_considered_incompatible, true ) ) {
$incompatibles[] = $plugin_name;
return array_intersect_key( $plugin_list, array_flip( $incompatibles ) );
* Handler for the admin_notices action.
* @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
public function display_notices_in_plugins_page(): void {
if ( ! $this->verify_did_woocommerce_init() ) {
$feature_filter_description_shown = $this->maybe_display_current_feature_filter_description();
if ( ! $feature_filter_description_shown ) {
$this->maybe_display_feature_incompatibility_warning();
* Shows a warning when there are any incompatibility between active plugins and enabled features.
* The warning is shown in on any admin screen except the plugins screen itself, since
* there's already a "You are viewing plugins that are incompatible" notice.
private function maybe_display_feature_incompatibility_warning(): void {
if ( ! current_user_can( 'activate_plugins' ) ) {
$incompatible_plugins = false;
$relevant_plugins = array_diff( $this->plugin_util->get_woocommerce_aware_plugins( true ), $this->plugins_excluded_from_compatibility_ui );
foreach ( $relevant_plugins as $plugin ) {
$compatibility_info = $this->get_compatible_features_for_plugin( $plugin, true );
$incompatibles = array_filter( $compatibility_info[ FeaturePluginCompatibility::INCOMPATIBLE ], fn( $id ) => ! $this->should_skip_compatibility_checks( $id ) );
if ( ! empty( $incompatibles ) ) {
$incompatible_plugins = true;
$uncertains = array_filter( $compatibility_info[ FeaturePluginCompatibility::UNCERTAIN ], fn( $id ) => ! $this->should_skip_compatibility_checks( $id ) );
foreach ( $uncertains as $feature_id ) {
if ( FeaturePluginCompatibility::COMPATIBLE !== $this->get_default_plugin_compatibility( $feature_id ) ) {
$incompatible_plugins = true;
if ( $incompatible_plugins ) {
if ( ! $incompatible_plugins ) {
'<a href="' . esc_url( add_query_arg( array( 'plugin_status' => 'incompatible_with_feature' ), admin_url( 'plugins.php' ) ) ) . '">',
__( 'WooCommerce has detected that some of your active plugins are incompatible with currently enabled WooCommerce features. Please <a>review the details</a>.', 'woocommerce' )
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
<div class="notice notice-error">
<p><?php echo $message; ?></p>
// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
* Shows a "You are viewing the plugins that are incompatible with the X feature"
* if we are in the plugins page and the query string of the current request
* looks like '?plugin_status=incompatible_with_feature&feature_id=<feature id>'.
private function maybe_display_current_feature_filter_description(): bool {
if ( 'plugins' !== get_current_screen()->id ) {
// phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput
$plugin_status = $_GET['plugin_status'] ?? '';
$feature_id = $_GET['feature_id'] ?? '';
// phpcs:enable WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput
if ( 'incompatible_with_feature' !== $plugin_status ) {
$feature_id = ( '' === $feature_id ) ? 'all' : $feature_id;
if ( 'all' !== $feature_id && ! $this->feature_exists( $feature_id ) ) {
$features = $this->get_feature_definitions();
$plugins_page_url = admin_url( 'plugins.php' );
$features_page_url = $this->get_features_page_url();
? __( 'You are viewing active plugins that are incompatible with currently enabled WooCommerce features.', 'woocommerce' )
/* translators: %s is a feature name. */
__( "You are viewing the active plugins that are incompatible with the '%s' feature.", 'woocommerce' ),
$features[ $feature_id ]['name']
__( "<a href='%1\$s'>View all plugins</a> - <a href='%2\$s'>Manage WooCommerce features</a>", 'woocommerce' ),
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
<div class="notice notice-info">
<p><?php echo $message; ?></p>
// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
* 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
* @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
public 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.
* @param string $plugin_file The id of the plugin for which a row has been rendered in the plugins page.
* @param array $plugin_data Plugin data, as returned by 'get_plugins'.
* @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
public function handle_plugin_list_rows( $plugin_file, $plugin_data ) {
if ( in_array( $plugin_file, $this->plugins_excluded_from_compatibility_ui, true ) ) {
if ( 'incompatible_with_feature' !== ArrayUtil::get_value_or_default( $_GET, 'plugin_status' ) ) { // phpcs:ignore WordPress.Security.NonceVerification
if ( is_null( $wp_list_table ) || ! $this->plugin_util->is_woocommerce_aware_plugin( $plugin_data ) ) {
if ( ! $this->proxy->call_function( 'is_plugin_active', $plugin_file ) ) {
$features = $this->get_feature_definitions();
$feature_compatibility_info = $this->get_compatible_features_for_plugin( $plugin_file, true, true );
$incompatible_features = $feature_compatibility_info[ FeaturePluginCompatibility::INCOMPATIBLE ];
$incompatible_features = array_values(
function ( $feature_id ) {
return ! $this->should_skip_compatibility_checks( $feature_id );
$incompatible_features_count = count( $incompatible_features );
if ( $incompatible_features_count > 0 ) {
$columns_count = $wp_list_table->get_column_count();
$is_active = true; // For now we are showing active plugins in the "Incompatible with..." view.
$is_active_class = $is_active ? 'active' : 'inactive';
$is_active_td_style = $is_active ? " style='border-left: 4px solid #72aee6;'" : '';
if ( 1 === $incompatible_features_count ) {
/* translators: %s = printable plugin name */
__( "âš This plugin is incompatible with the enabled WooCommerce feature '%s', it shouldn't be activated.", 'woocommerce' ),
$features[ $incompatible_features[0] ]['name']
} elseif ( 2 === $incompatible_features_count ) {
/* translators: %1\$s, %2\$s = printable plugin names */
__( "âš This plugin is incompatible with the enabled WooCommerce features '%1\$s' and '%2\$s', it shouldn't be activated.", 'woocommerce' ),
$features[ $incompatible_features[0] ]['name'],
$features[ $incompatible_features[1] ]['name']
/* translators: %1\$s, %2\$s = printable plugin names, %3\$d = plugins count */
__( "âš This plugin is incompatible with the enabled WooCommerce features '%1\$s', '%2\$s' and %3\$d more, it shouldn't be activated.", 'woocommerce' ),
$features[ $incompatible_features[0] ]['name'],
$features[ $incompatible_features[1] ]['name'],
$incompatible_features_count - 2
$features_page_url = $this->get_features_page_url();
$manage_features_message = __( 'Manage WooCommerce features', 'woocommerce' );
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
<tr class='plugin-update-tr update <?php echo $is_active_class; ?>' data-plugin='<?php echo $plugin_file; ?>' data-plugin-row-type='feature-incomp-warn'>
<td colspan='<?php echo $columns_count; ?>' class='plugin-update'<?php echo $is_active_td_style; ?>>
<div class='notice inline notice-warning notice-alt'>
<a href="<?php echo $features_page_url; ?>"><?php echo $manage_features_message; ?></a>
// phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
* Get the URL of the features settings page.
public function get_features_page_url(): string {
return admin_url( 'admin.php?page=wc-settings&tab=advanced§ion=features' );
* Fix for the HTML of the plugins list when there are feature-plugin incompatibility warnings.
* WordPress renders the plugin information rows in the plugins page in <tr> elements as follows:
* - If the plugin needs update, the <tr> will have an "update" class. This will prevent the lower
* border line to be drawn. Later an additional <tr> with an "update available" warning will be rendered,
* it will have a "plugin-update-tr" class which will draw the missing lower border line.
* - Otherwise, the <tr> will be already drawn with the lower border line.
* This is a problem for our rendering of the "plugin is incompatible with X features" warning:
* - If the plugin info <tr> has "update", our <tr> will render nicely right after it; but then
* our own "plugin-update-tr" class will draw an additional line before the "needs update" warning.
* - If not, the plugin info <tr> will render its lower border line right before our compatibility info <tr>.
* This small script fixes this by adding the "update" class to the plugin info <tr> if it doesn't have it
* (so no extra line before our <tr>), or removing 'plugin-update-tr' from our <tr> otherwise
* (and then some extra manual tweaking of margins is needed).
* @param string $current_screen The current screen object.
* @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
public function enqueue_script_to_fix_plugin_list_html( $current_screen ): void {
if ( 'plugins' !== $current_screen->id ) {
$handle = 'wc-features-fix-plugin-list-html';
wp_register_script( $handle, '', array(), WC_VERSION, array( 'in_footer' => true ) );
wp_enqueue_script( $handle );
const warningRows = document.querySelectorAll('tr[data-plugin-row-type=\"feature-incomp-warn\"]');
for(const warningRow of warningRows) {
const pluginName = warningRow.getAttribute('data-plugin');
const pluginInfoRow = document.querySelector('tr.active[data-plugin=\"' + pluginName + '\"]:not(.plugin-update-tr), tr.inactive[data-plugin=\"' + pluginName + '\"]:not(.plugin-update-tr)');
if(pluginInfoRow.classList.contains('update')) {
warningRow.classList.remove('plugin-update-tr');
warningRow.querySelector('.notice').style.margin = '5px 10px 15px 30px';
pluginInfoRow.classList.add('update');
* Handler for the 'views_plugins' hook that shows the links to the different views in the plugins page.
* If we come from a "Manage incompatible plugins" in the features page we'll show just two views:
* "All" (so that it's easy to go back to a known state) and "Incompatible with X".
* We'll skip the rest of the views since the counts are wrong anyway, as we are modifying
* the plugins list via the 'all_plugins' filter.
* @param array $views An array of view ids => view links.
* @return string[] The actual views array to use.
* @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
public function handle_plugins_page_views_list( $views ): array {
// phpcs:disable WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput
if ( 'incompatible_with_feature' !== ArrayUtil::get_value_or_default( $_GET, 'plugin_status' ) ) {
$feature_id = $_GET['feature_id'] ?? 'all';
if ( 'all' !== $feature_id && ! $this->feature_exists( $feature_id ) ) {
// phpcs:enable WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput
$all_items = get_plugins();
$features = $this->get_feature_definitions();
$incompatible_plugins_count = count( $this->filter_plugins_list( $all_items ) );
? __( 'Incompatible with WooCommerce features', 'woocommerce' )
/* translators: %s = name of a WooCommerce feature */
: sprintf( __( "Incompatible with '%s'", 'woocommerce' ), $features[ $feature_id ]['name'] );
$incompatible_link = "<a href='plugins.php?plugin_status=incompatible_with_feature&feature_id={$feature_id}' class='current' aria-current='page'>{$incompatible_text} <span class='count'>({$incompatible_plugins_count})</span></a>";
$all_plugins_count = count( $all_items );
$all_text = __( 'All', 'woocommerce' );
$all_link = "<a href='plugins.php?plugin_status=all'>{$all_text} <span class='count'>({$all_plugins_count})</span></a>";
'incompatible_with_feature' => $incompatible_link,
* Set the feature nonce to be sent from client side.
* @param array $settings Component settings.
* @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
public function set_change_feature_enable_nonce( $settings ) {
$settings['_feature_nonce'] = wp_create_nonce( 'change_feature_enable' );
* Changes the feature given it's id, a toggle value and nonce as a query param.
* `/wp-admin/post.php?product_block_editor=1&_feature_nonce=1234`, 1 for on
* `/wp-admin/post.php?product_block_editor=0&_feature_nonce=1234`, 0 for off
* @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
public function change_feature_enable_from_query_params(): void {
if ( ! current_user_can( 'manage_woocommerce' ) ) {
$is_feature_nonce_invalid = ( ! isset( $_GET['_feature_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_feature_nonce'] ) ), 'change_feature_enable' ) );
$query_params_to_remove = array( '_feature_nonce' );
foreach ( array_keys( $this->get_feature_definitions() ) as $feature_id ) {
if ( isset( $_GET[ $feature_id ] ) && is_numeric( $_GET[ $feature_id ] ) ) {
$value = absint( $_GET[ $feature_id ] );
if ( $is_feature_nonce_invalid ) {
wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'woocommerce' ) );
$this->change_feature_enable( $feature_id, true );
} elseif ( 0 === $value ) {
$this->change_feature_enable( $feature_id, false );
$query_params_to_remove[] = $feature_id;
if ( count( $query_params_to_remove ) > 1 && isset( $_SERVER['REQUEST_URI'] ) ) {
// phpcs:disable WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
wp_safe_redirect( remove_query_arg( $query_params_to_remove, $_SERVER['REQUEST_URI'] ) );
* Display the email improvements feedback notice to render CES modal in.
* @param string $feature_id The feature id.
* @param bool $is_enabled Whether the feature is enabled.
* @internal For exclusive usage of WooCommerce core, backwards compatibility not guaranteed.
public function display_email_improvements_feedback_notice( $feature_id, $is_enabled ): void {
if ( 'email_improvements' === $feature_id && ! $is_enabled ) {
set_transient( 'wc_settings_email_improvements_reverted', 'yes', 15 );
echo '<div id="wc_settings_features_email_feedback_slotfill"></div>';
* Check if the email improvements feature is enabled in preview mode in Settings > Emails.
* This is used to force the email improvements feature without affecting shoppers.
* @param string $feature_id The feature id.
* @return bool Whether the email improvements feature is enabled in preview mode.