acf_register_block_type()
Registers a block type.
Хуки из функции
Возвращает
(Массив|false)
.
Использование
acf_register_block_type( $block );
- $block(массив) (обязательный)
- The block settings.
Список изменений
С версии 5.8.0 | Введена. |
Код acf_register_block_type() acf register block type ACF 6.0.4
function acf_register_block_type( $block ) { // Validate block type settings. $block = acf_validate_block_type( $block ); /** * Filters the arguments for registering a block type. * * @since 5.8.9 * * @param array $block The array of arguments for registering a block type. */ $block = apply_filters( 'acf/register_block_type_args', $block ); // Require name. if ( ! $block['name'] ) { $message = __( 'Block type name is required.', 'acf' ); _doing_it_wrong( __FUNCTION__, $message, '5.8.0' ); //phpcs:ignore -- escape not required. return false; } // Bail early if already exists. if ( acf_has_block_type( $block['name'] ) ) { /* translators: The name of the block type */ $message = sprintf( __( 'Block type "%s" is already registered.', 'acf' ), $block['name'] ); _doing_it_wrong( __FUNCTION__, $message, '5.8.0' ); //phpcs:ignore -- escape not required. return false; } // Set ACF required attributes. $block['attributes'] = acf_get_block_type_default_attributes( $block ); if ( ! isset( $block['api_version'] ) ) { $block['api_version'] = 2; } if ( ! isset( $block['acf_block_version'] ) ) { $block['acf_block_version'] = 1; } // Add to storage. acf_get_store( 'block-types' )->set( $block['name'], $block ); // Overwrite callback for WordPress registration. $block['render_callback'] = 'acf_render_block_callback'; // Register block type in WP. if ( function_exists( 'register_block_type' ) ) { register_block_type( $block['name'], $block ); } // Register action. add_action( 'enqueue_block_editor_assets', 'acf_enqueue_block_assets' ); // Return block. return $block; }