_acf_track_synced_pattern()
The internal ACF function to record that blocks rendered by a synced pattern are saved in the pattern, by wrapping the render callback of the core/block block type.
A synced pattern renders its blocks by rendering its own block instance again, so the render_block runs twice for it and can't be used to find where the pattern ends.
Внутренняя функция — эта функция рассчитана на использование самим ядром. Не рекомендуется использовать эту функцию в своем коде.
Хуков нет.
Возвращает
array. The block type's arguments.
Использование
_acf_track_synced_pattern( $args, $block_type );
- $args(массив) (обязательный)
- The block type's arguments.
- $block_type(строка) (обязательный)
- The block type's name.
Список изменений
| С версии 6.8.11 | Введена. |
Код _acf_track_synced_pattern() acf track synced pattern ACF 6.8.11
function _acf_track_synced_pattern( $args, $block_type ) {
if ( 'core/block' !== $block_type || empty( $args['render_callback'] ) || ! is_callable( $args['render_callback'] ) ) {
return $args;
}
$render_callback = $args['render_callback'];
$args['render_callback'] = function ( $attributes, $content = '', $block = null ) use ( $render_callback ) {
$previous_pattern = acf_get_data( 'acf_synced_pattern' );
acf_set_data( 'acf_synced_pattern', empty( $attributes['ref'] ) ? null : get_post( (int) $attributes['ref'] ) );
try {
return call_user_func( $render_callback, $attributes, $content, $block );
} finally {
acf_set_data( 'acf_synced_pattern', $previous_pattern );
}
};
return $args;
}