Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
LazyLoadingHealthCheck
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 test
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace NewfoldLabs\WP\Module\Performance\HealthChecks;
4
5/**
6 * Health check for lazy loading.
7 */
8class LazyLoadingHealthCheck extends HealthCheck {
9    /**
10     * Constructor.
11     */
12    public function __construct() {
13        $this->id           = 'newfold-lazy-loading';
14        $this->title        = esc_html__( 'Lazy Loading', 'wp-module-performance' );
15        $this->passing_text = esc_html__( 'Lazy loading is enabled', 'wp-module-performance' );
16        $this->failing_text = esc_html__( 'Lazy loading is disabled', 'wp-module-performance' );
17        $this->description  = esc_html__( 'Lazy loading can improve performance by only loading images when they are in view.', 'wp-module-performance' );
18    }
19
20    /**
21     * Test if lazy loading is enabled.
22     *
23     * @return bool
24     */
25    public function test() {
26        $image_optimization = get_option( 'nfd_image_optimization', array() );
27        return isset( $image_optimization['lazy_loading'], $image_optimization['lazy_loading']['enabled'] ) && $image_optimization['lazy_loading']['enabled'];
28    }
29}