← All changes
|
modules/image-loading-optimization/module.php
+8
-21
4.1.0-dev3
→
3.21.0-beta2
View file →
| @@ -1,11 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor\Modules\ImageLoadingOptimization; |
| 3 | 3 | |
| 4 | 4 | use Elementor\Core\Base\Module as BaseModule; |
| 5 | +use Elementor\Core\Experiments\Manager as Experiments_Manager; | |
| 5 | 6 | |
| 6 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | - exit; // Exit if accessed directly. | |
| 8 | + exit; // Exit if accessed directly | |
| 8 | 9 | } |
| 9 | 10 | |
| 10 | 11 | class Module extends BaseModule { |
| 11 | 12 | /** |
| @@ -33,12 +34,8 @@ | ||
| 33 | 34 | /** |
| 34 | 35 | * Constructor. |
| 35 | 36 | */ |
| 36 | 37 | public function __construct() { |
| 37 | - if ( ! static::is_optimized_image_loading_enabled() ) { | |
| 38 | - return; | |
| 39 | - } | |
| 40 | - | |
| 41 | 38 | parent::__construct(); |
| 42 | 39 | |
| 43 | 40 | // Stop wp core logic. |
| 44 | 41 | add_action( 'init', [ $this, 'stop_core_fetchpriority_high_logic' ] ); |
| @@ -54,24 +51,15 @@ | ||
| 54 | 51 | add_filter( 'wp_content_img_tag', [ $this, 'loading_optimization_image' ] ); |
| 55 | 52 | } |
| 56 | 53 | |
| 57 | 54 | /** |
| 58 | - * Check whether the "Optimized Image Loading" settings is enabled. | |
| 59 | - * | |
| 60 | - * The 'optimized_image_loading' option can be enabled/disabled from the Elementor settings. | |
| 61 | - * | |
| 62 | - * @since 3.21.0 | |
| 63 | - * @access private | |
| 64 | - */ | |
| 65 | - private static function is_optimized_image_loading_enabled(): bool { | |
| 66 | - return '1' === get_option( 'elementor_optimized_image_loading', '1' ); | |
| 67 | - } | |
| 68 | - | |
| 69 | - /** | |
| 70 | 55 | * Stop WordPress core fetchpriority logic by setting the wp_high_priority_element_flag flag to false. |
| 71 | 56 | */ |
| 72 | 57 | public function stop_core_fetchpriority_high_logic() { |
| 73 | - wp_high_priority_element_flag( false ); | |
| 58 | + // wp_high_priority_element_flag was only introduced in 6.3.0 | |
| 59 | + if ( function_exists( 'wp_high_priority_element_flag' ) ) { | |
| 60 | + wp_high_priority_element_flag( false ); | |
| 61 | + } | |
| 74 | 62 | } |
| 75 | 63 | |
| 76 | 64 | /** |
| 77 | 65 | * Set buffer to handle header and footer content. |
| @@ -239,9 +227,8 @@ | ||
| 239 | 227 | __FUNCTION__, |
| 240 | 228 | esc_html__( 'An image should not be lazy-loaded and marked as high priority at the same time.', 'elementor' ), |
| 241 | 229 | '' |
| 242 | 230 | ); |
| 243 | - | |
| 244 | 231 | /* |
| 245 | 232 | * Set `fetchpriority` here for backward-compatibility as we should |
| 246 | 233 | * not override what a developer decided, even though it seems |
| 247 | 234 | * incorrect. |
| @@ -312,10 +299,10 @@ | ||
| 312 | 299 | |
| 313 | 300 | /** |
| 314 | 301 | * Determines whether to add `fetchpriority='high'` to loading attributes. |
| 315 | 302 | * |
| 316 | - * @param array $loading_attrs Array of the loading optimization attributes for the element. | |
| 317 | - * @param array $attr Array of the attributes for the element. | |
| 303 | + * @param array $loading_attrs Array of the loading optimization attributes for the element. | |
| 304 | + * @param array $attr Array of the attributes for the element. | |
| 318 | 305 | * @return array Updated loading optimization attributes for the element. |
| 319 | 306 | */ |
| 320 | 307 | private function maybe_add_fetchpriority_high_attr( $loading_attrs, $attr ) { |
| 321 | 308 | if ( isset( $attr['fetchpriority'] ) ) { |