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

Commit

Permalink
Block Widgets: hide legacy widgets with a feature-complete block equi…
Browse files Browse the repository at this point in the history
…valent (#4237)

* Block Widgets: hide legacy widgets with block equivalent

* Unhide Products and Products by Rating widgets
  • Loading branch information
frontdevde authored and grogou committed Aug 20, 2021
1 parent 47556b9 commit b7eabf5
Showing 1 changed file with 13 additions and 0 deletions.
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_recent_reviews' );
return $widget_types;
}

/**
* Get list of block types.
*
Expand Down

0 comments on commit b7eabf5

Please sign in to comment.