Skip to content

Commit 24754f4

Browse files
committed
refactor: update lazyload data availability checks and adjust skip setting
- Renamed method for checking data availability in PageProfiler for clarity. - Updated lazyload replacer and tag replacer to use the new method. - Adjusted the 'skip_lazyload_images' setting from 3 to 2 for improved functionality.
1 parent 13f5ebd commit 24754f4

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

inc/lazyload_replacer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ public function can_lazyload_for( $url, $tag = '' ) {
461461
$image_id = $this->get_id_by_url( $url );
462462
$is_in_all_viewports = Optml_Manager::instance()->page_profiler->is_in_all_viewports( $image_id );
463463
$is_lcp_image = Optml_Manager::instance()->page_profiler->is_lcp_image_in_all_viewports( $image_id );
464-
$no_viewport_data_available = ! Optml_Manager::instance()->page_profiler->check_data_availability();
464+
$no_viewport_data_available = ! Optml_Manager::instance()->page_profiler->is_data_available();
465465

466466
if ( OPTML_DEBUG ) {
467467
if ( $is_in_all_viewports ) {
@@ -531,7 +531,7 @@ public function get_svg_for( $width, $height, $url = null ) {
531531
list( $width, $height ) = $sizes;
532532
}
533533
// If the width is not found the url might be an offloaded attachment so we can get the width and height from the metadata.
534-
if ( ! is_numeric( $width ) ) {
534+
if ( ! is_numeric( $width ) && ! empty( $url ) ) {
535535
$attachment_id = $this->attachment_url_to_post_id( $url );
536536
$meta = wp_get_attachment_metadata( $attachment_id );
537537
$width = $meta['width'] ?? false;

inc/settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class Optml_Settings {
9393
'transfer_status' => 'disabled',
9494
'cloud_images' => 'enabled',
9595
'strip_metadata' => 'enabled',
96-
'skip_lazyload_images' => 3,
96+
'skip_lazyload_images' => 2,
9797
'defined_image_sizes' => [],
9898
'banner_frontend' => 'disabled',
9999
'offloading_status' => 'disabled',

inc/tag_replacer.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,8 @@ public function regular_tag_replace( $new_tag, $original_url, $new_url, $optml_a
433433

434434
if ( $this->settings->is_lazyload_type_viewport() ) {
435435
$image_id = $this->get_id_by_url( $original_url );
436-
$is_lcp_image = Optml_Manager::instance()->page_profiler->is_lcp_image_in_all_viewports( $image_id );
437-
$no_viewport_data_available = ! Optml_Manager::instance()->page_profiler->check_data_availability();
438-
436+
$is_lcp_image = Optml_Manager::instance()->page_profiler->is_lcp_image_in_all_viewports( $image_id );
437+
$no_viewport_data_available = ! Optml_Manager::instance()->page_profiler->is_data_available();
439438
if ( OPTML_DEBUG ) {
440439
do_action( 'optml_log', 'Adding fetchpriority image is LCP ' . $original_url . '|' . $image_id );
441440
}

inc/v2/PageProfiler/Profile.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,17 +452,14 @@ public static function get_active_devices(): array {
452452
*
453453
* @return bool
454454
*/
455-
public function check_data_availability(): bool {
456-
$has_data = false;
457-
455+
public function is_data_available(): bool {
458456
foreach ( self::get_active_devices() as $device ) {
459457
if ( empty( self::$current_profile_data[ $device ] ) ) {
460-
$has_data = true;
461-
break;
458+
return false;
462459
}
463460
}
464461

465-
return $has_data;
462+
return true;
466463
}
467464

468465
/**

0 commit comments

Comments
 (0)