generate_block_asset_handle()
最后更新于:2021-11-26 04:10:05
generate_block_asset_handle( string$block_name, string$field_name)Generates the name for an asset based on the name of the block and the field name provided.
参数
- $block_name
-
(string) (Required) Name of the block.
- $field_name
-
(string) (Required) Name of the metadata field.
响应
(string) Generated asset name for the block’s field.
源文件
文件: gc-includes/blocks.php
function generate_block_asset_handle( $block_name, $field_name ) {
if ( 0 === strpos( $block_name, 'core/' ) ) {
$asset_handle = str_replace( 'core/', 'gc-block-', $block_name );
if ( 0 === strpos( $field_name, 'editor' ) ) {
$asset_handle .= '-editor';
}
return $asset_handle;
}
$field_mappings = array(
'editorScript' => 'editor-script',
'script' => 'script',
'editorStyle' => 'editor-style',
'style' => 'style',
);
return str_replace( '/', '-', $block_name ) .
'-' . $field_mappings[ $field_name ];
}