PluginProbe
Elementor Website Builder – more than just a page builder / 3.23.0-dev3
Elementor Website Builder – more than just a page builder v3.23.0-dev3
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
← All changes | modules/lazyload/module.php +20 -13 4.0.93.23.0-dev3 View file →
@@ -1,20 +1,35 @@
1 1 <?php
2 2 namespace Elementor\Modules\LazyLoad;
3 3
4 4 use Elementor\Core\Base\Module as BaseModule;
5 +use Elementor\Core\Experiments\Manager as Experiments_Manager;
5 6 use Elementor\Plugin;
6 7
7 8 if ( ! defined( 'ABSPATH' ) ) {
8 - exit; // Exit if accessed directly.
9 + exit; // Exit if accessed directly
9 10 }
10 11
11 12 class Module extends BaseModule {
12 13
14 + const EXPERIMENT_NAME = 'e_lazyload';
15 +
13 16 public function get_name() {
14 17 return 'lazyload';
15 18 }
16 19
20 + public static function get_experimental_data() {
21 + return [
22 + 'name' => static::EXPERIMENT_NAME,
23 + 'title' => esc_html__( 'Lazy Load Background Images', 'elementor' ),
24 + 'tag' => esc_html__( 'Performance', 'elementor' ),
25 + 'description' => esc_html__( 'Lazy loading images that are not in the viewport improves initial page load performance and user experience. By activating this experiment all background images except the first one on your page will be lazy loaded to improve your LCP score', 'elementor' ),
26 + 'release_status' => Experiments_Manager::RELEASE_STATUS_STABLE,
27 + 'default' => Experiments_Manager::STATE_ACTIVE,
28 + 'generator_tag' => true,
29 + ];
30 + }
31 +
17 32 public function __construct() {
18 33 parent::__construct();
19 34
20 35 add_action( 'init', [ $this, 'init' ] );
@@ -20,14 +35,10 @@
20 35 add_action( 'init', [ $this, 'init' ] );
21 36 }
22 37
23 38 public function init() {
24 - if ( ! $this->is_lazy_load_background_images_enabled() ) {
25 - return;
26 - }
27 -
28 39 add_action( 'wp_head', function() {
29 - if ( ! $this->should_lazy_load_background_images() ) {
40 + if ( ! $this->should_lazyload() ) {
30 41 return;
31 42 }
32 43 ?>
33 44 <style>
@@ -51,13 +62,13 @@
51 62 <?php
52 63 } );
53 64
54 65 add_action( 'wp_footer', function() {
55 - if ( ! $this->should_lazy_load_background_images() ) {
66 + if ( ! $this->should_lazyload() ) {
56 67 return;
57 68 }
58 69 ?>
59 - <script>
70 + <script type='text/javascript'>
60 71 const lazyloadRunObserver = () => {
61 72 const lazyloadBackgrounds = document.querySelectorAll( `.e-con.e-parent:not(.e-lazyloaded)` );
62 73 const lazyloadBackgroundObserver = new IntersectionObserver( ( entries ) => {
63 74 entries.forEach( ( entry ) => {
@@ -85,12 +96,8 @@
85 96 <?php
86 97 } );
87 98 }
88 99
89 - private function should_lazy_load_background_images(): bool {
100 + private function should_lazyload() {
90 101 return ! is_admin() && ! Plugin::$instance->preview->is_preview_mode() && ! Plugin::$instance->editor->is_edit_mode();
91 - }
92 -
93 - private static function is_lazy_load_background_images_enabled(): bool {
94 - return '1' === get_option( 'elementor_lazy_load_background_images', '1' );
95 102 }
96 103 }