Skip to content

Commit d9b3b66

Browse files
committed
Move image_prioritizer_get_lazy_load_script to helper.php
1 parent d02fc27 commit d9b3b66

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

plugins/image-prioritizer/helper.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@ function image_prioritizer_get_asset_path( string $src_path, ?string $min_path =
113113
return $min_path;
114114
}
115115

116+
/**
117+
* Gets the script to lazy-load videos.
118+
*
119+
* Load a video and its poster image when it approaches the viewport using an IntersectionObserver.
120+
*
121+
* Handles 'autoplay' and 'preload' attributes accordingly.
122+
*
123+
* @since 0.2.0
124+
*/
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;
134+
}
135+
116136
/**
117137
* Gets the script to lazy-load background images.
118138
*

plugins/image-prioritizer/hooks.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,3 @@
1111
}
1212

1313
add_action( 'od_init', 'image_prioritizer_init' );
14-
15-
/**
16-
* Gets the script to lazy-load videos.
17-
*
18-
* Load a video and its poster image when it approaches the viewport using an IntersectionObserver.
19-
*
20-
* Handles 'autoplay' and 'preload' attributes accordingly.
21-
*
22-
* @since 0.2.0
23-
*/
24-
function image_prioritizer_get_lazy_load_script(): string {
25-
$path = image_prioritizer_get_asset_path( 'lazy-load.js' );
26-
$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.
27-
28-
if ( false === $script ) {
29-
return '';
30-
}
31-
32-
return $script;
33-
}

0 commit comments

Comments
 (0)