-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass-divi.php
More file actions
75 lines (64 loc) · 2.29 KB
/
class-divi.php
File metadata and controls
75 lines (64 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace SLCA\Divi;
use wpCloud\StatelessMedia\Compatibility;
use wpCloud\StatelessMedia\Utility;
/**
* Class Divi
*/
class Divi extends Compatibility {
protected $id = 'divi';
protected $title = 'Divi';
protected $constant = 'WP_STATELESS_COMPATIBILITY_DIVI';
protected $description = 'Ensures compatibility with Divi theme.';
protected $theme_name = 'Divi';
/**
* Cache Busting call stack conditions to disable.
* Fixing the issue with multiple cache files being created on each page load.
* @see https://github.com/wpCloud/wp-stateless/issues/430
* @var array
*/
private $cache_busting_disable_conditions = array(
array('stack_level' => 7, 'function' => '__construct', 'class' => 'ET_Core_PageResource'),
array('stack_level' => 7, 'function' => 'get_cache_filename', 'class' => 'ET_Builder_Element')
);
/**
* Initialize compatibility module
* @param $sm
*/
public function module_init($sm) {
// exclude randomize_filename from export
add_action('admin_init', array($this, 'admin_init'), 5);
add_action('wp_ajax_et_core_portability_export', array($this, 'portability_ajax_export'), 5);
// maybe skip cache busting
add_filter('stateless_skip_cache_busting', array($this, 'maybe_skip_cache_busting'), 10, 2);
}
/**
* Disable Cache Busting when exporting Divi Options
*/
public function admin_init() {
if ( empty($_GET['et_core_portability']) ) {
return;
}
if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash ( $_GET['nonce'] ) ) , 'et_core_portability_export' ) ) {
return;
}
remove_filter('sanitize_file_name', array("wpCloud\StatelessMedia\Utility", 'randomize_filename'), 10);
}
/**
* Disable Cache Busting when exporting Divi Options
*/
public function portability_ajax_export() {
remove_filter('sanitize_file_name', array("wpCloud\StatelessMedia\Utility", 'randomize_filename'), 10);
}
/**
* Maybe skip cache busting
* @param $null
* @param $filename
* @return bool | string
*/
public function maybe_skip_cache_busting($null, $filename) {
$callstack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 8);
if (Utility::isCallStackMatches($callstack, $this->cache_busting_disable_conditions)) return $filename;
return $null;
}
}