From d56b8b0106e9f188933eb31606e509b1f39d4d63 Mon Sep 17 00:00:00 2001 From: "Michael P. Pfeiffer" Date: Wed, 19 May 2021 11:51:44 +0200 Subject: [PATCH 1/2] Block Widgets: hide legacy widgets with block equivalent --- src/BlockTypesController.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/BlockTypesController.php b/src/BlockTypesController.php index 2cc2f7a183c..a562d7e85a1 100644 --- a/src/BlockTypesController.php +++ b/src/BlockTypesController.php @@ -47,6 +47,7 @@ public function __construct( AssetApi $asset_api, AssetDataRegistry $asset_data_ protected function init() { add_action( 'init', array( $this, 'register_blocks' ) ); add_action( 'woocommerce_login_form_end', array( $this, 'redirect_to_field' ) ); + add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_legacy_widgets_with_block_equivalent' ) ); } /** @@ -76,6 +77,18 @@ public function redirect_to_field() { echo ''; // phpcs:ignore WordPress.Security.NonceVerification } + /** + * Hide legacy widgets with a feature complete block equivalent in the inserter + * and prevent them from showing as an option in the Legacy Widget block. + * + * @param array $widget_types An array of widgets hidden in core. + * @return array $widget_types An array inluding the WooCommerce widgets to hide. + */ + public function hide_legacy_widgets_with_block_equivalent( $widget_types ) { + array_push( $widget_types, 'woocommerce_product_search', 'woocommerce_product_categories', 'woocommerce_products', 'woocommerce_top_rated_products', 'woocommerce_recent_reviews' ); + return $widget_types; + } + /** * Get list of block types. * From 789267a299ef2ff0072156a171371a9f6819dc33 Mon Sep 17 00:00:00 2001 From: "Michael P. Pfeiffer" Date: Wed, 19 May 2021 15:10:28 +0200 Subject: [PATCH 2/2] Unhide Products and Products by Rating widgets --- src/BlockTypesController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BlockTypesController.php b/src/BlockTypesController.php index a562d7e85a1..6046d6ecccf 100644 --- a/src/BlockTypesController.php +++ b/src/BlockTypesController.php @@ -85,7 +85,7 @@ public function redirect_to_field() { * @return array $widget_types An array inluding the WooCommerce widgets to hide. */ public function hide_legacy_widgets_with_block_equivalent( $widget_types ) { - array_push( $widget_types, 'woocommerce_product_search', 'woocommerce_product_categories', 'woocommerce_products', 'woocommerce_top_rated_products', 'woocommerce_recent_reviews' ); + array_push( $widget_types, 'woocommerce_product_search', 'woocommerce_product_categories', 'woocommerce_recent_reviews' ); return $widget_types; }