generate_block_asset_handle
函数
generate_block_asset_handle ( $block_name, $field_name, $index = 0 )
- 参数
-
-
(string)
$block_name
Name of the block.- Required: 是
-
(string)
$field_name
Name of the metadata field.- Required: 是
-
(int)
$index
Optional. Index of the asset when multiple items passed. Default 0.- Required: 否
-
(string)
- 返回值
-
- (string) Generated asset name for the block’s field.
- 定义位置
-
-
wp-includes/blocks.php
, line 46
-
wp-includes/blocks.php
- 引入
- 5.5.0
- 弃用
- –
Generates the name for an asset based on the name of the block
and the field name provided.
function generate_block_asset_handle( $block_name, $field_name, $index = 0 ) {
if ( 0 === strpos( $block_name, 'core/' ) ) {
$asset_handle = str_replace( 'core/', 'wp-block-', $block_name );
if ( 0 === strpos( $field_name, 'editor' ) ) {
$asset_handle .= '-editor';
}
if ( 0 === strpos( $field_name, 'view' ) ) {
$asset_handle .= '-view';
}
if ( $index > 0 ) {
$asset_handle .= '-' . ( $index + 1 );
}
return $asset_handle;
}
$field_mappings = array(
'editorScript' => 'editor-script',
'script' => 'script',
'viewScript' => 'view-script',
'editorStyle' => 'editor-style',
'style' => 'style',
);
$asset_handle = str_replace( '/', '-', $block_name ) .
'-' . $field_mappings[ $field_name ];
if ( $index > 0 ) {
$asset_handle .= '-' . ( $index + 1 );
}
return $asset_handle;
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。