acf_prepare_block()
Prepares a block for use in render_callback by merging in all settings and attributes.
Хуков нет.
Возвращает
Массив|true|false.
Использование
acf_prepare_block( $block );
- $block(массив) (обязательный)
- The block props.
Список изменений
| С версии 5.8.0 | Введена. |
Код acf_prepare_block() acf prepare block ACF 6.4.2
function acf_prepare_block( $block ) {
// Bail early if no name.
if ( ! isset( $block['name'] ) ) {
return false;
}
// Ensure a block ID is always prefixed with `block_` for meta.
$block['id'] = acf_ensure_block_id_prefix( $block['id'] );
// Get block type and return false if doesn't exist.
$block_type = acf_get_block_type( $block['name'] );
if ( ! $block_type ) {
return false;
}
// Prevent protected attributes being overridden.
$protected = array(
'render_template',
'render_callback',
'enqueue_script',
'enqueue_style',
'enqueue_assets',
'post_types',
'use_post_meta',
);
$block = array_diff_key( $block, array_flip( $protected ) );
// 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 );
// Add backward compatibility attributes.
$block = acf_add_back_compat_attributes( $block );
// Return block.
return $block;
}