Automattic\WooCommerce\Blocks

BlockTemplatesController::prevent_shortcodes_html_breakage()publicWC 1.0

Prevents shortcodes in templates having their HTML content broken by wpautop.

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

Хуков нет.

Возвращает

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

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

$BlockTemplatesController = new BlockTemplatesController();
$BlockTemplatesController->prevent_shortcodes_html_breakage( $settings, $metadata );
$settings(массив) (обязательный)
Array of determined settings for registering a block type.
$metadata(массив) (обязательный)
Metadata provided for registering a block type.

Заметки

Код BlockTemplatesController::prevent_shortcodes_html_breakage() 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;
}