使WordPress成为核心

变更集57944


忽略:
时间戳:
2024年8月4日下午04:45:22(7周(之前)
作者:
大戟
消息:

在站点编辑器中创建模板时遵循template_hierarchy过滤器。

目前,在区块主题中,可以使用${type}模板层次结构筛选以更改模板层次结构。但是,在站点编辑器中创建新模板时出现的“选择图案”弹出屏幕没有考虑这些过滤器,从而导致编辑器和前端之间不匹配。

Props aljullu、mukes27、ntsekouras、jorgefilipecosta、gziolo。
修复#60846

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

图例:

未修改
补充
远离的
  • trunk/src/wp-includes/block-template-utils.php

    57928兰特 57944兰特  
    13981398函数get_template_hierarchy($slug,$is_custom=false,$template_prefix=''){
    13991399if(“索引”===$slug){
    1400 返回数组(“index”);
     1400/**此过滤器记录在wp-includes/template.php中*/
     1401return apply_filters('index_template_hierarchy',数组('index'));
    14011402    }
    14021403if($is_custom){
    1403 返回数组(“page”,“singular”,“index”);
     1404/**此筛选器记录在wp-includs/template.php中*/
     1405return apply_filters(“page_template_hierarchy”,数组(“page”,“singular”,“index”);
    14041406    }
    14051407if(“front-page”===$slug){
    1406 返回数组(“front-page”、“home”、“index”);
     1408/**此过滤器记录在wp-includes/template.php中*/
     1409return apply_filters('frontpage_template_hierarchy',array('frent-page','home','index'));
    14071410    }
    14081411
     
    14701473    }
    14711474$template_hierarchy[]=“索引”;
     1475
     1476$template_type=“”;
     1477if(!空($template_prefix)){
     1478list($template_type)=分解('-',$template_prefix);
     1479}其他{
     1480列表($template_type)=爆炸('-',$slug);
     1481    }
     1482$valid_template_types=数组('404','archive','attachment','author','category','date','embed','frontpage','home','index','page','paged','privacypolicy','搜索','single','signal','tag','分类法');
     1483if(in_array($template_type,$valid_template_types)){
     1484/**此过滤器记录在wp-includes/template.php中*/
     1485返回apply_filters(“{$template_type}_template_hierarchy”,$template_hierarchies);
     1486    }
    14721487返回$template_hierarchy;
    14731488}
  • trunk/tests/phpunit/tests/block-templates/getTemplateHierarchy.php

    55194兰特 r57944美元  
    4242
    4343/**
     44*@车票60846
     45     */
     46公共函数test_get_template_hierarchy_with_hooks(){
     47添加筛选器(
     48'日期模板层次结构',
     49函数($templates){
     50return array_merge(数组('date-custom'),$templates);
     51            }
     52        );
     53$expected=数组('date-custom','date','archive','index');
     54$this->assertSame($expected,get_template_hierarchy('date'));
     55    }
     56
     57/**
    4458*数据提供商。
    4559*
注:请参见TracChangeset(跟踪变更集)获取有关使用变更集查看器的帮助。