acf_get_block_id()ACF 6.0.0

Return or generate a block ID.

Хуков нет.

Возвращает

Строку. A block ID.

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

acf_get_block_id( $attributes, $context );
$attributes(массив) (обязательный)
A block attributes array.
$context(массив)
The block context array.
По умолчанию: an empty array

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

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

Код acf_get_block_id() ACF 6.0.4

function acf_get_block_id( $attributes, $context = array() ) {
	$attributes['_acf_context'] = $context;
	if ( empty( $attributes['id'] ) ) {
		unset( $attributes['id'] );

		// Remove all empty string values as they're not present in JS hash building.
		foreach ( $attributes as $key => $value ) {
			if ( '' === $value ) {
				unset( $attributes[ $key ] );
			}
		}

		// Check if data is empty and remove it if so to match JS hash building.
		if ( isset( $attributes['data'] ) && empty( $attributes['data'] ) ) {
			unset( $attributes['data'] );
		}

		ksort( $attributes );
		return md5( wp_json_encode( $attributes, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) );
	}
	return $attributes['id'];
}