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

Commit e319530

Browse files
roykhomikejolley
authored andcommitted
Revert "Update the logic of disabling some blocks in the widget areas and post editor (#9462)"
This reverts commit 0e1d6bd.
1 parent 21e06b6 commit e319530

File tree

1 file changed

+34
-41
lines changed

1 file changed

+34
-41
lines changed

src/BlockTypesController.php

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ protected function init() {
5252
add_filter( 'render_block', array( $this, 'add_data_attributes' ), 10, 2 );
5353
add_action( 'woocommerce_login_form_end', array( $this, 'redirect_to_field' ) );
5454
add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_legacy_widgets_with_block_equivalent' ) );
55-
add_filter( 'allowed_block_types_all', array( $this, 'disable_blocks_depending_on_context' ), 10, 2 );
5655
}
5756

5857
/**
@@ -161,52 +160,14 @@ public function hide_legacy_widgets_with_block_equivalent( $widget_types ) {
161160
return $widget_types;
162161
}
163162

164-
/**
165-
* Disable specific woocommerce blocks on the widgets area, post and page editor.
166-
*
167-
* @param bool|string[] $allowed_block_types Array of block type slugs, or boolean to enable/disable all. Default true (all registered block types supported).
168-
* @param WP_Block_Editor_Context $block_editor_context The current block editor context.
169-
*
170-
* @return array|bool The updated allowed block types depending on context
171-
*/
172-
public function disable_blocks_depending_on_context( $allowed_block_types, $block_editor_context ) {
173-
$registered_blocks = \WP_Block_Type_Registry::get_instance()->get_all_registered();
174-
175-
/**
176-
* This disables specific blocks in Widget Areas.
177-
*/
178-
if ( 'core/edit-widgets' === $block_editor_context->name && is_array( $registered_blocks ) && ! empty( $registered_blocks ) ) {
179-
unset( $registered_blocks['woocommerce/cart'] );
180-
unset( $registered_blocks['woocommerce/all-products'] );
181-
unset( $registered_blocks['woocommerce/checkout'] );
182-
183-
return array_keys( $registered_blocks );
184-
}
185-
186-
/**
187-
* This disables specific blocks in Post and Page editor.
188-
*/
189-
if ( 'core/edit-post' === $block_editor_context->name && is_array( $registered_blocks ) && ! empty( $registered_blocks ) ) {
190-
unset( $registered_blocks['woocommerce/add-to-cart-form'] );
191-
unset( $registered_blocks['woocommerce/breadcrumbs'] );
192-
unset( $registered_blocks['woocommerce/catalog-sorting'] );
193-
unset( $registered_blocks['woocommerce/legacy-template'] );
194-
unset( $registered_blocks['woocommerce/product-results-count'] );
195-
unset( $registered_blocks['woocommerce/product-details'] );
196-
unset( $registered_blocks['woocommerce/store-notices'] );
197-
198-
return array_keys( $registered_blocks );
199-
}
200-
201-
return $allowed_block_types;
202-
}
203-
204163
/**
205164
* Get list of block types.
206165
*
207166
* @return array
208167
*/
209168
protected function get_block_types() {
169+
global $pagenow;
170+
210171
$block_types = [
211172
'ActiveFilters',
212173
'AddToCartForm',
@@ -268,6 +229,38 @@ protected function get_block_types() {
268229
$block_types[] = 'ProductTemplate';
269230
}
270231

232+
/**
233+
* This disables specific blocks in Widget Areas by not registering them.
234+
*/
235+
if ( in_array( $pagenow, [ 'widgets.php', 'themes.php', 'customize.php' ], true ) && ( empty( $_GET['page'] ) || 'gutenberg-edit-site' !== $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
236+
$block_types = array_diff(
237+
$block_types,
238+
[
239+
'AllProducts',
240+
'Cart',
241+
'Checkout',
242+
]
243+
);
244+
}
245+
246+
/**
247+
* This disables specific blocks in Post and Page editor by not registering them.
248+
*/
249+
if ( in_array( $pagenow, [ 'post.php', 'post-new.php' ], true ) ) {
250+
$block_types = array_diff(
251+
$block_types,
252+
[
253+
'AddToCartForm',
254+
'Breadcrumbs',
255+
'CatalogSorting',
256+
'ClassicTemplate',
257+
'ProductResultsCount',
258+
'ProductDetails',
259+
'StoreNotices',
260+
]
261+
);
262+
}
263+
271264
return $block_types;
272265
}
273266

0 commit comments

Comments
 (0)