Automattic\WooCommerce\Blocks\BlockTypes

ComingSoon::enqueue_block_assetspublicWC 1.0

Enqueue coming soon deprecated styles in site editor to support coming soon templates created before WooCommerce 9.8.0.

Метод класса: ComingSoon{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$ComingSoon = new ComingSoon();
$ComingSoon->enqueue_block_assets();

Код ComingSoon::enqueue_block_assets() WC 10.5.2

public function enqueue_block_assets() {
	if ( ! is_admin() ) {
		return;
	}

	$current_screen = get_current_screen();
	if ( $current_screen instanceof \WP_Screen && 'site-editor' !== $current_screen->base ) {
		return;
	}

	$post_id = isset( $_REQUEST['postId'] ) ? wc_clean( wp_unslash( $_REQUEST['postId'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
	if ( 'woocommerce/woocommerce//coming-soon' !== $post_id ) {
		return;
	}

	$block_template = get_block_template( $post_id );
	if ( $block_template ) {
		$parsed_blocks = parse_blocks( $block_template->content );
		foreach ( $parsed_blocks as $block ) {
			if ( isset( $block['blockName'] ) && 'woocommerce/coming-soon' === $block['blockName'] ) {
				// Color attribute is deprecated in WooCommerce 9.8.0.
				if ( isset( $block['attrs']['color'] ) && ! empty( $block['attrs']['color'] ) ) {
					wp_enqueue_style(
						'woocommerce-coming-soon',
						WC()->plugin_url() . '/assets/css/coming-soon-entire-site-deprecated' . ( is_rtl() ? '-rtl' : '' ) . '.css',
						array(),
						Constants::get_constant( 'WC_VERSION' )
					);
					break;
				}
			}
		}
	}
}