| @@ -75,10 +75,17 @@ | ||
| 75 | 75 | 'lazy_videos' => array( |
| 76 | 76 | 'type' => 'bool', |
| 77 | 77 | 'default' => true, |
| 78 | 78 | 'label' => __( 'Lazy-load your own videos', 'xspeed' ), |
| 79 | - 'description' => __( 'Videos uploaded to your site download only when played. Autoplaying videos are left alone.', 'xspeed' ), | |
| 79 | + 'description' => __( 'Videos uploaded to your site download only when played. An autoplaying video still plays by itself, but its file waits until the video is near the screen. Add data-skip-lazy to a video to leave it alone.', 'xspeed' ), | |
| 80 | 80 | ), |
| 81 | + 'video_after_load' => array( | |
| 82 | + 'type' => 'bool', | |
| 83 | + 'default' => false, | |
| 84 | + 'label' => __( 'Start autoplay videos after page load', 'xspeed' ), | |
| 85 | + 'description' => __( 'An autoplaying video, such as a hero background, waits until the page has finished loading, even when it is on screen from the start. Visitors see the poster first, and the video no longer competes with the page\'s images, styles and scripts. Needs "Lazy-load your own videos".', 'xspeed' ), | |
| 86 | + 'dependsOn' => array( 'field' => 'lazy_videos' ), | |
| 87 | + ), | |
| 81 | 88 | 'lazy_background_images' => array( |
| 82 | 89 | 'type' => 'bool', |
| 83 | 90 | 'default' => false, |
| 84 | 91 | 'label' => __( 'Lazy-load background images', 'xspeed' ), |
| @@ -111,9 +118,9 @@ | ||
| 111 | 118 | 'type' => 'list', |
| 112 | 119 | 'default' => array(), |
| 113 | 120 | 'item_type' => 'string', |
| 114 | 121 | 'label' => __( 'Excluded images', 'xspeed' ), |
| 115 | - 'description' => __( 'Images and embeds whose tag contains a line here, such as a class or file name, are never lazy-loaded. Useful for logos and hero images.', 'xspeed' ), | |
| 122 | + 'description' => __( 'Images, videos and embeds whose tag contains a line here, such as a class or file name, are never lazy-loaded. Useful for logos and hero images.', 'xspeed' ), | |
| 116 | 123 | ), |
| 117 | 124 | ); |
| 118 | 125 | } |
| 119 | 126 | |
| @@ -191,8 +198,22 @@ | ||
| 191 | 198 | add_filter( 'post_thumbnail_html', array( Lazy_Loader::class, 'process_html' ), 999 ); |
| 192 | 199 | add_filter( 'get_avatar', array( Lazy_Loader::class, 'process_html' ), 999 ); |
| 193 | 200 | add_filter( 'widget_text_content', array( Lazy_Loader::class, 'process_html' ), 999 ); |
| 194 | 201 | |
| 202 | + /** | |
| 203 | + * Whether media-library images printed in the footer get srcset | |
| 204 | + * with sizes="auto" and loading="lazy". Core never filters that | |
| 205 | + * markup, so a footer popup ships its images at full size. | |
| 206 | + * | |
| 207 | + * @param bool $enabled Default true while lazy-loading images is on. | |
| 208 | + */ | |
| 209 | + if ( ! empty( $opts['lazy_images'] ) && apply_filters( 'xspeed_lazy_footer_images', true ) ) { | |
| 210 | + add_action( 'template_redirect', array( \XSpeed\Footer_Images::class, 'reset_state' ) ); | |
| 211 | + add_action( 'get_footer', array( \XSpeed\Footer_Images::class, 'start' ), PHP_INT_MAX, 0 ); | |
| 212 | + add_action( 'wp_footer', array( \XSpeed\Footer_Images::class, 'start' ), PHP_INT_MIN, 0 ); | |
| 213 | + add_action( 'wp_footer', array( \XSpeed\Footer_Images::class, 'finish' ), PHP_INT_MAX, 0 ); | |
| 214 | + } | |
| 215 | + | |
| 195 | 216 | // The facade's click handler is printed only on pages that actually |
| 196 | 217 | // rendered a facade — a page with no embeds should not carry the |
| 197 | 218 | // script that reveals them. |
| 198 | 219 | if ( ! empty( $opts['video_facade'] ) ) { |
| @@ -317,9 +338,12 @@ | ||
| 317 | 338 | * video, and the script installs observers only — it does no work |
| 318 | 339 | * and touches nothing when it finds no autoplay video. That is a |
| 319 | 340 | * better trade than missing the one case the feature exists for. |
| 320 | 341 | */ |
| 321 | - wp_print_inline_script_tag( Lazy_Loader::autoplay_script(), array( 'id' => 'xspeed-lazy-autoplay' ) ); | |
| 342 | + $settings = $this->get_settings(); | |
| 343 | + $after_load = ! empty( $settings['video_after_load'] ); | |
| 344 | + $excluded = is_array( $settings['excluded_images'] ?? null ) ? $settings['excluded_images'] : array(); | |
| 345 | + wp_print_inline_script_tag( Lazy_Loader::autoplay_script( $after_load, $excluded ), array( 'id' => 'xspeed-lazy-autoplay' ) ); | |
| 322 | 346 | } |
| 323 | 347 | |
| 324 | 348 | public function cli_commands(): array { |
| 325 | 349 | return array( |