| 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 |
* Checks if current page is in Page Builder edit mode. |
| 54 |
* |
| 55 |
* @return bool |
| 56 |
*/ |
| 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 |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Disables altering HTML for WebP when current page is in edit mode. |
| 63 |
*/ |
| 64 |
private function disable_webp_alter_html_in_edit_mode() { |
| 65 |
if ($this->is_edit_mode()) { |
| 66 |
add_filter('wpo_disable_webp_alter_html', '__return_true'); |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
|