Automattic\WooCommerce\Blocks
BlockTemplatesController::init()
Initialization method.
Метод класса: BlockTemplatesController{}
Хуков нет.
Возвращает
null
. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->init();
Код BlockTemplatesController::init() BlockTemplatesController::init WC 8.7.0
protected function init() { add_filter( 'default_wp_template_part_areas', array( $this, 'register_mini_cart_template_part_area' ), 10, 1 ); add_action( 'template_redirect', array( $this, 'render_block_template' ) ); add_filter( 'pre_get_block_template', array( $this, 'get_block_template_fallback' ), 10, 3 ); add_filter( 'pre_get_block_file_template', array( $this, 'get_block_file_template' ), 10, 3 ); add_filter( 'get_block_template', array( $this, 'add_block_template_details' ), 10, 1 ); add_filter( 'get_block_templates', array( $this, 'add_block_templates' ), 10, 3 ); add_filter( 'current_theme_supports-block-templates', array( $this, 'remove_block_template_support_for_shop_page' ) ); add_filter( 'taxonomy_template_hierarchy', array( $this, 'add_archive_product_to_eligible_for_fallback_templates' ), 10, 1 ); add_filter( 'post_type_archive_title', array( $this, 'update_product_archive_title' ), 10, 2 ); add_action( 'after_switch_theme', array( $this, 'check_should_use_blockified_product_grid_templates' ), 10, 2 ); if ( wc_current_theme_is_fse_theme() ) { // By default, the Template Part Block only supports template parts that are in the current theme directory. // This render_callback wrapper allows us to add support for plugin-housed template parts. add_filter( 'block_type_metadata_settings', function( $settings, $metadata ) { if ( isset( $metadata['name'], $settings['render_callback'] ) && 'core/template-part' === $metadata['name'] && in_array( $settings['render_callback'], [ 'render_block_core_template_part', 'gutenberg_render_block_core_template_part' ], true ) ) { $settings['render_callback'] = [ $this, 'render_woocommerce_template_part' ]; } return $settings; }, 10, 2 ); // Prevents shortcodes in templates having their HTML content broken by wpautop. // @see https://core.trac.wordpress.org/ticket/58366 for more info. add_filter( 'block_type_metadata_settings', function( $settings, $metadata ) { if ( isset( $metadata['name'], $settings['render_callback'] ) && 'core/shortcode' === $metadata['name'] ) { $settings['original_render_callback'] = $settings['render_callback']; $settings['render_callback'] = function( $attributes, $content ) use ( $settings ) { // The shortcode has already been rendered, so look for the cart/checkout HTML. if ( strstr( $content, 'woocommerce-cart-form' ) || strstr( $content, 'wc-empty-cart-message' ) || strstr( $content, 'woocommerce-checkout-form' ) ) { // Return early before wpautop runs again. return $content; } $render_callback = $settings['original_render_callback']; return $render_callback( $attributes, $content ); }; } return $settings; }, 10, 2 ); /** * Prevents the pages that are assigned as cart/checkout from showing the "template" selector in the page-editor. * We want to avoid this flow and point users towards the site editor instead. */ add_action( 'current_screen', function () { if ( ! is_admin() ) { return; } $current_screen = get_current_screen(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( $current_screen && 'page' === $current_screen->id && ! empty( $_GET['post'] ) && in_array( absint( $_GET['post'] ), [ wc_get_page_id( 'cart' ), wc_get_page_id( 'checkout' ) ], true ) ) { wp_add_inline_style( 'wc-blocks-editor-style', '.edit-post-post-template { display: none; }' ); } }, 10 ); } }