变更集58041
时间戳: 2024年4月24日下午12:00:29 ( 4周 (之前) 位置: 分支/6.5 文件夹: -
添加了1个 5已编辑
-
src/wp-includes/block-template-utils.php (已修改) ( 3个差异 ) -
src/wp-includes/default-filters.php (已修改) ( 1个差异 ) -
src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php (已修改) ( 1个差异 ) -
tests/phpunit/tests/block-template-utils.php (已修改) ( 1个差异 ) -
tests/phpunit/tests/block-templates/injectIgnoredHookedBlocksMetadataAttributes.php (已添加) -
tests/phpunit/tests/rest-api/wpRestTemplatesController.php (已修改) ( 9个差异 )
图例:
未修改 补充 已删除
-
分支/6.5/src/wp-includes/block-template-utils.php 57947兰特 58041兰特 724 724 725 725 /** 726 *基于post object构建统一的模板对象。 727 * 728 *@自5.9.0起 729 *@自6.3.0起在模板对象中添加了“modified”属性。 730 *@自6.4.0起增加了对传递给此函数的修订帖子的支持。 726 *从post对象构建块模板对象。 727 * 728 *这是一个帮助函数,用于从给定的post对象创建块模板对象。 729 *它是自给自足的,因为它只使用作为参数传递的信息; 它没有 730 *查询数据库以获取更多信息。 731 * 732 *@自6.5.1起 731 733 *@access私有 732 734 * 733 *@param WP_Post$Post模板帖子。 735 *@param WP_Post$Post模板帖子。 736 *@param array$terms通知模板对象的其他术语。 737 *@param array$meta通知模板对象的其他元字段。 734 738 *@return WP_Block_Template | WP_Error模板或错误对象。 735 739 */ 736 函数_build_block_template_result_from_post($post){ 740 函数_build_block_template_object_from_post_object($post,$terms=array(),$meta=array()){ 741 if(空($terms['wp_theme']){ 742 return new WP_Error('template_missing_theme',__('没有为此模板定义主题。')); 743 } 744 $theme=$terms['wp_theme']; 745 737 746 $default_template_types=获取默认块模板类型(); 738 747 739 $post_id=wp_is_post_revision($post); 740 if(!$post_id){ 741 $post_id=$post; 742 } 743 $parent_post=获取post($post_id); 744 745 $terms=get_the_terms($parent_post,'wp_theme'); 746 747 if(iswp_error($terms)){ 748 返回$terms; 749 } 750 751 if(!$terms){ 752 return new WP_Error('template_missing_theme',__('没有为此模板定义主题。')); 753 } 754 755 $theme=$terms[0]->名称; 756 748 $template_file=_get_block_template_file($post->post_type,$post->post_name); 757 749 $has_theme_file=get_stylesheet()===$theme&&null!==$ template_file; 758 750 759 $origin=get_post_meta($parent_post->ID,'origin',true); 760 $is_wp_suggestion=get_post_meta($parent_post->ID,'is_wp_suggession',true); 761 762 751 $template=新的WP_Block_template(); 763 752 $template->wp_id=$post->id; 764 $template->id=$theme.'//'$ 对 父母 ost->post_name; 753 $template->id=$theme.'//'$ 对 ost->post_name; 765 754 $template->theme=$theme; 766 755 $template->content=$post->post_content; 767 756 $template->slug=$post->post_name; 768 757 $template->source=“自定义”; 769 $template->origin=! 空($ 原产地)$ 起源 :null; 758 $template->origin=! 空($ meta[“源”])$ meta[“源”] :null; 770 759 $template->type=$post->post_type; 771 760 $template->description=$post->post_excerpt; … … 773 762 $template->status=$post->post_status; 774 763 $template->has_theme_file=$has_ttheme_file; 775 $template->is_custom=空($ is_wp_建议 ); 764 $template->is_custom=空($ 元['is_wp_suggestion'] ); 776 765 $template->author=$post->post_author; 777 766 $template->modified=$post->post_modified; 778 767 779 if('wp_template'===$p 父母 ost->post_type&&$has_theme_file&&isset($template_file['postTypes']){ 768 if('wp_template'===$p ost->post_type&&$has_theme_file&&isset($template_file['postTypes']){ 780 769 $template->post_types=$template_file['postTypes']; 781 770 } 782 771 783 if('wp_template'===$p 父母 ost->post_type&&isset($default_template_types[$template->slug]){ 772 if('wp_template'===$p ost->post_type&&isset($default_template_types[$template->slug]){ 784 773 $template->is_custom=false; 785 774 } 775 776 if('wp_template_part'====$post->post_type&&isset($terms['wp_template_part_area'])){ 777 $template->区域=$terms['wp_template_part_area']; 778 } 779 780 返回$template; 781 } 782 783 /** 784 *基于post object构建统一的模板对象。 785 * 786 *@自5.9.0起 787 *@自6.3.0起在模板对象中添加了“modified”属性。 788 *@自6.4.0起增加了对传递给此函数的修订帖子的支持。 789 *@access私有 790 * 791 *@param WP_Post$Post模板帖子。 792 *@return WP_Block_Template | WP_Error模板或错误对象。 793 */ 794 函数_build_block_template_result_from_post($post){ 795 $post_id=wp_is_post_revision($post); 796 if(!$post_id){ 797 $post_id=$post; 798 } 799 $parent_post=获取post($post_id); 800 $post->post_name=$parent_post->post-name; 801 $post->post_type=$parent_post->post-type; 802 803 $terms=get_the_terms($parent_post,'wp_theme'); 804 805 if(iswp_error($terms)){ 806 返回$terms; 807 } 808 809 如果(!$terms){ 810 return new WP_Error('template_missing_theme',__('没有为此模板定义主题。')); 811 } 812 813 $terms=数组( 814 “wp_theme”=>$terms[0]->名称, 815 ); 786 816 787 817 if(“wp_template_part”===$parent_post->post_type){ 788 818 $type_terms=get_the_terms($parent_post,'wp_template_part_area'); 789 819 if(!iswp_error($type_terms)&&false!==$ type_terms){ 790 $template->area=$type_terms[0]->名称; 791 } 820 $terms['wp_template_part_area']=$type_terms[0]->名称; 821 } 822 } 823 824 $meta=数组( 825 'origin'=>get_post_meta($parent_post->ID,'origin'',true), 826 “is_wp_suggestion”=>get_post_meta($parent_post->ID,“is_wp_suggession”,true), 827 ); 828 829 $template=_build_block_template_object_from_post_object($post、$terms、$meta); 830 831 if(iswp_error($template)){ 832 返回$template; 792 833 } 793 834 … … 1443 1484 *@access私有 1444 1485 * 1445 *@param stdClass$post表示模板或模板部分的对象 1446 *准备插入或更新数据库。 1447 *@param WP_REST_Request$请求请求对象。 1448 *@return stdClass表示模板或模板部分的更新对象。 1449 */ 1450 函数inject_ignored_hooked_blocks_metadata_attributes($post,$request){ 1451 $filter_name=当前过滤器(); 1452 if(!str_starts_with($filter_name,'rest_pre_insert_')){ 1453 返回$post; 1454 } 1455 $post_type=str_replace('rest_pre_insert_','',$filter_name); 1486 *@param stdClass$changes表示模板或模板部分的对象 1487 *准备插入或更新数据库。 1488 *@param WP_REST_Request$已弃用。 未使用。 1489 *@return stdClass | WP_Error表示模板或模板部分的更新对象。 1490 */ 1491 函数inject_ignored_hooked_blocks_metadata_attributes($changes,$deprecated=null){ 1492 if(null!==$已弃用){ 1493 _预制_参数(__FUNCTION_,'6.5.1'); 1494 } 1456 1495 1457 1496 $hooked_blocks=获取挂钩块(); 1458 1497 if(空($hooked_blocks)&&! has_filter('挂钩块类型'){ 1459 返回$post; 1460 } 1461 1462 //此时,帖子已经创建。 1463 //我们需要构建相应的“WP_Block_Template”对象作为访问者的上下文参数。 1464 //为此,我们需要禁止钩子块插入到模板中。 1465 add_filter('hooked_block_types','__return_empty_array',99999,0); 1466 $template=$request['id']? get_block_template($request['id'],$post_type):null; 1467 删除过滤器('挂钩块类型','返回空数组',99999); 1498 返回$changes; 1499 } 1500 1501 $meta=isset($changes->meta_input)$ 更改->meta_input:array(); 1502 $terms=isset($changes->tax_input)$ 更改->tax_input:数组(); 1503 1504 if(空($changes->ID)){ 1505 //该模板的数据库中还没有该模板的post对象。 1506 $post=$个更改; 1507 }其他{ 1508 //查找现有的post对象。 1509 $post=get_post($changes->ID); 1510 1511 //如果文章是修订版,请使用父文章的post_name和post_type。 1512 $post_id=wp_is_post_revision($post); 1513 if($post_id){ 1514 $parent_post=获取post($post_id); 1515 $post->post_name=$parent_post->post-name; 1516 $post->post_type=$parent_post->post-type; 1517 } 1518 1519 //将更改应用于现有post对象。 1520 $post=(对象)array_merge((数组)$post,(数组)$更改); 1521 1522 $type_terms=get_the_terms($changes->ID,'wp_theme'); 1523 $terms['wp_theme']=! is_wp_error($type_terms)&&! 空($type_terms)$ type_terms[0]->名称:空; 1524 } 1525 1526 //WP_Block_Template必需。 使用当前时间更新post对象。 1527 $post->post_modified=当前时间('mysql'); 1528 1529 //如果post_author为空,则将其设置为当前用户。 1530 if(空($post->post_author)){ 1531 $post->post_author=get_current_user_id(); 1532 } 1533 1534 if('wp_template_part'===$post->post_type&&!isset($terms['wp_template_part_area']){ 1535 $area_terms=get_the_terms($changes->ID,'wp_template_part_area'); 1536 $terms['wp_template_part_area']=! is_wp_error($area_terms)&&! 空($area_terms)$ area_terms[0]->名称:空; 1537 } 1538 1539 $template=_build_block_template_object_from_post_object(新WP_post($post),$terms,$meta); 1540 1541 if(iswp_error($template)){ 1542 返回$template; 1543 } 1468 1544 1469 1545 $before_block_visitor=make_before_block_visitor($hooked_blocks,$template,'set_ignored_blocks_metadata'); 1470 1546 $after_block_visitor=make_after_block_访客($hooked_blocks,$template,'set_ignored_hooked_ blocks_metadata'); 1471 1547 1472 $blocks=解析块($post->post_content); 1473 $content=traverse_and_serialize_blocks($blocks,$before_block_visitor,$after_block_visitors); 1474 1475 $post->post_content=$content; 1476 返回$post; 1477 } 1548 $blocks=parse_blocks($changes->post_content); 1549 $changes->post_content=traverse_and_serialize_blocks($blocks,$before_block_visitor,$after_block_visitors); 1550 1551 返回$changes; 1552 } -
分支/6.5/src/wp-includes/default-filters.php r57802码 58041兰特 754 754 755 755 //将ignoredHookedBlocks元数据属性添加到模板和模板零件发布类型。 756 add_filter(“rest_pre_insert_wp_template”,“inject_ignored_hooked_blocks_metadata_attributes” , 10, 2 ); 757 添加过滤器(“rest_pre_insert_wp_template_part”,“inject_ignored_hooked_blocks_metadata_attributes” , 10, 2 ); 756 add_filter(“rest_pre_insert_wp_template”,“inject_ignored_hooked_blocks_metadata_attributes” ); 757 添加过滤器(“rest_pre_insert_wp_template_part”,“inject_ignored_hooked_blocks_metadata_attributes” ); 758 758 759 759 未设置($filter,$action); -
分支/6.5/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php r57802码 58041兰特 533 533 * 534 534 *@param WP_REST_Request$请求请求对象。 535 *@return stdClass 要传递给wp_update_post的更改。 535 *@return stdClass |WP_错误 要传递给wp_update_post的更改。 536 536 */ 537 537 受保护函数prepare_item_for_database($request){ -
分支/6.5/tests/phpunit/tests/block-template-utils.php 57803兰特 58041兰特 404 404 $this->assertTrue($has_html_files,'包含至少一个html文件'); 405 405 } 406 407 /** 408 *@票60671 409 * 410 *@covers inject_ignored_hooked_blocks_metadata_attributes 411 */ 412 公共函数test_inject_ignored_hooked_blocks_metadata_attributes_into_template(){ 413 全局$wp_current_filter; 414 //模拟当前设置的过滤器。 $wp_current_filter全局在拆卸过程中由重置 415 //测试/phpunit/includes/abstract-testcase.php中的WP_UnitTestCase_Base::_restore_hooks()。 416 $wp_current_filter[]=“rest_pre_insert_wp_template”; 417 418 寄存器块类型( 419 '测试/挂接块', 420 阵列( 421 “block_hooks”=>数组( 422 “测试/锚块”=>“之后”, 423 ), 424 ) 425 ); 426 427 $id=self::TEST_THEME.'//'。' my_template'; 428 $request=新的WP_REST_request('POST','/WP/v2/templates/'.$id); 429 430 $changes=新stdClass(); 431 $changes->post_content='<!-- wp:tests/anchor-block-->你好<!--/ wp:测试/锚块-->'; 432 433 $post=inject_ignored_hooked_blocks_metadata_attributes($changes,$request); 434 $this->资产相同( 435 '<!-- wp:tests/anchor-block{“metadata”:{“ignoredHookedBlocks”:[“tests/hoked-block”]}-->Hello<!--/ wp:测试/锚块-->', 436 $post->post_content, 437 “钩子块未插入锚块的ignoredHookedBlocks元数据。” 438 ); 439 } 440 441 /** 442 *@票60671 443 * 444 *@covers inject_ignored_hooked_blocks_metadata_attributes 445 */ 446 公共函数test_inject_ignored_hooked_blocks_metadata_attributes_into_template_part(){ 447 全局$wp_current_filter; 448 //模拟当前设置的过滤器。 $wp_current_filter全局变量在拆卸期间被重置 449 //测试/phpunit/includes/abstract-testcase.php中的WP_UnitTestCase_Base::_restore_hooks()。 450 $wp_current_filter[]=“rest_pre_insert_wp_template_part”; 451 452 寄存器块类型( 453 '测试/挂接块', 454 阵列( 455 “block_hooks”=>数组( 456 “测试/锚块”=>“之后”, 457 ), 458 ) 459 ); 460 461 $id=self::TEST_THEME.'//'。' 我的模板部件'; 462 $request=新的WP_REST_request('POST','/WP/v2/template-parts/'.$id); 463 464 $changes=新的stdClass(); 465 $changes->post_content='<!-- wp:tests/anchor-block-->你好<!--/ wp:测试/锚块-->'; 466 467 $post=inject_ignored_hooked_blocks_metadata_attributes($changes,$request); 468 $this->资产相同( 469 '<!-- wp:tests/anchor-block{“metadata”:{“ignoredHookedBlocks”:[“tests/hoked-block”]}-->Hello<!--/ wp:测试/锚块-->', 470 $post->post_content, 471 “钩子块未插入锚块的ignoredHookedBlocks元数据。” 472 ); 473 } 474 406 } -
分支/6.5/tests/phpunit/tests/rest-api/wpRestTemplatesController.php r57802码 58041兰特 15 15 */ 16 16 受保护的静态$admin_id; 17 私有静态$post; 17 私有静态$template_post; 18 私有静态$template_part_post; 18 19 19 20 /** … … 30 31 31 32 //设置模板帖子。 32 $个参数 =数组( 33 $个参数 =数组( 33 34 “post_type”=>“wp_template”, 34 35 “post_name”=>“my_template”, … … 42 43 ), 43 44 ); 44 self::$post=self:;factory()->post->create_and_get($args); 45 wp_set_post_terms(self::$post->ID,get_stylesheet(),'wp_theme'); 45 自我::$template_post=self::factory()->post->create_and_get($args); 46 wp_set_post_terms(self::$template_post->ID,get_stylesheet(),'wp_theme'); 47 48 //设置模板部件发布。 49 $args=阵列( 50 'post_type'=>'wp_template_part', 51 “post_name”=>“my_template_part”, 52 “post_title”=>“我的模板部件”, 53 'post_content'=>'内容', 54 “post_excerpt”=>“我的模板部件说明”, 55 “tax_input”=>数组( 56 “wp_theme”=>数组( 57 获取样式表(), 58 ), 59 “wp_template_part_area”=>数组( 60 WP_模板_零件_区域_标题, 61 ), 62 ), 63 ); 64 self::$template_part_post=self::factory()->post->create_and_get($args); 65 wp_set_post_terms(self::$template_part_post->ID,get_stylesheet(),'wp_theme'); 66 wp_set_post_terms(自::$template_part_post->ID,wp_template_part_AREA_HEADER,'wp_template_part_AREA'); 46 67 } 47 68 48 69 公共静态函数wpTearDownAfterClass(){ 49 wp_delete_post(自身::$ post->ID); 70 wp_delete_post(自身::$ 模板_ post->ID); 50 71 } 51 72 … … 57 78 公共函数tear_down(){ 58 79 if(has_filter('rest_pre_insert_wp_template_part','inject_ignored_hooked_blocks_metadata_attributes')){ 59 删除过滤器('rest_pre_insert_wp_template_part','注入_ignored_hooked_blocks_metadata_attributes' , 10 ); 80 删除过滤器('rest_pre_insert_wp_template_part','注入_ignored_hooked_blocks_metadata_attributes' ); 60 81 } 61 82 if(WP_Block_Type_Registry::get_instance()->已注册(“测试/块”)){ … … 131 152 ), 132 153 “status”=>“publish”, 133 “wp_id”=>自我::$ 帖子->ID, 154 “wp_id”=>自我::$ 模板_ 帖子->ID, 134 155 “has_theme_file”=>假, 135 156 “is_custom”=>为true, 136 157 '作者'=>0, 137 “修改”=>mysql_to_rfc3339(自我::$ post->post_modified), 158 “修改”=>mysql_to_rfc3339(自我::$ 模板_ post->post_modified), 138 159 “author_text”=>“测试博客”, 139 160 “original_source”=>“site”, … … 178 199 ), 179 200 “status”=>“发布”, 180 “wp_id”=>自我::$ 帖子->ID, 201 “wp_id”=>自我::$ 模板_ 帖子->ID, 181 202 “has_theme_file”=>假, 182 203 “is_custom”=>为true, 183 204 “作者”=>0, 184 “修改”=>mysql_to_rfc3339(自我::$ post->post_modified), 205 “修改”=>mysql_to_rfc3339(自我::$ 模板_ post->post_modified), 185 206 “author_text”=>“测试博客”, 186 207 “original_source”=>“site”, … … 217 238 ), 218 239 “status”=>“publish”, 219 “wp_id”=>自我::$ 帖子->ID, 240 “wp_id”=>自我::$ 模板_ 帖子->ID, 220 241 “has_theme_file”=>假, 221 242 “is_custom”=>为true, 222 243 '作者'=>0, 223 “修改”=>mysql_to_rfc3339(自我::$ post->post_modified), 244 “修改”=>mysql_to_rfc3339(自我::$ 模板_ post->post_modified), 224 245 “author_text”=>“测试博客”, 225 246 “original_source”=>“site”, … … 945 966 ); 946 967 947 添加过滤器(“rest_pre_insert_wp_template_part”,“inject_ignored_hooked_blocks_metadata_attributes” ,10,2 ); 968 添加过滤器(“rest_pre_insert_wp_template_part”,“inject_ignored_hooked_blocks_metadata_attributes” ); 948 969 949 970 $endpoint=新WP_REST_Templates_Controller('WP_template_part'); … … 952 973 $prepare_item_for_database->setAccessible(true); 953 974 975 $id=get_stylesheet().'//'。' 我的模板部件'; 954 976 $body_params=数组( 955 ' title“=>”无标题模板部件“ , 956 '段塞'=>' 无标题模板- 部件', 977 ' id’=>$id , 978 '段塞'=>' 我的模板(_T)_ 部件', 957 979 “内容”=>“<!-- wp:tests/anchor-block-->你好<!--/ wp:测试/锚块-->', 958 980 );