acf_handle_json_block_registration()
Handle an ACF block registered through block.json
Хуков нет.
Возвращает
Массив
. Block registration settings with ACF required additions.
Использование
acf_handle_json_block_registration( $settings, $metadata );
- $settings(массив) (обязательный)
- The compiled block settings.
- $metadata(массив) (обязательный)
- The raw json metadata.
Список изменений
С версии 6.0.0 | Введена. |
Код acf_handle_json_block_registration() acf handle json block registration ACF 6.0.4
function acf_handle_json_block_registration( $settings, $metadata ) { if ( ! acf_is_acf_block_json( $metadata ) ) { return $settings; } // Setup ACF defaults. $settings = wp_parse_args( $settings, array( 'render_template' => false, 'render_callback' => false, 'enqueue_style' => false, 'enqueue_script' => false, 'enqueue_assets' => false, 'post_types' => array(), 'uses_context' => array(), 'supports' => array(), 'attributes' => array(), 'acf_block_version' => 2, 'api_version' => 2, ) ); // Add user provided attributes to ACF's required defaults. $settings['attributes'] = wp_parse_args( acf_get_block_type_default_attributes( $metadata ), $settings['attributes'] ); // Add default ACF 'supports' settings. $settings['supports'] = wp_parse_args( $settings['supports'], array( 'align' => true, 'html' => false, 'mode' => true, 'jsx' => true, ) ); // Add default ACF 'uses_context' settings. $settings['uses_context'] = array_unique( array_merge( $settings['uses_context'], array( 'postId', 'postType', ) ) ); // Map custom ACF properties from the ACF key, with localization. $property_mappings = array( 'renderCallback' => 'render_callback', 'renderTemplate' => 'render_template', 'mode' => 'mode', 'blockVersion' => 'acf_block_version', 'postTypes' => 'post_types', ); $textdomain = ! empty( $metadata['textdomain'] ) ? $metadata['textdomain'] : 'acf'; $i18n_schema = get_block_metadata_i18n_schema(); foreach ( $property_mappings as $key => $mapped_key ) { if ( isset( $metadata['acf'][ $key ] ) ) { unset( $settings[ $key ] ); $settings[ $mapped_key ] = $metadata['acf'][ $key ]; if ( $textdomain && isset( $i18n_schema->$key ) ) { $settings[ $mapped_key ] = translate_settings_using_i18n_schema( $i18n_schema->$key, $settings[ $key ], $textdomain ); } } } // Add the block name and registration path to settings. $settings['name'] = $metadata['name']; $settings['path'] = dirname( $metadata['file'] ); acf_get_store( 'block-types' )->set( $metadata['name'], $settings ); add_action( 'enqueue_block_editor_assets', 'acf_enqueue_block_assets' ); // Ensure our render callback is used. $settings['render_callback'] = 'acf_render_block_callback'; return $settings; }