Commit dc076845534 for woocommerce
commit dc076845534eadb9888e8843c354162020ef84d6
Author: Vladimir Reznichenko <kalessil@gmail.com>
Date: Tue Oct 20 13:20:17 2026 +0200
[Performance] Micro-optimizations package to compress Woo core initialization execution time (#70011)
Micro-optimizes the Woo core initialization hot path to minimize function/method calls and memory allocations where it makes sense.
diff --git a/plugins/woocommerce/changelog/performance-69369-blocks-hotpath-micro-optimizations-p2 b/plugins/woocommerce/changelog/performance-69369-blocks-hotpath-micro-optimizations-p2
new file mode 100644
index 00000000000..07cea8551ee
--- /dev/null
+++ b/plugins/woocommerce/changelog/performance-69369-blocks-hotpath-micro-optimizations-p2
@@ -0,0 +1,4 @@
+Significance: patch
+Type: performance
+
+Micro-optimizations package to compress Woo core initialization execution time.
diff --git a/plugins/woocommerce/includes/wc-core-functions.php b/plugins/woocommerce/includes/wc-core-functions.php
index cbed7ef7773..0b5401f8041 100644
--- a/plugins/woocommerce/includes/wc-core-functions.php
+++ b/plugins/woocommerce/includes/wc-core-functions.php
@@ -50,9 +50,7 @@ add_filter( 'woocommerce_attribute_label', 'wp_kses_post', 100 );
/**
* Short Description (excerpt).
*/
-if ( function_exists( 'do_blocks' ) ) {
- add_filter( 'woocommerce_short_description', 'do_blocks', 9 );
-}
+add_filter( 'woocommerce_short_description', 'do_blocks', 9 );
add_filter( 'woocommerce_short_description', 'wptexturize' );
add_filter( 'woocommerce_short_description', 'convert_smilies' );
add_filter( 'woocommerce_short_description', 'convert_chars' );
diff --git a/plugins/woocommerce/includes/wc-product-functions.php b/plugins/woocommerce/includes/wc-product-functions.php
index ccf5c9cb691..02c7514eca5 100644
--- a/plugins/woocommerce/includes/wc-product-functions.php
+++ b/plugins/woocommerce/includes/wc-product-functions.php
@@ -417,13 +417,10 @@ add_action( 'template_redirect', 'wc_product_canonical_redirect', 5 );
* @return string
*/
function wc_placeholder_img_src( $size = 'woocommerce_thumbnail' ) {
- $src = WC()->plugin_url() . '/assets/images/placeholder.webp';
$placeholder_image = get_option( 'woocommerce_placeholder_image', 0 );
-
if ( ! empty( $placeholder_image ) ) {
if ( is_numeric( $placeholder_image ) ) {
$image = wp_get_attachment_image_src( $placeholder_image, $size );
-
if ( ! empty( $image[0] ) ) {
$src = $image[0];
}
@@ -432,7 +429,15 @@ function wc_placeholder_img_src( $size = 'woocommerce_thumbnail' ) {
}
}
- return apply_filters( 'woocommerce_placeholder_img_src', $src );
+ /**
+ * Filters the placeholder image source URL.
+ *
+ * @since 1.0.0
+ *
+ * @param string $src Placeholder image URL.
+ * @return string
+ */
+ return apply_filters( 'woocommerce_placeholder_img_src', $src ?? ( WC()->plugin_url() . '/assets/images/placeholder.webp' ) );
}
/**
diff --git a/plugins/woocommerce/includes/wc-user-functions.php b/plugins/woocommerce/includes/wc-user-functions.php
index 727b8b5eda5..dc414372b00 100644
--- a/plugins/woocommerce/includes/wc-user-functions.php
+++ b/plugins/woocommerce/includes/wc-user-functions.php
@@ -1158,11 +1158,6 @@ function wc_update_user_last_active( $user_id ) {
* @return string
*/
function wc_translate_user_roles( $translation, $text, $context ) {
- // translate_user_role() only accepts a second parameter starting in WP 5.2.
- if ( version_compare( get_bloginfo( 'version' ), '5.2', '<' ) ) {
- return $translation;
- }
-
if ( 'User role' === $context && in_array( $text, array( 'Shop manager', 'Customer' ), true ) ) {
return translate_user_role( $text, 'woocommerce' );
}
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index 88d48e1065b..a41a215fc95 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -49533,12 +49533,6 @@ parameters:
count: 1
path: src/Blocks/BlockTypes/ComingSoon.php
- -
- message: '#^Call to function is_null\(\) with mixed will always evaluate to false\.$#'
- identifier: function.impossibleType
- count: 1
- path: src/Blocks/BlockTypes/CustomerAccount.php
-
-
message: '#^Method Automattic\\WooCommerce\\Blocks\\BlockTypes\\CustomerAccount\:\:initialize\(\) has no return type specified\.$#'
identifier: missingType.return
@@ -49575,12 +49569,6 @@ parameters:
count: 1
path: src/Blocks/BlockTypes/CustomerAccount.php
- -
- message: '#^Property Automattic\\WooCommerce\\Blocks\\BlockTypes\\CustomerAccount\:\:\$hooked_block_placements \(array\) in isset\(\) is not nullable\.$#'
- identifier: isset.property
- count: 1
- path: src/Blocks/BlockTypes/CustomerAccount.php
-
-
message: '#^Trying to invoke array\{\$this\(Automattic\\WooCommerce\\Blocks\\BlockTypes\\CustomerAccount\), mixed\} but it might not be a callable\.$#'
identifier: callable.nonCallable
@@ -49683,12 +49671,6 @@ parameters:
count: 2
path: src/Blocks/BlockTypes/HandpickedProducts.php
- -
- message: '#^Call to function is_null\(\) with mixed will always evaluate to false\.$#'
- identifier: function.impossibleType
- count: 1
- path: src/Blocks/BlockTypes/MiniCart.php
-
-
message: '#^Method Automattic\\WooCommerce\\Blocks\\BlockTypes\\MiniCart\:\:enqueue_data\(\) has no return type specified\.$#'
identifier: missingType.return
@@ -49785,24 +49767,12 @@ parameters:
count: 1
path: src/Blocks/BlockTypes/MiniCart.php
- -
- message: '#^Property Automattic\\WooCommerce\\Blocks\\BlockTypes\\MiniCart\:\:\$hooked_block_placements \(array\) in isset\(\) is not nullable\.$#'
- identifier: isset.property
- count: 1
- path: src/Blocks/BlockTypes/MiniCart.php
-
-
message: '#^Result of && is always false\.$#'
identifier: booleanAnd.alwaysFalse
count: 1
path: src/Blocks/BlockTypes/MiniCart.php
- -
- message: '#^Ternary operator condition is always true\.$#'
- identifier: ternary.alwaysTrue
- count: 2
- path: src/Blocks/BlockTypes/MiniCart.php
-
-
message: '#^Trying to invoke array\{\$this\(Automattic\\WooCommerce\\Blocks\\BlockTypes\\MiniCart\), mixed\} but it might not be a callable\.$#'
identifier: callable.nonCallable
@@ -60810,12 +60780,6 @@ parameters:
count: 1
path: src/Internal/Features/FeaturesController.php
- -
- message: '#^Method Automattic\\WooCommerce\\Internal\\Features\\FeaturesController\:\:init_compatibility_info_by_feature\(\) has no return type specified\.$#'
- identifier: missingType.return
- count: 1
- path: src/Internal/Features/FeaturesController.php
-
-
message: '#^Method Automattic\\WooCommerce\\Internal\\Features\\FeaturesController\:\:process_added_option\(\) has no return type specified\.$#'
identifier: missingType.return
diff --git a/plugins/woocommerce/src/Admin/WCAdminHelper.php b/plugins/woocommerce/src/Admin/WCAdminHelper.php
index 84c3172a085..cc674fe125d 100644
--- a/plugins/woocommerce/src/Admin/WCAdminHelper.php
+++ b/plugins/woocommerce/src/Admin/WCAdminHelper.php
@@ -147,7 +147,8 @@ class WCAdminHelper {
* @param array $store_pages The store pages array. The keys are the page slugs and the values are the page IDs.
*/
$store_pages = apply_filters( 'woocommerce_store_pages', $store_pages );
- _prime_post_caches( array_values( array_filter( $store_pages ) ), false, false );
+ $prime_ids = array_values( array_filter( $store_pages, static fn( $page_id ) => $page_id > 0 ) );
+ _prime_post_caches( $prime_ids, false, false );
foreach ( $store_pages as $page_slug => $page_id ) {
if ( $page_id > 0 && is_page( $page_id ) ) {
diff --git a/plugins/woocommerce/src/Blocks/Assets/Api.php b/plugins/woocommerce/src/Blocks/Assets/Api.php
index 1a8c7076ee8..435d5930e7b 100644
--- a/plugins/woocommerce/src/Blocks/Assets/Api.php
+++ b/plugins/woocommerce/src/Blocks/Assets/Api.php
@@ -260,10 +260,11 @@ class Api {
}
// Return asset details as well as the requested dependencies array.
+ $script_dependencies = $this->script_data[ $relative_src ]['dependencies'];
return [
'src' => $this->script_data[ $relative_src ]['src'],
'version' => $this->script_data[ $relative_src ]['version'],
- 'dependencies' => array_merge( $this->script_data[ $relative_src ]['dependencies'], $dependencies ),
+ 'dependencies' => ! empty( $dependencies ) ? array_merge( $script_dependencies, $dependencies ) : $script_dependencies,
];
}
@@ -316,9 +317,7 @@ class Api {
$script_dependencies = apply_filters( 'woocommerce_blocks_register_script_dependencies', $script_data['dependencies'], $handle );
wp_register_script( $handle, $script_data['src'], $script_dependencies, $script_data['version'], true );
-
- if ( $has_i18n && function_exists( 'wp_set_script_translations' ) ) {
- wp_set_script_translations( $handle, 'woocommerce', $this->package->get_path( 'languages' ) );
+ if ( $has_i18n ) {
wp_set_script_translations( $handle, 'woocommerce', $this->package->get_path( 'i18n/languages' ) );
}
}
diff --git a/plugins/woocommerce/src/Blocks/AssetsController.php b/plugins/woocommerce/src/Blocks/AssetsController.php
index 9b7c9412994..f2c1e2bd811 100644
--- a/plugins/woocommerce/src/Blocks/AssetsController.php
+++ b/plugins/woocommerce/src/Blocks/AssetsController.php
@@ -60,9 +60,10 @@ final class AssetsController {
$this->api->get_block_asset_build_path( 'interactivity-blocks-frontend-assets', 'php' )
);
+ $base_path = plugins_url( '/', dirname( __DIR__ ) );
foreach ( $asset_data as $handle => $data ) {
$handle_without_js = str_replace( '.js', '', $handle );
- wp_register_script_module( $handle_without_js, plugins_url( $this->api->get_block_asset_build_path( $handle_without_js ), dirname( __DIR__ ) ), $data['dependencies'], $data['version'] );
+ wp_register_script_module( $handle_without_js, $base_path . $this->api->get_block_asset_build_path( $handle_without_js ), $data['dependencies'], $data['version'] );
}
}
diff --git a/plugins/woocommerce/src/Blocks/BlockPatterns.php b/plugins/woocommerce/src/Blocks/BlockPatterns.php
index 06c84227ce9..dad750b3727 100644
--- a/plugins/woocommerce/src/Blocks/BlockPatterns.php
+++ b/plugins/woocommerce/src/Blocks/BlockPatterns.php
@@ -90,10 +90,6 @@ class BlockPatterns {
* @return void
*/
public function register_block_patterns() {
- if ( ! class_exists( 'WP_Block_Patterns_Registry' ) ) {
- return;
- }
-
foreach ( $this->get_block_patterns() as $pattern ) {
// The pattern list can come from a stale or malformed site transient, so make sure the source is a
// usable string before dereferencing it, to avoid a PHP warning when building the path.
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/AbstractBlock.php b/plugins/woocommerce/src/Blocks/BlockTypes/AbstractBlock.php
index de1b3266fe5..f318907c8e1 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/AbstractBlock.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/AbstractBlock.php
@@ -156,7 +156,8 @@ abstract class AbstractBlock {
* This registers the scripts; it does not enqueue them.
*/
protected function register_block_type_assets() {
- $editor_script = $this->get_block_type_editor_script();
+ // Skip on frontend: WordPress core gates editor script enqueuing on is_admin() (wp-includes/script-loader.php).
+ $editor_script = is_admin() ? $this->get_block_type_editor_script() : null;
if ( is_array( $editor_script ) ) {
$this->register_editor_script_asset( $editor_script );
}
@@ -189,7 +190,7 @@ abstract class AbstractBlock {
$this->add_script_dependencies( $handle, $dependencies );
} else {
$data = $this->asset_api->get_script_data( $path );
- $has_i18n = in_array( 'wp-i18n', $data['dependencies'], true );
+ $has_i18n = ! empty( $data['dependencies'] ) && in_array( 'wp-i18n', $data['dependencies'], true );
$this->asset_api->register_script(
$handle,
@@ -214,7 +215,7 @@ abstract class AbstractBlock {
$this->integration_registry->get_all_registered_script_handles()
);
$data = $this->asset_api->get_script_data( $path );
- $has_i18n = in_array( 'wp-i18n', $data['dependencies'], true );
+ $has_i18n = ! empty( $data['dependencies'] ) && in_array( 'wp-i18n', $data['dependencies'], true );
$this->asset_api->register_script(
$handle,
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/CustomerAccount.php b/plugins/woocommerce/src/Blocks/BlockTypes/CustomerAccount.php
index 8cbb2345596..960a6b6e783 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/CustomerAccount.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/CustomerAccount.php
@@ -44,15 +44,9 @@ class CustomerAccount extends AbstractBlock {
*/
protected function initialize() {
parent::initialize();
- /**
- * The hooked_block_{$hooked_block_type} filter was added in WordPress 6.5.
- * We are the only code adding the filter 'hooked_block_woocommerce/customer-account'.
- * Using has_filter() for a compatibility check won't work because add_filter() is used in the same file.
- */
- if ( version_compare( get_bloginfo( 'version' ), '6.5', '>=' ) ) {
- add_filter( 'hooked_block_woocommerce/customer-account', array( $this, 'modify_hooked_block_attributes' ), 10, 5 );
- add_filter( 'hooked_block_types', array( $this, 'register_hooked_block' ), 9, 4 );
- }
+
+ add_filter( 'hooked_block_woocommerce/customer-account', array( $this, 'modify_hooked_block_attributes' ), 10, 5 );
+ add_filter( 'hooked_block_types', array( $this, 'register_hooked_block' ), 9, 4 );
}
/**
@@ -153,7 +147,7 @@ class CustomerAccount extends AbstractBlock {
<div
class="wp-block-woocommerce-customer-account <?php echo esc_attr( $classes_and_styles['classes'] ); ?>"
style="<?php echo esc_attr( $classes_and_styles['styles'] ); ?>"
- >
+ >
<a
class="wc-block-customer-account__link"
href="<?php echo esc_url( $account_link ); ?>"
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/MiniCart.php b/plugins/woocommerce/src/Blocks/BlockTypes/MiniCart.php
index 89bd72be34d..4013f6261db 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/MiniCart.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/MiniCart.php
@@ -326,9 +326,8 @@ class MiniCart extends AbstractBlock {
$product_count_visibility = isset( $attributes['productCountVisibility'] ) ? $attributes['productCountVisibility'] : 'greater_than_zero';
$wrapper_classes = sprintf( 'wc-block-mini-cart wp-block-woocommerce-mini-cart %s', $classes_styles['classes'] );
$wrapper_styles = $classes_styles['styles'];
- $cart_item_count = $cart ? $cart->get_cart_contents_count() : 0;
+ $cart_item_count = $cart->get_cart_contents_count();
$display_cart_price_including_tax = get_option( 'woocommerce_tax_display_cart' ) === TaxDisplayMode::INCLUSIVE;
- $cart_item_count = $cart ? $cart->get_cart_contents_count() : 0;
$badge_is_visible = ( 'always' === $product_count_visibility ) || ( 'never' !== $product_count_visibility && $cart_item_count > 0 );
$formatted_subtotal = '';
$html = new \WP_HTML_Tag_Processor( wc_price( $cart->get_displayed_subtotal() ) );
diff --git a/plugins/woocommerce/src/Blocks/BlockTypesController.php b/plugins/woocommerce/src/Blocks/BlockTypesController.php
index f1f233f1d6a..b2d6e94131b 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypesController.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypesController.php
@@ -231,12 +231,9 @@ final class BlockTypesController {
*/
public function register_block_metadata() {
$meta_file_path = WC_ABSPATH . 'assets/client/blocks/blocks-json.php';
- if ( function_exists( 'wp_register_block_metadata_collection' ) && file_exists( $meta_file_path ) ) {
+ if ( file_exists( $meta_file_path ) ) {
add_filter( 'doing_it_wrong_trigger_error', array( __CLASS__, 'bypass_block_metadata_doing_it_wrong' ), 10, 4 );
- wp_register_block_metadata_collection(
- WC_ABSPATH . 'assets/client/blocks/',
- $meta_file_path
- );
+ wp_register_block_metadata_collection( WC_ABSPATH . 'assets/client/blocks/', $meta_file_path );
remove_filter( 'doing_it_wrong_trigger_error', array( __CLASS__, 'bypass_block_metadata_doing_it_wrong' ), 10 );
}
}
diff --git a/plugins/woocommerce/src/Blocks/Utils/BlockHooksTrait.php b/plugins/woocommerce/src/Blocks/Utils/BlockHooksTrait.php
index 895222730fb..b5ee7df3563 100644
--- a/plugins/woocommerce/src/Blocks/Utils/BlockHooksTrait.php
+++ b/plugins/woocommerce/src/Blocks/Utils/BlockHooksTrait.php
@@ -19,13 +19,13 @@ trait BlockHooksTrait {
*/
public function register_hooked_block( $hooked_blocks, $position, $anchor_block, $context ) {
// If the block has no hook placements, return early.
- if ( ! isset( $this->hooked_block_placements ) || empty( $this->hooked_block_placements ) ) {
+ if ( empty( $this->hooked_block_placements ) ) {
return $hooked_blocks;
}
// Cache the block hooks version.
static $block_hooks_version = null;
- if ( defined( 'WP_RUN_CORE_TESTS' ) || is_null( $block_hooks_version ) ) {
+ if ( defined( 'WP_RUN_CORE_TESTS' ) || null === $block_hooks_version ) {
$block_hooks_version = get_option( 'woocommerce_hooked_blocks_version' );
}
@@ -39,8 +39,8 @@ trait BlockHooksTrait {
$valid_placements = array_filter(
$this->hooked_block_placements,
function ( $placement ) use ( $block_hooks_version ) {
- $placement_version = isset( $placement['version'] ) ? $placement['version'] : null;
- return is_null( $placement_version ) || ! is_null( $placement_version ) && version_compare( $block_hooks_version, $placement_version, '>=' );
+ $placement_version = $placement['version'] ?? null;
+ return null === $placement_version || version_compare( $block_hooks_version, $placement_version, '>=' );
}
);
diff --git a/plugins/woocommerce/src/Internal/Features/FeaturesController.php b/plugins/woocommerce/src/Internal/Features/FeaturesController.php
index 88c0f0eebfb..262cd796e50 100644
--- a/plugins/woocommerce/src/Internal/Features/FeaturesController.php
+++ b/plugins/woocommerce/src/Internal/Features/FeaturesController.php
@@ -267,6 +267,7 @@ class FeaturesController {
}
$this->features[ $slug ] = $args;
+ $this->init_compatibility_info_by_feature( (string) $slug );
}
/**
@@ -790,9 +791,12 @@ class FeaturesController {
/**
* Initialize the compatibility_info_by_feature property after all the features have been added.
+ *
+ * @param string|null $feature Feature ID (falls back to iterating all features).
+ * @return void
*/
- private function init_compatibility_info_by_feature() {
- foreach ( array_keys( $this->features ) as $feature_id ) {
+ private function init_compatibility_info_by_feature( ?string $feature = null ): void {
+ foreach ( (array) ( $feature ?? array_keys( $this->features ) ) as $feature_id ) {
if ( ! isset( $this->compatibility_info_by_feature[ $feature_id ] ) ) {
$this->compatibility_info_by_feature[ $feature_id ] = array(
FeaturePluginCompatibility::COMPATIBLE => array(),
@@ -936,7 +940,7 @@ class FeaturesController {
* @since 10.5.0
*/
public function get_feature_definition( string $feature_id ): ?array {
- return $this->get_feature_definitions()[ $feature_id ] ?? null;
+ return $this->features[ $feature_id ] ?? $this->get_feature_definitions()[ $feature_id ] ?? null;
}
/**
@@ -949,28 +953,27 @@ class FeaturesController {
* @return bool True if the feature is enabled, false if not or if the feature doesn't exist.
*/
public function feature_is_enabled( string $feature_id ): bool {
- $feature = $this->get_feature_definition( $feature_id );
-
- if ( null === $feature ) {
+ $definition = $this->features[ $feature_id ] ?? $this->get_feature_definitions()[ $feature_id ] ?? null;
+ if ( null === $definition ) {
return false;
}
// Handle deprecated features - return the backwards-compatible value.
- if ( ! empty( $feature['deprecated_since'] ) ) {
- return (bool) ( $feature['deprecated_value'] ?? false );
+ if ( ! empty( $definition['deprecated_since'] ) ) {
+ return (bool) ( $definition['deprecated_value'] ?? false );
}
+ // Dedicated overrides to bypass the settings.
if ( 'analytics' === $feature_id && WCAdminFeatures::is_analytics_disabled_by_legacy_filters() ) {
return false;
}
-
- if ( $this->is_preview_email_improvements_enabled( $feature_id ) ) {
+ if ( 'email_improvements' === $feature_id && $this->is_preview_email_improvements_enabled() ) {
return true;
}
- $default_value = $this->feature_is_enabled_by_default( $feature_id ) ? 'yes' : 'no';
- $value = 'yes' === get_option( $this->feature_enable_option_name( $feature_id ), $default_value );
- return $value;
+ $default_value = ! empty( $definition['enabled_by_default'] ) ? 'yes' : 'no';
+ $option_key = ! empty( $definition['option_key'] ) ? $definition['option_key'] : sprintf( 'woocommerce_feature_%s_enabled', $feature_id );
+ return 'yes' === get_option( $option_key, $default_value );
}
/**
@@ -980,9 +983,9 @@ class FeaturesController {
* @return boolean TRUE if the feature is enabled by default, FALSE otherwise.
*/
private function feature_is_enabled_by_default( string $feature_id ): bool {
- $features = $this->get_feature_definitions();
+ $definition = $this->features[ $feature_id ] ?? $this->get_feature_definitions()[ $feature_id ] ?? null;
- return ! empty( $features[ $feature_id ]['enabled_by_default'] );
+ return ! empty( $definition['enabled_by_default'] );
}
/**
@@ -1131,9 +1134,7 @@ class FeaturesController {
* @return bool True if the feature exists.
*/
private function feature_exists( string $feature_id ): bool {
- $features = $this->get_feature_definitions();
-
- return isset( $features[ $feature_id ] );
+ return null !== ( $this->features[ $feature_id ] ?? $this->get_feature_definitions()[ $feature_id ] ?? null );
}
/**
@@ -1249,13 +1250,9 @@ class FeaturesController {
* @return string The option that enables or disables the feature.
*/
public function feature_enable_option_name( string $feature_id ): string {
- $features = $this->get_feature_definitions();
-
- if ( ! empty( $features[ $feature_id ]['option_key'] ) ) {
- return $features[ $feature_id ]['option_key'];
- }
+ $definition = $this->features[ $feature_id ] ?? $this->get_feature_definitions()[ $feature_id ] ?? null;
- return "woocommerce_feature_{$feature_id}_enabled";
+ return ! empty( $definition['option_key'] ) ? $definition['option_key'] : sprintf( 'woocommerce_feature_%s_enabled', $feature_id );
}
/**
@@ -1267,9 +1264,9 @@ class FeaturesController {
* @return bool TRUE if the compatibility checks should be skipped.
*/
public function should_skip_compatibility_checks( string $feature_id ): bool {
- $features = $this->get_feature_definitions();
+ $definition = $this->features[ $feature_id ] ?? $this->get_feature_definitions()[ $feature_id ] ?? null;
- return ! empty( $features[ $feature_id ]['skip_compatibility_checks'] );
+ return ! empty( $definition['skip_compatibility_checks'] );
}
/**
@@ -2155,21 +2152,16 @@ class FeaturesController {
* 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.
*/
- private function is_preview_email_improvements_enabled( string $feature_id ): bool {
- if ( 'email_improvements' !== $feature_id ) {
- return false;
- }
+ private function is_preview_email_improvements_enabled(): bool {
/**
* This filter is documented in templates/emails/email-styles.php
*
* @since 9.9.0
* @param bool $is_email_preview Whether the email is being previewed.
*/
- $is_email_preview = apply_filters( 'woocommerce_is_email_preview', false );
- if ( $is_email_preview ) {
+ if ( apply_filters( 'woocommerce_is_email_preview', false ) ) {
return get_transient( EmailPreview::TRANSIENT_PREVIEW_EMAIL_IMPROVEMENTS ) === 'yes';
}
return false;