acf_render_block()ACF 5.7.12

Renders the block HTML.

Хуков нет.

Возвращает

null. Ничего.

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

acf_render_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.12 Введена.

Код acf_render_block() ACF 5.10.2

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

	// 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 );

	// 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 );

		// Or include template.
	} elseif ( $block['render_template'] ) {

		// Locate template.
		if ( file_exists( $block['render_template'] ) ) {
			$path = $block['render_template'];
		} else {
			$path = locate_template( $block['render_template'] );
		}

		// Include template.
		if ( file_exists( $path ) ) {
			include $path;
		}
	}

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