Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Block Widgets: hide legacy widgets with a feature-complete block equivalent #4237

Merged
merged 2 commits into from
May 21, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/BlockTypesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
}

/**
Expand Down Expand Up @@ -76,6 +77,18 @@ public function redirect_to_field() {
echo '<input type="hidden" name="redirect" value="' . esc_attr( esc_url_raw( wp_unslash( $_GET['redirect_to'] ) ) ) . '" />'; // 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.
*
Expand Down