acf_rendered_block()ACF 5.7.13

Returns the rendered block HTML.

Хуков нет.

Возвращает

Строку. The block HTML.

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

acf_rendered_block( $attributes, $content, $is_preview, $post_id, $wp_block );
$attributes(массив) (обязательный)
The block attributes.
$content(строка)
The block content.
По умолчанию: ''
$is_preview(true|false)
Whether or not the block is being rendered for editing preview.
По умолчанию: false
$post_id(int)
The current post being edited or viewed.
$wp_block(WP_Block)
The block instance (since WP 5.5).
По умолчанию: null

Список изменений

С версии 5.7.13 Введена.

Код acf_rendered_block() ACF 5.10.2

function acf_rendered_block( $attributes, $content = '', $is_preview = false, $post_id = 0, $wp_block = null ) {
	$mode = isset( $attributes['mode'] ) ? $attributes['mode'] : 'auto';

	ob_start();

	if ( 'edit' === $mode && $is_preview ) {
		// Load the block form since we're in edit mode.
		$block = acf_prepare_block( $attributes );
		acf_setup_meta( $block['data'], $block['id'], true );
		$fields = acf_get_block_fields( $block );
		acf_prefix_fields( $fields, "acf-{$block['id']}" );

		echo '<div class="acf-block-fields acf-fields">';
		acf_render_fields( $fields, $block['id'], 'div', 'field' );
		echo '</div>';
	} else {
		// Capture block render output.
		acf_render_block( $attributes, $content, $is_preview, $post_id, $wp_block );
	}

	$html = ob_get_clean();

	if ( 'preview' === $mode && $is_preview ) {
		$html = '<div class="acf-block-preview">' . $html . '</div>';
	}

	// Replace <InnerBlocks /> placeholder on front-end.
	if ( ! $is_preview ) {
		// Escape "$" character to avoid "capture group" interpretation.
		$content = str_replace( '$', '\$', $content );
		$html    = preg_replace( '/<InnerBlocks([\S\s]*?)\/>/', $content, $html );
	}

	// Store in cache for preloading.
	acf_get_store( 'block-cache' )->set( $attributes['id'], $html );
	return $html;
}