acf_render_block()ACF 5.7.12

Renders the block HTML.

Хуки из функции

Возвращает

null|Строку.

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

acf_render_block( $attributes, $content, $is_preview, $post_id, $wp_block, $context );
$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
$context(массив)
The block context array.
По умолчанию: false

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

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

Код acf_render_block() ACF 6.0.4

function acf_render_block( $attributes, $content = '', $is_preview = false, $post_id = 0, $wp_block = null, $context = false ) {

	// Prepare block ensuring all settings and attributes exist.
	$block = acf_prepare_block( $attributes );
	if ( ! $block ) {
		return '';
	}

	// Find post_id if not defined.
	if ( ! $post_id ) {
		$post_id = get_the_ID();
	}

	// Enqueue block type assets.
	acf_enqueue_block_type_assets( $block );

	// Ensure block ID is prefixed for render.
	$block['id'] = acf_ensure_block_id_prefix( $block['id'] );

	// Setup postdata allowing get_field() to work.
	acf_setup_meta( $block['data'], $block['id'], true );

	// Call render_callback.
	if ( is_callable( $block['render_callback'] ) ) {
		call_user_func( $block['render_callback'], $block, $content, $is_preview, $post_id, $wp_block, $context );

		// Or include template.
	} elseif ( $block['render_template'] ) {
		do_action( 'acf_block_render_template', $block, $content, $is_preview, $post_id, $wp_block, $context );
	}

	// Reset postdata.
	acf_reset_meta( $block['id'] );
}