bute data- attributes appended on render. * * @since 5.9.0 * * @param array $allowed_namespaces List of namespaces. */ $allowed_blocks = (array) apply_filters( '__experimental_woocommerce_blocks_add_data_attributes_to_block', array() ); if ( ! in_array( $block_namespace, $allowed_namespaces, true ) && ! in_array( $block_name, $allowed_blocks, true ) ) { return $content; } $attributes = (array) $block['attrs']; $exclude_attributes = array( 'className', 'align' ); $escaped_data_attributes = array( 'data-block-name="' . esc_attr( $block['blockName'] ) . '"', ); foreach ( $attributes as $key => $value ) { if ( in_array( $key, $exclude_attributes, true ) ) { continue; } if ( is_bool( $value ) ) { $value = $value ? 'true' : 'false'; } if ( ! is_scalar( $value ) ) { $value = wp_json_encode( $value ); } $escaped_data_attributes[] = 'data-' . esc_attr( strtolower( preg_replace( '/(?'; // 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', 'woocommerce_product_tag_cloud', 'woocommerce_price_filter', 'woocommerce_layered_nav', 'woocommerce_layered_nav_filters', 'woocommerce_rating_filter' ); return $widget_types; } /** * Delete product transients when a product is deleted. */ public function delete_product_transients() { delete_transient( 'wc_blocks_has_downloadable_product' ); } /** * Get list of block types. * * @return array */ protected function get_block_types() { global $pagenow; $block_types = array( 'ActiveFilters', 'AddToCartForm', 'AllProducts', 'AllReviews', 'AttributeFilter', 'Breadcrumbs', 'CatalogSorting', 'ClassicTemplate', 'ClassicShortcode', 'CustomerAccount', 'FeaturedCategory', 'FeaturedProduct', 'FilterWrapper', 'HandpickedProducts', 'MiniCart', 'StoreNotices', 'PriceFilter', 'ProductAddToCart', 'ProductBestSellers', 'ProductButton', 'ProductCategories', 'ProductCategory', 'ProductCollection', 'ProductCollectionNoResults', 'ProductGallery', 'ProductGalleryLargeImage', 'ProductGalleryLargeImageNextPrevious', 'ProductGalleryPager', 'ProductGalleryThumbnails', 'ProductImage', 'ProductImageGallery', 'ProductNew', 'ProductOnSale', 'ProductPrice', 'ProductTemplate', 'ProductQuery', 'ProductAverageRating', 'ProductRating', 'ProductRatingCounter', 'ProductRatingStars', 'ProductResultsCount', 'ProductReviews', 'ProductSaleBadge', 'ProductSearch', 'ProductSKU', 'ProductStockIndicator', 'ProductSummary', 'ProductTag', 'ProductTitle', 'ProductTopRated', 'ProductsByAttribute', 'RatingFilter', 'ReviewsByCategory', 'ReviewsByProduct', 'RelatedProducts', 'ProductDetails', 'SingleProduct', 'StockFilter', 'PageContentWrapper', 'OrderConfirmation\Status', 'OrderConfirmation\Summary', 'OrderConfirmation\Totals', 'OrderConfirmation\TotalsWrapper', 'OrderConfirmation\Downloads', 'OrderConfirmation\DownloadsWrapper', 'OrderConfirmation\BillingAddress', 'OrderConfirmation\ShippingAddress', 'OrderConfirmation\BillingWrapper', 'OrderConfirmation\ShippingWrapper', 'OrderConfirmation\AdditionalInformation', 'OrderConfirmation\AdditionalFieldsWrapper', 'OrderConfirmation\AdditionalFields', ); $block_types = array_merge( $block_types, Cart::get_cart_block_types(), Checkout::get_checkout_block_types(), MiniCartContents::get_mini_cart_block_types() ); if ( Package::feature()->is_experimental_build() ) { $block_types[] = 'ProductFilter'; $block_types[] = 'ProductFilterStockStatus'; $block_types[] = 'ProductFilterPrice'; $block_types[] = 'ProductFilterAttribute'; $block_types[] = 'ProductFilterRating'; $block_types[] = 'ProductFilterActive'; } /** * This disables specific blocks in Widget Areas by not registering them. */ if ( in_array( $pagenow, array( 'widgets.php', 'themes.php', 'customize.php' ), true ) && ( empty( $_GET['page'] ) || 'gutenberg-edit-site' !== $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification $block_types = array_diff( $block_types, array( 'AllProducts', 'Cart', 'Checkout', ) ); } /** * This disables specific blocks in Post and Page editor by not registering them. */ if ( in_array( $pagenow, array( 'post.php', 'post-new.php' ), true ) ) { $block_types = array_diff( $block_types, array( 'AddToCartForm', 'Breadcrumbs', 'CatalogSorting', 'ClassicTemplate', 'ProductResultsCount', 'ProductDetails', 'OrderConfirmation\Status', 'OrderConfirmation\Summary', 'OrderConfirmation\Totals', 'OrderConfirmation\TotalsWrapper', 'OrderConfirmation\Downloads', 'OrderConfirmation\DownloadsWrapper', 'OrderConfirmation\BillingAddress', 'OrderConfirmation\ShippingAddress', 'OrderConfirmation\BillingWrapper', 'OrderConfirmation\ShippingWrapper', 'OrderConfirmation\AdditionalInformation', 'OrderConfirmation\AdditionalFieldsWrapper', 'OrderConfirmation\AdditionalFields', ) ); } return $block_types; } }