Automattic\WooCommerce\Blocks
BlockTemplatesController::prevent_shortcodes_html_breakage()
Prevents shortcodes in templates having their HTML content broken by wpautop.
Method of the class: BlockTemplatesController{}
No Hooks.
Return
null
. Nothing (null).
Usage
$BlockTemplatesController = new BlockTemplatesController(); $BlockTemplatesController->prevent_shortcodes_html_breakage( $settings, $metadata );
- $settings(array) (required)
- Array of determined settings for registering a block type.
- $metadata(array) (required)
- Metadata provided for registering a block type.
Notes
- See: https://core.trac.wordpress.org/ticket/58366 for more info.
BlockTemplatesController::prevent_shortcodes_html_breakage() BlockTemplatesController::prevent shortcodes html breakage code WC 9.3.3
public function prevent_shortcodes_html_breakage( $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; }