PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.6.1
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.6.1
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / compatibility / class-wpo-page-builder-compatibility.php

class-wpo-page-builder-compatibility.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 4.6.1, at compatibility/class-wpo-page-builder-compatibility.php

71 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) {
3 die('No direct access allowed');
4 }
5
6 /**
7 * Adds compatibility for Page Builder plugins.
8 */
9 class WPO_Page_Builder_Compatibility {
10
11 /**
12 * Constructor.
13 */
14 private function __construct() {
15 $this->disable_webp_alter_html_in_edit_mode();
16
17 add_filter('wpo_minify_file_modification_time', array($this, 'use_file_hash_for_divi_assets'), 10, 2);
18 }
19
20 /**
21 * Returns singleton instance.
22 *
23 * @return self
24 */
25 public static function instance() {
26 static $instance = null;
27 if (null === $instance) {
28 $instance = new self();
29 }
30
31 return $instance;
32 }
33
34 /**
35 * Replaces the modification time of Divi assets with the file hash for WPO Minify
36 *
37 * @param string $modification_time The original modification time.
38 * @param string $file_path The absolute path to the file.
39 * @return string
40 */
41 public function use_file_hash_for_divi_assets($modification_time, $file_path) {
42 if (false !== strpos($file_path, 'et-cache')) {
43 $hash = hash_file('adler32', $file_path);
44 if ($hash) {
45 return $hash . '-h';
46 }
47 }
48
49 return $modification_time;
50 }
51
52 /**
53 * Determines whether the page is in edit mode using page builders
54 * Beaver Builder, Divi Theme, Elementor, and Oxygen Builder
55 *
56 * @return bool
57 */
58 public static function is_edit_mode(): bool {
59 return isset($_GET['fl_builder']) || isset($_GET['et_fb']) || isset($_GET['ct_builder']) || isset($_GET['elementor-preview']) || isset($_GET['oxygen']); // phpcs:ignore WordPress.Security.NonceVerification -- We are not using any global values, only checking for existence
60 }
61
62 /**
63 * Disables altering HTML for WebP when current page is in edit mode.
64 */
65 private function disable_webp_alter_html_in_edit_mode() {
66 if (self::is_edit_mode()) {
67 add_filter('wpo_disable_webp_alter_html', '__return_true');
68 }
69 }
70 }
71