使WordPress成为核心

变更集54155


忽略:
时间戳:
2022年9月14日上午10:50:26(22个月(之前)
作者:
吉奥罗牌手表
消息:

块:允许为所有支持的资产类型注册多个项目

后续行动#54337,[52069]。的一部分https://github.com/WordPress/gutenberg/issues/41236。有关更多详细信息,请参阅https://github.com/WordPress/gutenberg/issues/33542.

允许为每个块传递多个脚本编辑器脚本,脚本、和查看脚本中的字段块.json元数据文件。这与之前添加的更改保持一致风格编辑器样式领域。

此更改影响工作包块类型类和块类型的REST API端点。为了确保向后兼容,旧名称被软弃用,取而代之的是使用数组值并具有_把手后缀。

Props zieladam、dlh、timothyblynjacobs、aristah、bernhard-reiter。
修复#56408.

位置:
大旅行箱
文件夹:
10已编辑

图例:

未修改
补充
远离的
  • 主干/src/wp-includes/block-editor.php

    53419兰特 54155兰特  
    325325
    326326foreach($block_registry->get_all_registered()作为$block_type){
    327 if(!空($block_type->style)){
    328 $style_handles[]=$block_type->style;
    329         }
    330 
    331 if(!空($block_type->editor_style)){
    332 $style_handles[]=$block_type->editor_style;
    333         }
    334 
    335 if(!空($block_type->script)){
    336 $script_handles[]=$block_type->script;
    337         }
     327$style_handles=数组_合并(
     328$style_handles,
     329$block_type->style_handles,
     330$block_type->editor_style_handles
     331        );
     332
     333$script_handles=数组合并(
     334$script_handles,
     335$block_type->script_handles
     336        );
    338337    }
    339338
  • trunk/src/wp-includes/blocks.php

    r54138 54155兰特  
    3636 *
    3737*@自5.5.0起
     38*@自6.1.0以来添加了`$index`参数。
    3839 *
    3940*@param string$block_name块的名称。
    4041*@param string$field_name元数据字段的名称。
     42*@param int$index可选。传递多个项目时的资产索引。
     43*默认值为0。
    4144*@return string为块字段生成的资产名称。
    4245 */
    43 函数generate_block_asset_handle($block_name,$field_name) {
     46函数generate_block_asset_handle($block_name,$field_name,$index=0) {
    4447if(0===strpos($block_name,'core/')){
    4548$asset_handle=str_replace('core/','wp-block-',$block_name);
     
    4952if(0===strpos($field_name,'view')){
    5053$asset_handle.='资产句柄-视图';
     54        }
     55if($index>0){
     56$asset_handle.=“-”。($指数+1);
    5157        }
    5258返回$asset_handle;
     
    6066“样式”=>“样式”,
    6167    );
    62    返回str_replace('/','-',$block_name)。
     68   $asset_handle=str_replace('/','-',$block_name)。
    6369        '-' . $字段映射[$field_name];
     70if($index>0){
     71$asset_handle.=“-”。($指数+1);
     72    }
     73返回$asset_handle;
    6474}
    6575
     
    7181 *
    7282*@自5.5.0起
     83*@自6.1.0起添加了`$index`参数。
    7384 *
    7485*@param array$metadata块元数据。
    7586*@param string$field_name要从元数据中选择的字段名。
     87*@param int$index可选。传递多个项时要注册的脚本的索引。
     88*默认为0。
    7689*@return string|false直接提供或通过创建的脚本句柄
    7790*脚本的注册,或失败时为false。
    7891 */
    79 函数register_block_script_handle($metadata,$field_name) {
     92函数register_block_script_handle($metadata,$field_name,$index=0) {
    8093if(空($metadata[$field_name]){
    8194返回false;
    8295    }
     96
    8397$script_handle=$metadata[$field_name];
    84 $script_path=删除块路径前缀($metadata[$field_name]);
     98if(is_array($script_handle)){
     99if(空($scripthandle[$index]){
     100返回false;
     101        }
     102$script_handle=$script_handle[$index];
     103    }
     104
     105$script_path=remove_block_asset_path_prefix($script_handle);
    85106if($script_handle===$script_path){
    86107返回$script_handle;
    87108    }
    88109
    89 $script_handle=生成块资产句柄($metadata[“名称”],$field_name);
     110$script_handle=生成块资产句柄($metadata[“名称”],$field_name,$索引);
    90111$script_asset_path=wp_normalize_path(
    91112真实路径(
     
    146167 *
    147168*@自5.5.0起
     169*@自6.1.0起添加了`$index`参数。
    148170 *
    149171*@param array$metadata块元数据。
    150172*@param string$field_name要从元数据中选择的字段名。
     173*@param int$index可选。传递多个项时要注册的样式的索引。
     174*默认值为0。
    151175*@return string|false直接提供或通过创建的Style句柄
    152176*样式的注册,或失败时为false。
    153177 */
    154 函数register_block_style_handle($metadata,$field_name) {
     178函数register_block_style_handle($metadata,$field_name,$index=0) {
    155179if(空($metadata[$field_name]){
    156180返回false;
    157181    }
     182
    158183$wpinc_path_norm=wp_normalize_path(真实路径(ABSPATH.wpinc));
    159184$theme_path_norm=wp_normalize_path(get_theme_file_path());
    160185$is_core_block=isset($metadata['file'])&&0==strpos($metata['file'],$wpinc_path_norm);
     186//提供捆绑版本时,跳过为每个核心块注册单个样式。
    161187如果($is_core_block&&!wp_sshould_load_separate_core_block_assets()){
    162188返回false;
    163189    }
    164190
     191$style_handle=$metadata[$field_name];
     192if(is_array($stylehandle)){
     193if(空($stylehandle[$index]){
     194返回false;
     195        }
     196$style_handle=$style_handle[$index];
     197    }
     198
     199$style_path=删除块路径前缀($style_handle);
     200$is_style_handle=$style_handle===$style_path;
     201//只允许传递核心块的样式句柄。
     202if($is_core_block&&!$is_style_handle){
     203返回false;
     204    }
     205//返回样式句柄,除非它是每个需要特殊处理的核心块的第一项。
     206if($is_style_handle&&!($is_core_block&&0==$index)){
     207return$style_handle;
     208    }
     209
    165210//检查样式是否应有“.min”后缀。
    166 $后缀=SCRIPT_DEBUG?“:”。最小值';
    167 
    168 $style_handle=$metadata[$field_name];
    169 $style_path=删除块路径前缀($metadata[$field_name]);
    170 
    171 if($style_handle===$style_path&&!$is_core_block){
    172 return$style_handle;
    173     }
    174 
     211$后缀=SCRIPT_DEBUG?“:”。最小值';
    175212$style_uri=插件url($style_path,$metadata['file']);
    176213if($is_core_block){
     
    186223    }
    187224
    188 $style_handle=生成块资产句柄($metadata[“名称”],$field_name);
     225$style_handle=生成块资产句柄($metadata[“名称”],$field_name,$索引);
    189226$block_dir=目录名($metadata['file']);
    190 $style_file=realpath(“$block_dir/$style_path”);
     227$style_file=wp_normalize_path(realpath(“$block_dir/$style_path”));
    191228$has_style_file=false!==$样式文件;
    192229$版本=$is_core_block&&isset($metadata['version'])$元数据[“版本”]:false;
     
    312349    }
    313350
    314 if(!空($metadata['editorScript']){
    315 $settings['editor_script']=寄存器块脚本句柄(
    316 $元数据,
    317 '编辑器脚本'
    318         );
    319     }
    320 
    321 if(!空($metadata['script']){
    322 $settings['script']=寄存器块脚本句柄(
    323 $元数据,
    324 '脚本'
    325         );
    326     }
    327 
    328 if(!空($metadata['viewScript'])){
    329 $settings['view_script']=寄存器块脚本句柄(
    330 $元数据,
    331 '查看脚本'
    332         );
    333     }
    334 
    335 if(!empty($metadata['editorStyle']){
    336 $settings['editor_style']=寄存器块样式句柄(
    337 $元数据,
    338 '编辑器样式'
    339         );
    340     }
    341 
    342 if(!空($metadata['style']){
    343 $settings['style']=寄存器块样式句柄(
    344 $元数据,
    345 “样式”
    346         );
     351$script_fields=数组(
     352“editorScript”=>“editor_script_handles”,
     353“script”=>“script_handles”,
     354“viewScript”=>“view_script_handles”,
     355    );
     356foreach($script_fields作为$metadata_field_name=>$settings_field-name){
     357if(!空($metadata[$metadata_field_name]){
     358$scripts=$metadata[$metadata_field_name];
     359$processed_scripts=数组();
     360if(is_array($scripts)){
     361for($index=0;$index<count($scripts)$索引++){
     362$result=寄存器块脚本句柄(
     363$元数据,
     364$元数据字段名,
     365$索引
     366                    );
     367if($result){
     368$processed_scripts[]=$result;
     369                    }
     370                }
     371}其他{
     372$result=寄存器块脚本句柄(
     373$元数据,
     374$元数据字段名
     375                );
     376if($result){
     377$processed_scripts[]=$result;
     378                }
     379            }
     380$settings[$settings_field_name]=$processed_scripts;
     381        }
     382    }
     383
     384$style_fields=数组(
     385“editorStyle”=>“editor_style_handles”,
     386“style”=>“style_handles”,
     387    );
     388foreach($style_fields作为$metadata_field_name=>$settings_field-name){
     389if(!空($metadata[$metadata_field_name]){
     390$styles=$metadata[$metadata_field_name];
     391$processed_styles=数组();
     392if(is_array($styles)){
     393for($index=0;$index<count($styles)$索引++){
     394$result=寄存器块样式句柄(
     395$元数据,
     396$元数据字段名,
     397$索引
     398                    );
     399if($result){
     400$processed_styles[]=$result;
     401                    }
     402                }
     403}其他{
     404$result=寄存器块样式句柄(
     405$元数据,
     406$元数据字段名
     407                );
     408if($result){
     409$processed_styles[]=$result;
     410                }
     411            }
     412$settings[$settings_field_name]=$processed_styles;
     413        }
    347414    }
    348415
     
    12631330
    12641331/**
    1265 *允许多种块样式。
    1266  *
    1267 *@自5.9.0起
    1268  *
    1269 *@param array$metadata用于注册块类型的元数据。
    1270 *@return array用于注册块类型的元数据。
    1271  */
    1272 函数_wp_multiple_block_styles($metadata){
    1273 foreach(数组(“style”,“editorStyle”)作为$key){
    1274 if(!空($metadata[$key])&&isarray($metdata[$key]){
    1275 $default_style=array_shift($metadata[$key]);
    1276 foreach($metadata[$key]作为$handle){
    1277 $args=数组('handle'=>$handle);
    1278 if(0===strpos($handle,'file:')&&isset($metadata['file'])){
    1279 $style_path=删除块资产路径前缀($handle);
    1280 $theme_path_norm=wp_normalize_path(get_theme_file_path());
    1281 $style_path_norm=wp_normalize_path(realpath(目录名($metadata['file']).'/')$样式路径);
    1282 $is_theme_block=isset($metadata['file'])&&0===strpos($metata['file'],$theme_path_norm);
    1283 
    1284 $style_uri=插件url($style_path,$metadata['file']);
    1285 
    1286 if($is_theme_block){
    1287 $style_uri=获取_theme_file_uri(str_replace($theme_path_norm,'',$style_path_norm));
    1288                     }
    1289 
    1290 $args=阵列(
    1291 “handle”=>sanitize_key(“{$metadata['name']}-{$style_path}”),
    1292 “src”=>$style_uri,
    1293                     );
    1294                 }
    1295 
    1296 wp_enqueue_block_style($metadata['name'],$args);
    1297             }
    1298 
    1299 //只返回数组中的第一项。
    1300 $metadata[$key]=$default_style;
    1301         }
    1302     }
    1303 返回$metadata;
    1304 }
    1305 add_filter('block_type_metadata','_wp_multiple_block_styles');
    1306 
    1307 /**
    13081332*Helper函数,从传递的
    13091333*块属性。
  • trunk/src/wp-includes/class-wp-block-type.php

    r54133 54155兰特  
    167167
    168168    /**
    169 *块类型编辑器专用脚本句柄。
    170      *
    171 *@自5.0.0起
    172 *@var字符串|空
    173      */
    174 public$editor_script=null;
    175 
    176     /**
    177 *块类型前端和编辑器脚本句柄。
    178      *
    179 *@自5.0.0起
    180 *@var字符串|空
    181      */
    182 public$script=null;
    183 
    184     /**
    185 *块类型仅前端脚本句柄。
    186      *
    187 *@自5.9.0起
    188 *@var字符串|空
    189      */
    190 public$view_script=空;
    191 
    192     /**
    193 *块类型编辑器专用样式句柄。
    194      *
    195 *@自5.0.0起
    196 *@var字符串|空
    197      */
    198 public$editor_style=null;
    199 
    200     /**
    201 *块式前端和编辑器式手柄。
    202      *
    203 *@自5.0.0起
    204 *@var字符串|空
    205      */
    206 public$style=null;
     169*仅限块类型编辑器的脚本句柄。
     170     *
     171*@自6.1.0起
     172*@var字符串[]
     173     */
     174public$editor_script_handles=array();
     175
     176    /**
     177*块类型前端和编辑器脚本句柄。
     178     *
     179*@自6.1.0起
     180*@var字符串[]
     181     */
     182public$script_handles=array();
     183
     184    /**
     185*块类型仅前端脚本句柄。
     186     *
     187*@自6.1.0起
     188*@var字符串[]
     189     */
     190public$view_script_handles=array();
     191
     192    /**
     193*仅限块类型编辑器样式句柄。
     194     *
     195*@自6.1.0起
     196*@var字符串[]
     197     */
     198public$editor_style_handles=array();
     199
     200    /**
     201*块类型前端和编辑器样式手柄。
     202     *
     203*@自6.1.0起
     204*@var字符串[]
     205     */
     206public$style_handles=array();
     207
     208    /**
     209*脚本和样式句柄的块类型属性已弃用。
     210     *
     211*@自6.1.0起
     212*@var字符串[]
     213     */
     214private$deprecated_properties=数组(
     215'编辑脚本',
     216“脚本”,
     217'视图脚本',
     218'编辑器样式',
     219“样式”,
     220    );
    207221
    208222    /**
     
    229243*@自5.9.0起添加了“view_script”属性。
    230244*@since 6.0.0添加了“祖先”属性。
     245*@自6.1.0起添加了`editor_script_handles`、`script_handles、`view_script_handles、,
     246*`editor_style_handles`和`style_handles属性。
     247*不推荐使用`editor_script`、`script`、`view_script`和`style`属性。
    231248     *
    232249*@请参阅register_block_type()
     
    237254*但是,默认情况下支持以下描述的选项。默认空数组。
    238255     *
    239 *@type字符串$api_version块API版本。
    240 *@type字符串$title人可读块类型标签。
    241 *@type string |空$category块类型类别分类,用于
    242      *                                           搜索界面以按类别排列块类型。
    243 *@type字符串[]| null$parent设置父级允许块只需要
    244      *                                           嵌套在指定块中时可用。
    245 *@type string[]| null$祖先设置祖先使块仅在指定的
    246      *                                           位于祖先的块子树的任何位置的块类型。
    247 *@type string|null$图标块类型图标。
    248 *@type字符串$description详细的块类型描述。
    249 *@type字符串[]$关键字生成块类型的其他关键字
    250      *                                           搜索界面的结果。
    251 *@type string |空$textdomain翻译文本域。
    252 *@type数组[]$styles替代块样式。
    253 *@type数组[]$变体块变化。
    254 *@type array | null$支持支持的功能。
    255 *@type数组|null$示例块预览的结构化数据。
    256 *@type可调用|null$render_callback块类型渲染回调。
    257 *@type数组|null$属性块类型属性特性模式。
    258 *@type字符串[]$uses_context此类型的块继承的上下文值。
    259 *@type string[]|空$provides_context此类型的块提供的上下文。
    260 *@type字符串|空$editor_script块类型编辑器专用脚本句柄.
    261 *@type字符串|null$script块类型前端和编辑器脚本句柄.
    262 *@type字符串|空$view_script块类型仅前端脚本句柄.
    263 *@type字符串|null$editor_style块类型编辑器仅样式句柄.
    264 *@type字符串|null$style块类型前端和编辑器样式句柄.
     256*@类型字符串$api_version       块API版本。
     257*@type字符串$title       人可读块类型标签。
     258*@type字符串|null$category       块类型类别分类,用于
     259     *                                                  搜索界面以按类别排列块类型。
     260*@type字符串[]| null$parent       设置父级允许块只需要
     261     *                                                  嵌套在指定块中时可用。
     262*@type string[]| null$祖先       设置祖先使块仅在指定的
     263     *                                                  在祖先块子树的任何位置的块类型。
     264*@type string|null$图标       块类型图标。
     265*@type字符串$description       详细的块类型描述。
     266*@type字符串[]$关键字       生成块类型的其他关键字
     267     *                                                  搜索界面的结果。
     268*@type string |空$textdomain       翻译文本域。
     269*@type数组[]$styles       替代块样式。
     270*@type数组[]$变体       块变化。
     271*@type array | null$支持       支持的功能。
     272*@type数组|null$示例       块预览的结构化数据。
     273*@type可调用|null$render_callback       块类型渲染回调。
     274*@type数组|null$属性       块类型属性特性模式。
     275*@type字符串[]$uses_context       此类型的块继承的上下文值。
     276*@type string[]|空$provides_context       此类型的块提供的上下文。
     277*@类型字符串[]$editor_script_handles块类型编辑器专用脚本句柄.
     278*@type字符串[]$script_handles块类型前端和编辑器脚本句柄.
     279*@type字符串[]$view_script_handles块类型仅前端脚本句柄.
     280*@type字符串[]$editor_style_handles块类型编辑器专用样式句柄.
     281*@type字符串[]$style_handles块类型前端和编辑器样式句柄.
    265282     * }
    266283     */
     
    269286
    270287$this->set_props($args);
     288    }
     289
     290    /**
     291*代理为脚本和样式句柄获取不推荐使用的属性的值,以实现向后兼容性。
     292*如果提供数组中的第一项,则获取相应新属性的值。
     293     *
     294*@自6.1.0起
     295     *
     296*@param string$name不推荐属性名。
     297     *
     298*@return string | null | void如果提供数组中的第一项,则从新属性中读取的值,
     299*未找到值时为null,提供未知属性名称时为void。
     300     */
     301公共函数__get($name){
     302if(!in_array($name,$this->deprecated_properties)){
     303回报;
     304        }
     305
     306$new_name=$name。”_手柄';
     307返回isset($this->{$new_name}[0])$this->{$new_name}[0]:空;
     308    }
     309
     310    /**
     311*代理检查脚本和样式句柄的弃用属性,以实现向后兼容性。
     312*检查相应的新属性是否具有提供的数组中的第一项。
     313     *
     314*@自6.1.0起
     315     *
     316*@param string$name不推荐属性名。
     317     *
     318*@return boolean对于新属性,当数组中存在第一个项时返回true,
     319*或其他错误。
     320     */
     321公共函数__isset($name){
     322if(!in_array($name,$this->deprecated_properties)){
     323返回false;
     324        }
     325
     326$new_name=$name。”_手柄';
     327返回isset($this->{$new_name}[0]);
     328    }
     329
     330    /**
     331*代理设置脚本和样式句柄的弃用属性的值,以实现向后兼容性。
     332*将相应新属性的值设置为数组中的第一项。
     333*它还允许设置自定义属性以实现向后兼容性。
     334     *
     335*@自6.1.0起
     336     *
     337*@param string$name属性名。
     338*@param混合了$value属性值。
     339     */
     340公共函数__set($name,$value){
     341if(!in_array($name,$this->deprecated_properties)){
     342$this->{$name}=$value;
     343回报;
     344        }
     345
     346if(!is_string($value)){
     347回报;
     348        }
     349
     350$new_name=$name。”_手柄';
     351$this->{$new_name}[0]=$value;
    271352    }
    272353
  • 主干/src/wp-includes/class-wp-block.php

    r54133 54155兰特  
    261261        }
    262262
    263 if(!空($this->block_type->script)){
    264 wp_enque_script($this->block_type->script);
    265         }
    266 
    267 if(!empty($this->block_type->view_script)&&empty{
    268 wp_enqueue_script($this->block_type->view_script);
    269         }
    270 
    271 if(!空($this->block_type->style)){
    272 wp_enque_style($this->block_type->style);
     263if((!empty($this->block_type->script_handles)){
     264foreach($this->block_type->script_handles作为$script_hannel){
     265wp_enqueue_script($script_handle);
     266            }
     267        }
     268
     269if(!空($this->block_type->view_script_handles)&&empty($this->block-type->render_callback)){
     270foreach($this->block_type->view_script_handles作为$view_script_chandle){
     271wp_enqueue_script($view_script_handle);
     272            }
     273        }
     274
     275if((!empty($this->block_type->stylehandles)){
     276foreach($this->block_type->style_handles作为$style_hannel){
     277wp_enqueue_style($style_handle);
     278            }
    273279        }
    274280
  • trunk/src/wp-includes/deprecated.php

    53874兰特 54155兰特  
    44434443返回false;
    44444444}
     4445
     4446/**
     4447*允许多种块样式。
     4448  *
     4449*@自5.9.0起
     4450*@不推荐使用的6.1.0
     4451  *
     4452*@param array$metadata用于注册块类型的元数据。
     4453*@return array用于注册块类型的元数据。
     4454  */
     4455函数_wp_multiple_block_styles($metadata){
     4456_deprecated_function(__function__,‘6.1.0’);
     4457返回$metadata;
     4458}
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php

    53760兰特 54155兰特  
    257257        }
    258258
    259 $schema=$this->get_item_schema();
    260 $extra_fields=数组(
    261 “api版本”,
    262 “名称”,
    263 '标题',
    264 '描述',
    265 “图标”,
    266 “类别”,
    267 '关键词',
    268 “父级”,
    269 “祖先”,
    270 '提供上下文',
    271 “uses_context”,
    272 “支架”,
    273 “样式”,
    274 '文本域',
    275 “示例”,
     259$schema=$this->get_item_schema();
     260//WordPress 6.1中不推荐使用字段,但为了向后兼容,保留在模式中。
     261$deprecated_fields=数组(
    276262'编辑脚本',
    277263“脚本”,
     
    279265'编辑器样式',
    280266“样式”,
    281 “变化”,
     267        );
     268$extra_fields=阵列合并(
     269阵列(
     270“api版本”,
     271“名称”,
     272'标题',
     273'描述',
     274“图标”,
     275“类别”,
     276'关键词',
     277“父级”,
     278“祖先”,
     279'提供上下文',
     280“uses_context”,
     281“支架”,
     282“样式”,
     283'文本域',
     284“示例”,
     285'编辑器脚本句柄',
     286'脚本句柄',
     287'视图脚本句柄',
     288'编辑器样式句柄',
     289“style_handles”,
     290“变化”,
     291            ),
     292$deprecated_fields(已弃用字段)
    282293        );
    283294foreach($extra_fields作为$extra_field){
     
    438449        );
    439450
    440         $模式=数组(
     451        $此->模式=数组(
    441452“$schema”=>“http://json-schema.org/draft-04/schema#',
    442453'title'=>'block-type',
    443454“type”=>“object”,
    444455“属性”=>数组(
    445 'api版本'=>数组(
     456'api版本'     =>数组(
    446457'描述'=>__('区块API版本'),
    447458“type”=>“integer”,
     
    450461“只读”=>true,
    451462                ),
    452 '标题'=>数组(
     463'标题'     =>数组(
    453464“description”=>__(“块类型标题”),
    454465“type”=>“string”,
     
    457468“只读”=>true,
    458469                ),
    459 “名称”=>数组(
     470“名称”     =>数组(
    460471“description”=>__(“标识块类型的唯一名称”),
    461472'类型'=>'字符串',
     
    464475“只读”=>true,
    465476                ),
    466 '说明'=>数组(
     477'说明'     =>数组(
    467478'描述'=>__('块类型描述'),
    468479“type”=>“string”,
     
    471482“只读”=>true,
    472483                ),
    473 “图标”=>$icon_definition,
    474 '属性'=>数组(
     484“图标”     =>$icon_definition,
     485'属性'     =>数组(
    475486“description”=>__(“块属性”),
    476487“type”=>数组(“object”,“null”),
     
    483494“只读”=>true,
    484495                ),
    485 '提供上下文'=>数组(
     496'提供上下文'     =>数组(
    486497“description”=>__(“此类型的块提供的上下文。”),
    487498“type”=>“object”,
     
    494505“只读”=>true,
    495506                ),
    496 '使用上下文'=>数组(
     507'使用上下文'     =>数组(
    497508“description”=>__(“此类型的块继承的上下文值。”),
    498509“type”=>“array”,
     
    504515“只读”=>true,
    505516                ),
    506 “支持”=>数组(
     517“支持”     =>数组(
    507518“description”=>__(“块支持”),
    508519“type”=>“object”,
     
    512523“只读”=>true,
    513524                ),
    514 '类别'=>$category_definition,
    515 “is_dynamic”=>数组(
     525'类别'     =>$category_definition,
     526“is_dynamic”     =>数组(
    516527“description”=>__(“块是动态渲染的。”),
    517528“type”=>“boolean”,
     
    520531“只读”=>true,
    521532                ),
    522 'editor_script'=>数组(
    523 '描述'=>__('编辑器脚本句柄'),
    524 “type”=>数组(“string”,“null”),
    525 “默认”=>null,
    526 'context'=>数组('embed','view','edit'),
    527 “只读”=>true,
    528                 ),
    529 “script”=>数组(
    530 “description”=>__(“面向公众的编辑器脚本句柄”),
    531 “type”=>数组(“string”,“null”),
    532 “默认”=>null,
    533 “context”=>数组(“embed”、“view”、“edit”),
    534 “只读”=>true,
    535                 ),
    536 “view_script”=>数组(
    537 '描述'=>__('面向公众的脚本句柄'),
    538 “type”=>数组(“string”,“null”),
    539 '默认'=>空,
    540 “context”=>数组(“embed”、“view”、“edit”),
    541 “只读”=>true,
    542                 ),
    543 “editor_style”=>数组(
    544 “description”=>__(“编辑器样式句柄”),
    545 “type”=>数组(“string”,“null”),
    546 “默认”=>null,
    547 “context”=>数组(“embed”、“view”、“edit”),
    548 “只读”=>true,
    549                 ),
    550 “style”=>数组(
    551 “description”=>__(“面向公众的编辑器样式句柄”),
    552 “type”=>数组(“string”,“null”),
    553 “默认”=>null,
    554 “context”=>数组(“embed”、“view”、“edit”),
    555 “只读”=>true,
    556                 ),
    557 “styles”=>数组(
     533“editor_script_handles”=>数组(
     534“description”=>__(“编辑器脚本句柄”),
     535“type”=>数组(“array”),
     536“default”=>数组(),
     537“items”=>数组(
     538“type”=>“string”,
     539                    ),
     540“context”=>数组(“embed”、“view”、“edit”),
     541“只读”=>true,
     542                ),
     543“script_handles”=>数组(
     544“description”=>__(“面向公众的和编辑器脚本句柄。”),
     545“type”=>数组(“array”),
     546“default”=>数组(),
     547“items”=>数组(
     548“type”=>“string”,
     549                    ),
     550“context”=>数组(“embed”、“view”、“edit”),
     551“只读”=>true,
     552                ),
     553“view_script_handles”=>数组(
     554“description”=>__(“面向公众的脚本句柄”),
     555“type”=>数组(“array”),
     556“default”=>数组(),
     557“items”=>数组(
     558“type”=>“string”,
     559                    ),
     560“context”=>数组(“embed”、“view”、“edit”),
     561“只读”=>true,
     562                ),
     563“editor_style_handles”=>数组(
     564“description”=>__(“编辑器样式句柄”),
     565“type”=>数组(“array”),
     566“default”=>数组(),
     567“items”=>数组(
     568“type”=>“string”,
     569                    ),
     570“context”=>数组(“embed”、“view”、“edit”),
     571“只读”=>true,
     572                ),
     573'style_handles'=>数组(
     574“description”=>__(“公共外观和编辑器样式句柄。”),
     575“type”=>数组(“array”),
     576“default”=>数组(),
     577'items'=>数组(
     578“type”=>“string”,
     579                    ),
     580“context”=>数组(“embed”、“view”、“edit”),
     581“只读”=>true,
     582                ),
     583“styles”=>数组(
    558584“description”=>__(“块样式变化”),
    559585“type”=>“array”,
     
    584610“只读”=>true,
    585611                ),
    586 “变体”=>数组(
     612“变体”     =>数组(
    587613“description”=>__(“块变量”),
    588614“type”=>“array”,
     
    636662“默认”=>null,
    637663                ),
    638 '文本域'=>数组(
     664'文本域'     =>数组(
    639665'描述'=>__('公共文本域'),
    640666“type”=>数组(“string”,“null”),
     
    643669“只读”=>true,
    644670                ),
    645 “父级”=>数组(
     671“父级”     =>数组(
    646672“description”=>__(“父块”),
    647673“type”=>数组(“array”,“null”),
     
    653679“只读”=>true,
    654680                ),
    655 '祖先'=>数组(
     681'祖先'     =>阵列(
    656682“description”=>__(“祖先块”),
    657683“type”=>数组(“array”,“null”),
     
    668694        );
    669695
    670 $this->schema=$schema;
     696//WordPress 6.1中不推荐使用属性,但为了向后兼容,保留在模式中。
     697$deprecated_properties=数组(
     698“editor_script”=>数组(
     699“description”=>__(“编辑器脚本句柄。弃用:改用”“Editor_script_handles”“),
     700“type”=>数组(“string”,“null”),
     701“默认”=>null,
     702“context”=>数组(“embed”、“view”、“edit”),
     703“只读”=>true,
     704            ),
     705“script”=>数组(
     706'description'=>__('面向公众的编辑器脚本句柄。弃用:改用'script_handles'。'),
     707“type”=>数组(“string”,“null”),
     708“默认”=>null,
     709“context”=>数组(“embed”、“view”、“edit”),
     710“只读”=>true,
     711            ),
     712“view_script”=>数组(
     713“description”=>__(“面向公共的脚本句柄。弃用:改用“view_script_handles”),
     714“type”=>数组(“string”,“null”),
     715“默认”=>null,
     716“context”=>数组(“embed”、“view”、“edit”),
     717“只读”=>true,
     718            ),
     719“editor_style”=>数组(
     720“description”=>__(“编辑器样式句柄。弃用:改用”“Editor_style_handles”“。”),
     721“type”=>数组(“string”,“null”),
     722“默认”=>null,
     723“context”=>数组(“embed”、“view”、“edit”),
     724“只读”=>true,
     725            ),
     726“style”=>数组(
     727'description'=>__('面向公众的编辑器样式句柄。弃用:改用'style_handles'。'),
     728“type”=>数组(“string”,“null”),
     729'默认'=>空,
     730“context”=>数组(“embed”、“view”、“edit”),
     731“只读”=>true,
     732            ),
     733        );
     734$this->schema['properties']=array_merge($this->schema['属性'],$deprecated_properties);
    671735
    672736返回$this->add_additional_fields_schema($this->模式);
  • trunk/src/wp-includes/script-loader.php

    54118兰特 54155卢比  
    25322532    }
    25332533
    2534 $加载编辑器脚本=is_admin()&&wp_should_load_block_editor_scripts_and_styles();
     2534$加载编辑器脚本_和_样式=is_admin()&&wp_should_load_block_editor_scripts_and_styles();
    25352535
    25362536$block_registry=WP_block_Type_registry::get_instance();
    25372537foreach($block_registry->get_all_registered()作为$block_name=>$block_type){
    2538 //前端样式。
    2539 if(!空($block_type->style)){
    2540 wp_enqueue_style($block_type->style);
    2541         }
    2542 
    2543 //前端脚本。
    2544 if(!空($block_type->script)){
    2545 wp_enqueue_script($block_type->script);
    2546         }
    2547 
    2548 //编辑器样式。
    2549 if($load_editor_scripts&&!空($block_type->editor_style)){
    2550 wp_enqueue_style($block_type->editor_style);
    2551         }
    2552 
    2553 //编辑器脚本。
    2554 if($load_editor_scripts&&!空($block_type->editor_sscript)){
    2555 wp_enqueue_script($block_type->editor_script);
     2538//Front-end和编辑器样式。
     2539foreach($block_type->style_handles作为$style_hannel){
     2540wp_enqueue_style($style_handle);
     2541        }
     2542
     2543//Front-end和编辑器脚本。
     2544foreach($block_type->script_handles作为$script_handle){
     2545wp_enqueue_script($script_handle);
     2546        }
     2547
     2548if($load_editor_scripts_and_styles){
     2549//编辑器样式。
     2550foreach($block_type->editor_style_handles作为$editor_syle_handle){
     2551wp_enqueue_style($editor_style_handle);
     2552            }
     2553
     2554//编辑器脚本。
     2555foreach($block_type->editor_script_handles作为$editor_sscript_handle){
     2556wp_enqueue_script($editor_script_handle);
     2557            }
    25562558        }
    25572559    }
  • trunk/tests/phpunit/data/blocks/notice/block.json

    r54132 54155兰特  
    5858“editorScript”:“测试通知编辑器脚本”,
    5959“script”:“tests-notice-script”,
    60 “viewScript”:“tests-notice-view-script”,
     60“视图脚本”:[“tests-notice-view-script”,“tests-notice-view-script-2”],
    6161“editorStyle”:“tests-notice-editor-style”,
    62 “风格”:“测试-通知-样式”,
     62“风格”:[“tests-notice-style”,“tests-notice-sstyle-2”],
    6363“render”:“file:./render.php”
    6464}
  • trunk/tests/phpunit/tests/blocks/register.php

    r54132 54155兰特  
    149149$this->资产相同(
    150150'单元测试-my-block-script',
    151 generate_block_asset_handle($block_name,'脚本')
    152         );
    153 $this->资产相同(
    154 '单元测试-my-block-view-script',
    155 generate_block_asset_handle($block_name,'viewScript')
    156         );
    157 $this->资产相同(
    158 '单元测试-my-block-editor样式',
    159 generate_block_asset_handle($block_name,'editorStyle')
     151generate_block_asset_handle($block_name,'脚本', 0)
     152        );
     153$this->资产相同(
     154'单元测试-my-block-view-script-100',
     155generate_block_asset_handle($block_name,'viewScript', 99)
     156        );
     157$this->资产相同(
     158'单元测试-my-block-editor样式-2',
     159generate_block_asset_handle($block_name,'editorStyle', 1)
    160160        );
    161161$this->资产相同(
     
    177177$this->资产相同(
    178178“wp-block-pargraph”,
    179 generate_block_asset_handle($block_name,'脚本')
    180         );
    181 $this->资产相同(
    182 'wp-block-pargraph-view(wp-block图形视图)',
    183 generate_block_asset_handle($block_name,'viewScript')
    184         );
    185 $this->资产相同(
    186 'wp-block-pargraph-editor(wp-block图形编辑器)',
    187 generate_block_asset_handle($block_name,'editorStyle')
     179generate_block_asset_handle($block_name,'脚本', 0)
     180        );
     181$this->资产相同(
     182'wp-block-pargraph-view(wp-block图形视图)-100',
     183generate_block_asset_handle($block_name,'viewScript', 99)
     184        );
     185$this->资产相同(
     186'wp-block-pargraph-editor(wp-block图形编辑器)-2',
     187generate_block_asset_handle($block_name,'editorStyle', 1)
    188188        );
    189189$this->资产相同(
     
    205205*@票号50263
    206206     */
    207 公共功能测试_空_价值_寄存器块脚本句柄(){
     207公共功能测试_空_字符串_值_否_寄存器块脚本句柄(){
    208208$metadata=数组(“脚本”=>“”);
    209209$result=register_block_script_handle($metadata,'script');
     210
     211$this->assertFalse($result);
     212    }
     213
     214公共函数test_empty_array_value_do_not_register_block_script_handle(){
     215$metadata=数组('script'=>array());
     216$result=register_block_script_handle($metadata,'script');
     217
     218$this->assertFalse($result);
     219    }
     220
     221公共函数test_wrong_array_index_do_not_register_block_script_handle(){
     222$metadata=数组(“script”=>数组(“test-script-handle”));
     223$result=register_block_script_handle($metadata,'script',1);
    210224
    211225$this->assertFalse($result);
     
    232246公共函数test_handle_passed_register_block_script_handle(){
    233247$metadata=数组(
    234             '编辑Sscript'=>'测试脚本handle',
    235         );
    236 $result=寄存器块脚本句柄($metadata,'编辑S脚本');
     248            'script'=>'测试脚本handle',
     249        );
     250$result=寄存器块脚本句柄($metadata,'脚本');
    237251
    238252$this->assertSame(“test-script-handle”,$result);
     253    }
     254
     255公共函数test_handles_passed_register_block_script_handles(){
     256$metadata=数组(
     257“script”=>数组(“test-script-handle”,“test-script-handle-2”),
     258        );
     259
     260$result=register_block_script_handle($metadata,'script');
     261$this->assertSame(“test-script-handle”,$result);
     262
     263$result=register_block_script_handle($metadata,'script',1);
     264$this->assertSame(“test-script-handle-2”,$result,1);
    239265    }
    240266
     
    282308*@票号50263
    283309     */
    284 公共功能测试_空_找到的值_寄存器块样式句柄(){
     310公共功能测试_空_字符串_值_否_寄存器块样式句柄(){
    285311$metadata=数组(“style”=>“”);
    286312$result=register_block_style_handle($metadata,'style');
     
    289315    }
    290316
     317公共函数test_empty_array_value_do_not_register_block_style_handle(){
     318$metadata=数组(“style”=>数组());
     319$result=register_block_style_handle($metadata,'style');
     320
     321$this->assertFalse($result);
     322    }
     323
     324公共函数test_wrong_array_index_do_not_register_block_style_handle(){
     325$metadata=数组(“style”=>数组(“test style handle”));
     326$result=register_block_style_handle($metadata,'style',1);
     327
     328$this->assertFalse($result);
     329    }
     330
    291331    /**
    292332*@车票50263
     
    299339
    300340$this->assertSame(“test-style-handle”,$result);
     341    }
     342
     343公共函数test_handles_passed_register_block_style_handles(){
     344$metadata=数组(
     345“style”=>数组(“test-style-handle”,“test-tyle-handle-2”),
     346        );
     347
     348$result=register_block_style_handle($metadata,'style');
     349$this->assertSame(“test-style-handle”,$result);
     350
     351$result=register_block_style_handle($metadata,'style',1);
     352$this->assertSame('test-style-handle-2',$result,1);
    301353    }
    302354
     
    443495$result->示例
    444496        );
    445 $this->assertSame('tests-notice-editor-script',$result->editor_script);
    446 $this->assertSame(“tests-notice-script”,$result->script);
    447 $this->assertSame('tests-notice-view-script',$result->view_script);
    448 $this->assertSame('测试通知编辑器样式',$result->editor_style);
    449 $this->assertSame('tests-notice-style',$result->style);
     497$this->资产SameSet(
     498数组(“tests-notice-editor-script”),
     499$result->editor_script_handles
     500        );
     501$this->资产SameSet(
     502数组(“tests-notice-script”),
     503$result->script_handles
     504        );
     505$this->资产SameSet(
     506数组(“tests-notice-view-script”,“tests-notice-view-script-2”),
     507$result->view_script_handles
     508        );
     509$this->资产SameSet(
     510数组(“tests-notice-editor-style”),
     511$result->editor_style_handles
     512        );
     513$this->资产SameSet(
     514数组(“tests-notice-style”,“tests-notice-sstyle-2”),
     515$result->style_handles
     516        );
    450517
    451518//@门票50328
  • trunk/tests/phpunit/tests/rest-api/rest-block-type-controller.php

    54058兰特 54155兰特  
    238238$this->assertSame('1',$data['description']);
    239239$this->assertNull($data['icon']);
    240 $this->断言空($data['editor_script'] );
    241 $this->断言空($data['script'] );
    242 $this->断言空($data['view_script'] );
    243 $this->断言空($data['editor_style'] );
    244 $this->断言空($data['style'] );
     240$this->断言SameSet(数组(),$data['editor_script_handles'] );
     241$this->断言SameSet(数组(),$data['script_handles'] );
     242$this->断言SameSet(数组(),$data['view_script_handles'] );
     243$this->断言SameSet(数组(),$data['editor_style_handles'] );
     244$this->断言SameSet(数组(),$data['style_handles'] );
    245245$this->assertSameSet(数组(),$data['provides_context']);
    246246$this->资产SameSetsWithIndex(
     
    261261$this->assertFalse($data['is_dynamic']);
    262262$this->assertSameSet(数组(array()),$data['variations']);
     263//不推荐的属性。
     264$this->assertNull($data['editor_script']);
     265$this->assertNull($data['script']);
     266$this->assertNull($data['view_script']);
     267$this->assertNull($data['editor_style']);
     268$this->assertNull($data['style']);
     269
    263270    }
    264271
     
    300307$this->assertSame(“”,$data['description']);
    301308$this->assertNull($data['icon']);
    302 $this->断言空($data['editor_script'] );
    303 $this->断言空($data['script'] );
    304 $this->断言空($data['view_script'] );
    305 $this->断言空($data['editor_style'] );
    306 $this->断言空($data['style'] );
     309$this->断言SameSet(数组(),$data['editor_script_handles'] );
     310$this->断言SameSet(数组(),$data['script_handles'] );
     311$this->断言SameSet(数组(),$data['view_script_handles'] );
     312$this->断言SameSet(数组(),$data['editor_style_handles'] );
     313$this->断言SameSet(数组(),$data['style_handles'] );
    307314$this->资产SameSetsWithIndex(
    308315阵列(
     
    324331$this->assertFalse($data['is_dynamic']);
    325332$this->assertSameSet(数组(),$data['variations']);
     333//不推荐的属性。
     334$this->assertNull($data['editor_script']);
     335$this->assertNull($data['script']);
     336$this->assertNull($data['view_script']);
     337$this->assertNull($data['editor_style']);
     338$this->assertNull($data[“样式”]);
    326339    }
    327340
     
    393406$data=$response->get_data();
    394407$properties=$data['schema']['properties'];
    395 $this->assertCount(2,$properties);
     408$this->assertCount(28,$properties);
    396409$this->assertArrayHasKey('api_version',$properties);
    397410$this->assertArrayHasKey('title',$properties);
     
    406419$this->assertArrayHasKey(“类别”,$properties);
    407420$this->assertArrayHasKey(“is_dynamic”,$properties);
    408 $this->assertArrayHasKey('editor_script',$properties);
    409 $this->assertArrayHasKey('脚本',$properties);
    410 $this->assertArrayHasKey('view_script',$properties);
    411 $this->assertArrayHasKey('编辑器样式',$properties);
    412 $this->assertArrayHasKey('样式',$properties);
     421$this->assertArrayHasKey('editor_script_把手',$properties);
     422$this->assertArrayHasKey('脚本_手柄',$properties);
     423$this->assertArrayHasKey('view_script_把手',$properties);
     424$this->assertArrayHasKey('编辑器样式_把手',$properties);
     425$this->assertArrayHasKey('样式_把手',$properties);
    413426$this->assertArrayHasKey(“父级”,$properties);
    414427$this->assertArrayHasKey(“示例”,$properties);
     
    417430$this->assertArrayHasKey(“变体”,$properties);
    418431$this->assertArrayHasKey(“祖先”,$properties);
     432//不推荐的属性。
     433$this->assertArrayHasKey('editor_script',$properties);
     434$this->assertArrayHasKey(“脚本”,$properties);
     435$this->assertArrayHasKey('view_script',$properties);
     436$this->assertArrayHasKey('editor_style',$properties);
     437$this->assertArrayHasKey(“样式”,$properties);
     438
    419439    }
    420440
     
    519539“名称”,
    520540“类别”,
    521 '编辑器脚本',
    522 '脚本',
    523 '视图脚本',
    524 '编辑器样式',
    525 '样式',
     541'编辑器脚本_把手',
     542'脚本_把手',
     543'视图脚本_把手',
     544'编辑_样式_把手',
     545'样式_把手',
    526546'标题',
    527547“图标”,
     
    535555'文本域',
    536556“示例”,
     557//不推荐的字段。
     558'编辑脚本',
     559“脚本”,
     560'视图脚本',
     561'编辑器样式',
     562“样式”,
    537563        );
    538564
注:请参见TracChangeset(跟踪变更集)获取有关使用变更集查看器的帮助。