Skip to content

Commit 4d70ad0

Browse files
committed
Rename previous lazy-load code now to be for video specifically
1 parent 2b75add commit 4d70ad0

File tree

4 files changed

+16
-28
lines changed

4 files changed

+16
-28
lines changed

plugins/image-prioritizer/class-image-prioritizer-video-tag-visitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ private function lazy_load_videos( ?string $poster, OD_Tag_Visitor_Context $cont
241241
}
242242

243243
if ( ! $this->added_lazy_script ) {
244-
$processor->append_body_html( wp_get_inline_script_tag( image_prioritizer_get_lazy_load_script(), array( 'type' => 'module' ) ) );
244+
$processor->append_body_html( wp_get_inline_script_tag( image_prioritizer_get_video_lazy_load_script(), array( 'type' => 'module' ) ) );
245245
$this->added_lazy_script = true;
246246
}
247247
}

plugins/image-prioritizer/helper.php

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,12 @@ function image_prioritizer_get_asset_path( string $src_path, ?string $min_path =
121121
* Handles 'autoplay' and 'preload' attributes accordingly.
122122
*
123123
* @since 0.2.0
124+
*
125+
* @return string Lazy load script.
124126
*/
125-
function image_prioritizer_get_lazy_load_script(): string {
126-
$path = image_prioritizer_get_asset_path( 'lazy-load.js' );
127-
$script = file_get_contents( __DIR__ . '/' . $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- It's a local filesystem path not a remote request.
128-
129-
if ( false === $script ) {
130-
return '';
131-
}
132-
133-
return $script;
127+
function image_prioritizer_get_video_lazy_load_script(): string {
128+
$path = image_prioritizer_get_asset_path( 'lazy-load-video.js' );
129+
return (string) file_get_contents( __DIR__ . '/' . $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- It's a local filesystem path not a remote request.
134130
}
135131

136132
/**
@@ -139,30 +135,22 @@ function image_prioritizer_get_lazy_load_script(): string {
139135
* Load the background image when it approaches the viewport using an IntersectionObserver.
140136
*
141137
* @since n.e.x.t
138+
*
139+
* @return string Lazy load script.
142140
*/
143141
function image_prioritizer_get_lazy_load_bg_image_script(): string {
144-
$path = image_prioritizer_get_asset_path( 'lazy-load-bg-image.js' );
145-
$script = file_get_contents( __DIR__ . '/' . $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- It's a local filesystem path not a remote request.
146-
147-
if ( false === $script ) {
148-
return '';
149-
}
150-
151-
return $script;
142+
$path = image_prioritizer_get_asset_path( 'lazy-load-bg-image.js' );
143+
return (string) file_get_contents( __DIR__ . '/' . $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- It's a local filesystem path not a remote request.
152144
}
153145

154146
/**
155147
* Gets the stylesheet to lazy-load background images.
156148
*
157149
* @since n.e.x.t
150+
*
151+
* @return string Lazy load stylesheet.
158152
*/
159153
function image_prioritizer_get_lazy_load_bg_image_stylesheet(): string {
160-
$path = image_prioritizer_get_asset_path( 'lazy-load-bg-image.css' );
161-
$stylesheet = file_get_contents( __DIR__ . '/' . $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- It's a local filesystem path not a remote request.
162-
163-
if ( false === $stylesheet ) {
164-
return '';
165-
}
166-
167-
return $stylesheet;
154+
$path = image_prioritizer_get_asset_path( 'lazy-load-bg-image.css' );
155+
return (string) file_get_contents( __DIR__ . '/' . $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- It's a local filesystem path not a remote request.
168156
}

webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ const imagePrioritizer = ( env ) => {
133133
new CopyWebpackPlugin( {
134134
patterns: [
135135
{
136-
from: `${ pluginDir }/lazy-load.js`,
137-
to: `${ pluginDir }/lazy-load.min.js`,
136+
from: `${ pluginDir }/lazy-load-video.js`,
137+
to: `${ pluginDir }/lazy-load-video.min.js`,
138138
},
139139
{
140140
from: `${ pluginDir }/lazy-load-bg-image.js`,

0 commit comments

Comments
 (0)