Changeset 55318
- Timestamp:
- 02/13/2023 06:32:40 PM (18 months ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-template.php
r54817 r55318 242 242 $content = convert_smilies( $content ); 243 243 $content = shortcode_unautop( $content ); 244 $content = wp_filter_content_tags( $content );244 $content = wp_filter_content_tags( $content ); 245 245 $content = do_shortcode( $content ); 246 246 $content = str_replace( ']]>', ']]>', $content ); -
trunk/src/wp-includes/media.php
r55251 r55318 5445 5445 */ 5446 5446 function wp_get_loading_attr_default( $context ) { 5447 // Only elements with 'the_content' or 'the_post_thumbnail' context have special handling. 5448 if ( 'the_content' !== $context && 'the_post_thumbnail' !== $context ) { 5447 // Skip lazy-loading for the overall block template, as it is handled more granularly. 5448 if ( 'template' === $context ) { 5449 return false; 5450 } 5451 5452 // Do not lazy-load images in the header block template part, as they are likely above the fold. 5453 $header_area = WP_TEMPLATE_PART_AREA_HEADER; 5454 if ( "template_part_{$header_area}" === $context ) { 5455 return false; 5456 } 5457 5458 /* 5459 * The first elements in 'the_content' or 'the_post_thumbnail' should not be lazy-loaded, 5460 * as they are likely above the fold. 5461 */ 5462 if ( 'the_content' === $context || 'the_post_thumbnail' === $context ) { 5463 // Only elements within the main query loop have special handling. 5464 if ( is_admin() || ! in_the_loop() || ! is_main_query() ) { 5465 return 'lazy'; 5466 } 5467 5468 // Increase the counter since this is a main query content element. 5469 $content_media_count = wp_increase_content_media_count(); 5470 5471 // If the count so far is below the threshold, return `false` so that the `loading` attribute is omitted. 5472 if ( $content_media_count <= wp_omit_loading_attr_threshold() ) { 5473 return false; 5474 } 5475 5476 // For elements after the threshold, lazy-load them as usual. 5449 5477 return 'lazy'; 5450 5478 } 5451 5479 5452 // Only elements within the main query loop have special handling. 5453 if ( is_admin() || ! in_the_loop() || ! is_main_query() ) { 5454 return 'lazy'; 5455 } 5456 5457 // Increase the counter since this is a main query content element. 5458 $content_media_count = wp_increase_content_media_count(); 5459 5460 // If the count so far is below the threshold, return `false` so that the `loading` attribute is omitted. 5461 if ( $content_media_count <= wp_omit_loading_attr_threshold() ) { 5462 return false; 5463 } 5464 5465 // For elements after the threshold, lazy-load them as usual. 5480 // Lazy-load by default for any unknown context. 5466 5481 return 'lazy'; 5467 5482 } -
trunk/tests/phpunit/tests/media.php
r55278 r55318 3548 3548 3549 3549 /** 3550 3551 3550 3552 * @ticket 53675 3553 3554 3555 3556 3551 3557 * @dataProvider data_wp_get_loading_attr_default 3552 3558 * … … 3589 3595 $this->assertSame( 'lazy', wp_get_loading_attr_default( $context ) ); 3590 3596 } 3597 3598 3599 3600 3591 3601 } 3592 3602 … … 3701 3711 } 3702 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3703 3866 private function reset_content_media_count() { 3704 3867 // Get current value without increasing.
Note: See TracChangeset
for help on using the changeset viewer.