PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
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
← All changes | compatibility/class-wpo-page-builder-compatibility.php +37 -8 4.5.4 → 4.7.0 View file →
@@ -8,13 +8,35 @@
8 8 */
9 9 class WPO_Page_Builder_Compatibility {
10 10
11 11 /**
12 + * Query string parameters used by supported page builders to signal edit mode.
13 + *
14 + * - fl_builder: Beaver Builder
15 + * - et_fb: Divi Theme Builder
16 + * - ct_builder: Oxygen Builder
17 + * - elementor-preview: Elementor
18 + * - oxygen: Oxygen (alternative trigger)
19 + */
20 + const EDIT_MODE_QUERY_PARAMS = array(
21 + 'fl_builder',
22 + 'et_fb',
23 + 'ct_builder',
24 + 'elementor-preview',
25 + 'oxygen',
26 + );
27 +
28 + /**
29 + * Path fragment that identifies Divi cached assets.
30 + */
31 + const DIVI_CACHE_PATH_FRAGMENT = 'et-cache';
32 +
33 + /**
12 34 * Constructor.
13 35 */
14 36 private function __construct() {
15 37 $this->disable_webp_alter_html_in_edit_mode();
16 -
38 +
17 39 add_filter('wpo_minify_file_modification_time', array($this, 'use_file_hash_for_divi_assets'), 10, 2);
18 40 }
19 41
20 42 /**
@@ -31,9 +53,9 @@
31 53 return $instance;
32 54 }
33 55
34 56 /**
35 - * Replaces the modification time of Divi assets with the file hash for WPO Minify
57 + * Replaces the modification time of Divi assets with the file hash for WPO Minify.
36 58 *
37 59 * @param string $modification_time The original modification time.
38 60 * @param string $file_path The absolute path to the file.
39 61 * @return string
@@ -38,9 +60,9 @@
38 60 * @param string $file_path The absolute path to the file.
39 61 * @return string
40 62 */
41 63 public function use_file_hash_for_divi_assets($modification_time, $file_path) {
42 - if (false !== strpos($file_path, 'et-cache')) {
64 + if (false !== strpos($file_path, self::DIVI_CACHE_PATH_FRAGMENT)) {
43 65 $hash = hash_file('adler32', $file_path);
44 66 if ($hash) {
45 67 return $hash . '-h';
46 68 }
@@ -49,21 +71,28 @@
49 71 return $modification_time;
50 72 }
51 73
52 74 /**
53 - * Checks if current page is in Page Builder edit mode.
75 + * Determines whether the current page is being viewed inside a page builder's
76 + * edit/preview mode (e.g. Beaver Builder, Divi, Elementor, Oxygen Builder).
54 77 *
55 78 * @return bool
56 79 */
57 - public function is_edit_mode() {
58 - return isset($_GET['fl_builder']) || isset($_GET['et_fb']) || isset($_GET['ct_builder']); // phpcs:ignore WordPress.Security.NonceVerification -- We are not using $_GET value, just checking its existence
80 + public static function is_edit_mode(): bool {
81 + foreach (self::EDIT_MODE_QUERY_PARAMS as $param) {
82 + if (isset($_GET[$param])) { // phpcs:ignore WordPress.Security.NonceVerification -- Only checking for key existence, not using values.
83 + return true;
84 + }
85 + }
86 +
87 + return false;
59 88 }
60 89
61 90 /**
62 91 * Disables altering HTML for WebP when current page is in edit mode.
63 92 */
64 - private function disable_webp_alter_html_in_edit_mode() {
65 - if ($this->is_edit_mode()) {
93 + private function disable_webp_alter_html_in_edit_mode(): void {
94 + if (self::is_edit_mode()) {
66 95 add_filter('wpo_disable_webp_alter_html', '__return_true');
67 96 }
68 97 }
69 98 }