acf_get_block_id()
Return or generate a block ID.
Хуков нет.
Возвращает
Строку
. A block ID.
Использование
acf_get_block_id( $attributes, $context, $force );
- $attributes(массив) (обязательный)
- A block attributes array.
- $context(массив)
- The block context array.
По умолчанию: an empty array - $force(true|false)
- If we should generate a new block ID even if one exists.
По умолчанию: false
Список изменений
С версии 6.0.0 | Введена. |
Код acf_get_block_id() acf get block id ACF 6.4.2
function acf_get_block_id( $attributes, $context = array(), $force = false ) { $context = is_array( $context ) ? $context : array(); ksort( $context ); $attributes['_acf_context'] = $context; if ( empty( $attributes['id'] ) || $force ) { 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']; }