变更集55847
时间戳: 2023年5月22日下午07:11:36 ( 13个月 (之前) 位置: 大旅行箱 文件夹: -
4编辑
-
src/wp-includes/class-wp-query.php (已修改) ( 4个差异 ) -
src/wp-includes/media.php (已修改) ( 4个差异 ) -
tests/phpunit/tests/media.php (已修改) ( 8个差异 ) -
tests/phpunit/tests/query.php (已修改) ( 1个差异 )
图例:
未修改 补充 远离的
-
trunk/src/wp-includes/class-wp-query.php 55822兰特 55847兰特 108 108 */ 109 109 公共$current_post=-1; 110 111 /** 112 *调用方是否在循环之前。 113 * 114 *@自6.3.0起 115 *@var bool 116 */ 117 public$before_loop=true; 110 118 111 119 /** … … 518 526 $this->current_post=-1; 519 527 $this->in_the_loop=假; 528 $this->before_roop=true; 520 529 unset($this->请求); 521 530 取消设置($this->帖子); … … 3632 3641 3633 3642 $this->in_the_loop=true; 3643 $this->before_loop=false; 3634 3644 3635 3645 if(-1==$this->current_post){//循环刚刚启动。 … … 3672 3682 $this->rewind_posts(); 3673 3683 }elseif(0===$this->post_count){ 3684 $this->before_roop=false; 3685 3674 3686 /** 3675 3687 *如果在后期查询中找不到结果,则激发。 -
trunk/src/wp-includes/media.php 55843兰特 55847兰特 5491 5491 *@自5.9.0起 5492 5492 * 5493 *@global WP_Query$WP_Query WordPress查询对象。 5494 * 5493 5495 *@param string$context请求“loading”属性值的元素的上下文。 5494 5496 *@return string | bool默认的“加载”属性值。 “lazy”、“eager”或布尔值“false”表示 … … 5496 5498 */ 5497 5499 函数wp_get_loading_attr_default($context){ 5500 全局$wp_query; 5501 5498 5502 //跳过整个块模板的延迟加载,因为它处理得更精细。 5499 5503 if('template'===$context){ … … 5502 5506 5503 5507 //不要在头块模板部分延迟加载图像,因为它们可能位于折叠上方。 5508 //对于经典主题,这是在下面的条件下使用“get_header”操作处理的。 5504 5509 $header_area=WP_TEMPLATE_PART_area_header; 5505 5510 if(“template_part{$header_area}”===$context){ … … 5507 5512 } 5508 5513 5509 /* 5510 *跳过帖子内容中以编程方式创建的图像,因为它们需要与其他图像一起处理 5511 *文章内容中的图片。 5512 *如果没有这一条款,它们将被计算在下面,这将导致数字倾斜,并可能导致第一个 5513 *帖子内容图像被延迟加载,只是因为帖子内容中的其他地方有图像。 5514 */ 5515 if(('the_post_thumbnail'===$context||'wp_get_attachment_image'===$context)&&doing_filter('the_content')){ 5516 返回false; 5514 //对以编程方式创建的图像标记的特殊处理。 5515 if((“the_post_thumbnail”===$context ||“wp_get_attachment_image”===$context)){ 5516 /* 5517 *跳过帖子内容中以编程方式创建的图像,因为它们需要与其他图像一起处理 5518 *帖子内容中的图片。 5519 *如果没有这一条款,它们就已经被计算在内了,这会使数字倾斜,并可能导致第一个 5520 *由于帖子内容中的其他地方有图片,所以帖子内容图片被延迟加载。 5521 */ 5522 if(doing_filter('thecontent')){ 5523 返回false; 5524 } 5525 5526 //有条件地跳过循环之前对图像的延迟加载。 5527 如果( 5528 //仅适用于主查询,但在循环之前。 5529 $wp_query->before_loop&&$wp_cquery->is_main_query() 5530 /* 5531 *循环之前、但标头启动之后的任何图像都不应延迟加载, 5532 *除非页脚已经开始,当当前模板 5533 *不包括任何循环。 5534 */ 5535 &&did_action('get_header')&&! did_action('get_footer') 5536 ) { 5537 返回false; 5538 } 5517 5539 } 5518 5540 -
trunk/tests/phpunit/tests/media.php 55825卢比 55847兰特 3560 3560 */ 3561 3561 公共函数test_wp_get_loading_attr_default($context){ 3562 全局$wp_query,$wp_the_query; 3563 3564 3562 //默认返回“lazy”。 3565 3563 $this->assertSame('lazy',wp_get_loading_attr_default('test')); … … 3569 3567 $this->assertSame('lazy',wp_get_loading_attr_default($context)); 3570 3568 3571 $ wp_query=新的wp_query(数组(“post_in”=>数组(self::$post_ids[“publish”])) ); 3569 $ 查询=$this->get_new_wp_query_for_published_post( ); 3572 3570 $this->reset_content_media_count(); 3573 3571 $this->reset_omit_loading_attr_filter(); … … 3580 3578 3581 3579 //设置为主查询。 3582 $ wp_the_query=$wp_query ; 3580 $ this->set_main_query($query) ; 3583 3581 3584 3582 //对于主内容以外的上下文,即使在循环中也会返回“lazy” … … 3614 3612 */ 3615 3613 公共函数test_wp_omit_loading_attr_threshold_filter(){ 3616 全局$wp_query,$wp_the_query; 3617 3618 $wp_query=新wp_query(数组('post_in'=>数组(self::$post_ids['publish'])); 3619 $wp_the_query=$wp_query; 3614 $query=$this->get_new_wp_query_for_published_post(); 3615 $this->set_main_query($query); 3620 3616 $this->reset_content_media_count(); 3621 3617 $this->reset_omit_loading_attr_filter(); … … 3641 3637 */ 3642 3638 公共函数test_wp_filter_content_tags_with_wp_get_loading_attr_default(){ 3643 全局$wp_query,$wp_the_query; 3644 3645 3639 $img1=get_image_tag(self::$large_id,“”,“”; 3646 3640 $iframe1='<iframe src=“ https://www.example.com “width=”640“height=”360“></iframe>'; … … 3660 3654 $content_expected=wp_img_tag_add_decoding_attr($content_expected,'the_content'); 3661 3655 3662 $ wp_query=新的wp_query(数组(“post_in”=>数组(self::$post_ids[“publish”])) ); 3663 $ wp_the_query=$wp_query ; 3656 $ 查询=$this->get_new_wp_query_for_published_post( ); 3657 $ this->setmainquery($query) ; 3664 3658 $this->reset_content_media_count(); 3665 3659 $this->reset_omit_loading_attr_filter(); … … 3697 3691 $omit_threshold=wp_omit_loading_attr_thresho尔德(true); 3698 3692 $this->assertSame(1,$omit_threshold); 3693 } 3694 3695 /** 3696 *测试wp_get_loading_attr_default()在循环之前返回预期的加载属性值,如果不是主查询,则在get_header之后返回。 3697 * 3698 *@机票58211 3699 * 3700 *@封面::wp_get_loading_attr_default 3701 * 3702 *@dataProvider数据_wp_get_loading_attr_default_before_and_no_loop 3703 * 3704 *@param string$context请求“loading”属性值的元素的上下文。 3705 */ 3706 公共函数test_wp_get_loading_attr_default_before_loop_if_not_main_query($context){ 3707 全局$wp_query; 3708 3709 $wp_query=$this->get_new_wp_query_for_published_post(); 3710 $this->reset_content_media_count(); 3711 $this->reset_omit_loading_attr_filter(); 3712 3713 do_action('get_header'); 3714 3715 //如果不是主查询,则为惰性查询。 3716 $this->assertSame('lazy',wp_get_loading_attr_default($context)); 3717 } 3718 3719 /** 3720 *测试wp_get_loading_attr_default()在主查询的get_header之前但之后返回预期的加载属性值,但header未被调用。 3721 * 3722 *@票58211 3723 * 3724 *@covers::wp_get_loading_attr_default 3725 * 3726 *@dataProvider数据_wp_get_loading_attr_default_before_and_no_loop 3727 * 3728 *@param string$context请求“loading”属性值的元素的上下文。 3729 */ 3730 公共函数test_wp_get_loading_attr_default_before_loop_in_main_query_but_header_not_called($context){ 3731 全局$wp_query; 3732 3733 $wp_query=$this->get_new_wp_query_for_published_post(); 3734 $this->set_main_query($wp_query); 3735 $this->reset_content_media_count(); 3736 $this->reset_omit_loading_attr_filter(); 3737 3738 //如果未调用标头,则为Lazy。 3739 $this->assertSame('lazy',wp_get_loading_attr_default($context)); 3740 } 3741 3742 /** 3743 *测试wp_get_loading_attr_default()在主查询的循环之前、get_header之后返回预期的加载属性值。 3744 * 3745 *@机票58211 3746 * 3747 *@封面::wp_get_loading_attr_default 3748 * 3749 *@数据提供程序data_wp_get_loading_attr_default_before_and_no_loop 3750 * 3751 *@param string$context请求“loading”属性值的元素的上下文。 3752 */ 3753 公共函数test_wp_get_loading_attr_default_before_loop_if_main_query($context){ 3754 全局$wp_query; 3755 3756 $wp_query=$this->get_new_wp_query_for_published_post(); 3757 $this->set_main_query($wp_query); 3758 $this->reset_content_media_count(); 3759 $this->reset_omit_loading_attr_filter(); 3760 3761 do_action('get_header'); 3762 $this->assertFalse(wp_get_loading_attr_default($context)); 3763 } 3764 3765 /** 3766 *测试wp_get_loading_attr_default()在get_header和循环之后返回预期的加载属性值。 3767 * 3768 *@机票58211 3769 * 3770 *@covers::wp_get_loading_attr_default 3771 * 3772 *@dataProvider数据_wp_get_loading_attr_default_before_and_no_loop 3773 * 3774 *@param string$context请求“loading”属性值的元素的上下文。 3775 */ 3776 公共函数test_wp_get_loading_attr_default_after_loop($context){ 3777 全局$wp_query; 3778 3779 $wp_query=$this->get_new_wp_query_for_published_post(); 3780 $this->set_main_query($wp_query); 3781 $this->reset_content_media_count(); 3782 $this->reset_omit_loading_attr_filter(); 3783 3784 do_action('get_header'); 3785 3786 while(have_posts()){ 3787 post(); 3788 } 3789 $this->assertSame('lazy',wp_get_loading_attr_default($context)); 3790 } 3791 3792 /** 3793 *测试wp_get_loading_attr_default()是否在没有循环的情况下返回预期的加载属性。 3794 * 3795 *@机票58211 3796 * 3797 *@covers::wp_get_loading_attr_default 3798 * 3799 *@dataProvider数据_wp_get_loading_attr_default_before_and_no_loop 3800 * 3801 *@param string$context请求“loading”属性值的元素的上下文。 3802 */ 3803 公共函数test_wp_get_loading_attr_default_no_loop($context){ 3804 全局$wp_query; 3805 3806 $wp_query=$this->get_new_wp_query_for_published_post(); 3807 $this->set_main_query($wp_query); 3808 $this->reset_content_media_count(); 3809 $this->reset_omit_loading_attr_filter(); 3810 3811 //确保页眉和页脚被调用。 3812 do_action('get_header'); 3813 do_action('get_footer'); 3814 3815 //如果没有调用循环和页脚,则加载lazy。 3816 $this->assertSame('lazy',wp_get_loading_attr_default($context)); 3817 } 3818 3819 /** 3820 *数据提供商。 3821 * 3822 *@return数组[] 3823 */ 3824 公共函数data_wp_get_loading_attr_default_before_and_no_loop(){ 3825 返回数组( 3826 数组(“wp_get_attachment_image”), 3827 数组('the_post_thumbnail'), 3828 ); 3699 3829 } 3700 3830 … … 4167 4297 ); 4168 4298 } 4299 4300 /** 4301 *返回新的WP_Query。 4302 * 4303 *@global WP_Query$WP_Query WordPress查询对象。 4304 * 4305 *@return WP_Query新建查询。 4306 */ 4307 公共函数get_new_wp_query_for_published_post(){ 4308 全局$wp_query; 4309 4310 //对$wp_query的新查询。 更新循环的全局。 4311 $wp_query=新wp_query(数组('post_in'=>数组(self::$post_ids['publish'])); 4312 4313 返回$wp_query; 4314 } 4315 4316 /** 4317 *将查询设置为主查询。 4318 * 4319 *@global WP_Query$WP_the_Query WordPress查询对象。 4320 * 4321 *@param WP_Query$Query查询要设置为主查询。 4322 */ 4323 公共函数set_main_query($query){ 4324 全局$wp_the_query; 4325 $wp_the_query=$query; 4326 } 4169 4327 } 4170 4328 -
trunk/tests/phpunit/tests/query.php 54891卢比 55847兰特 898 898 $this->assertFalse($q->is_tag('non-existent-tag')); 899 899 } 900 901 /** 902 *在循环之前测试$before_loop是否为true。 903 * 904 *@机票58211 905 */ 906 公共函数test_before_loop_value_set_true_before_the_loop(){ 907 //获取包含3个帖子的新查询。 908 $query=$this->get_new_wp_query_with_posts(3); 909 910 $this->assertTrue($query->before_loop); 911 } 912 913 /** 914 *循环开始时,Test$before_loop值设置为false。 915 * 916 *@机票58211 917 * 918 *@covers WP_Query::the_post 919 */ 920 公共函数test_before_loop_value_set_to_false_in_loop_with_post(){ 921 //获取包含2个帖子的新查询。 922 $query=$this->get_new_wp_query_with_posts(2); 923 924 while($query->have_posts()){ 925 //$before_loop应该在第一次调用_post时设置为false。 926 $query->the_post(); 927 928 $this->assertFalse($query->before_loop); 929 断裂; 930 } 931 } 932 933 /** 934 *当循环中没有post时,Test$before_loop值设置为false。 935 * 936 *@机票58211 937 * 938 *@covers WP_Query::have_posts 939 */ 940 公共函数test_before_loop_set_false_after_loop_with_no_post(){ 941 //结果中没有任何帖子的新查询。 942 $query=新WP_query( 943 阵列( 944 “category_name”=>“不存在的类别”, 945 ) 946 ); 947 948 //不会有任何帖子,因此循环永远不会真正进入。 949 while($query->have_posts()){ 950 $query->the_post(); 951 } 952 953 //尽管如此,这应该是错误的,因为没有结果并且试图进入循环。 954 $this->assertFalse($query->before_loop); 955 } 956 957 /** 958 *获取具有给定帖子数的新查询。 959 * 960 *@param int$no_of_posts要在查询中添加的帖子数。 961 */ 962 公共函数get_new_wp_query_with_posts($no_of_posts){ 963 $post_ids=self::factory()->post->create_many($no_of_posts); 964 $query=新的WP_query(数组(“post_in”=>$post_id)); 965 return$query; 966 } 900 967 }