acf_parse_save_blocks_callback()
Callback used in preg_replace to modify ACF Block comment.
Хуки из функции
Возвращает
Строку.
Использование
acf_parse_save_blocks_callback( $matches );
- $matches(массив) (обязательный)
- The preg matches.
Список изменений
| С версии 5.7.13 | Введена. |
Код acf_parse_save_blocks_callback() acf parse save blocks callback ACF 6.4.2
function acf_parse_save_blocks_callback( $matches ) {
// Defaults.
$name = isset( $matches['name'] ) ? $matches['name'] : '';
$attrs = isset( $matches['attrs'] ) ? json_decode( $matches['attrs'], true ) : '';
$void = isset( $matches['void'] ) ? $matches['void'] : '';
// Bail early if missing data or not an ACF Block.
if ( ! $name || ! $attrs || ! acf_has_block_type( $name ) ) {
return $matches[0];
}
// Check if we need to generate a block ID.
$block_id = acf_ensure_block_id_prefix( acf_get_block_id( $attrs ) );
if ( ! empty( $attrs['data'] ) ) {
if ( acf_block_uses_post_meta( $attrs ) ) {
// Block ID is used later to retrieve & save values.
$attrs['id'] = $block_id;
// Cache the values until we have a post ID and can save.
$store = acf_get_store( 'block-meta-values' );
$store->set( $block_id, $attrs['data'] );
// No need to store values in post content.
unset( $attrs['data'] );
} else {
// Convert "data" to "meta".
// No need to check if already in meta format. Local Meta will do this for us.
$attrs['data'] = acf_setup_meta( $attrs['data'], $block_id );
}
}
/**
* Filters the block attributes before saving.
*
* @since 5.7.14
*
* @param array $attrs The block attributes.
*/
$attrs = apply_filters( 'acf/pre_save_block', $attrs );
// Gutenberg expects a specific encoding format.
$attrs = acf_serialize_block_attributes( $attrs );
return '<!-- wp:' . $name . ' ' . $attrs . ' ' . $void . '-->';
}