From b7eabf54bad4b7e08c7f4ef1484f7fea7ab64f20 Mon Sep 17 00:00:00 2001 From: "Michael P. Pfeiffer" Date: Fri, 21 May 2021 09:53:46 +0200 Subject: [PATCH] Block Widgets: hide legacy widgets with a feature-complete block equivalent (#4237) * Block Widgets: hide legacy widgets with block equivalent * Unhide Products and Products by Rating widgets --- src/BlockTypesController.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/BlockTypesController.php b/src/BlockTypesController.php index 27535df178c..4d8776bd50a 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_recent_reviews' ); + return $widget_types; + } + /** * Get list of block types. *