acf_parse_save_blocks_callback()ACF 5.7.13

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 6.0.4

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_get_block_id( $attrs );

	// Convert "data" to "meta".
	// No need to check if already in meta format. Local Meta will do this for us.
	if ( isset( $attrs['data'] ) ) {
		$attrs['data'] = acf_setup_meta( $attrs['data'], acf_ensure_block_id_prefix( $block_id ) );
	}

	/**
	 * Filters the block attributes before saving.
	 *
	 * @date    18/3/19
	 * @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 . '-->';
}