acf_prepare_block()ACF 5.8.0

acf_prepare_block

Prepares a block for use in render_callback by merging in all settings and attributes.

Хуков нет.

Возвращает

Массив.

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

acf_prepare_block( $block );
$block(массив) (обязательный)
The block props.

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

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

Код acf_prepare_block() ACF 5.10.2

function acf_prepare_block( $block ) {

	// Bail early if no name.
	if ( ! isset( $block['name'] ) ) {
		return false;
	}

	// Replace className with wpClassName if it's set. This enables support for blocks API v2 filters.
	if ( isset( $block['wpClassName'] ) ) {
		$block['className'] = $block['wpClassName'];
		unset( $block['wpClassName'] );
	}

	// Get block type and return false if doesn't exist.
	$block_type = acf_get_block_type( $block['name'] );
	if ( ! $block_type ) {
		return false;
	}

	// Generate default attributes.
	$attributes = array();
	foreach ( acf_get_block_type_default_attributes( $block_type ) as $k => $v ) {
		$attributes[ $k ] = $v['default'];
	}

	// Merge together arrays in order of least to most specific.
	$block = array_merge( $block_type, $attributes, $block );

	// Return block.
	return $block;
}