Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/wp-rocket/inc/ThirdParty/Themes/Themify.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
namespace WP_Rocket\ThirdParty\Themes;
3
+
4
+
use WP_Rocket\Admin\Options_Data;
5
+
use WP_Rocket\Event_Management\Subscriber_Interface;
6
+
7
+
class Themify implements Subscriber_Interface {
8
+
/**
9
+
* WP Rocket options instance.
10
+
*
11
+
* @var Options_Data
12
+
*/
13
+
private $options;
14
+
15
+
/**
16
+
* Instantiate the class.
17
+
*
18
+
* @param Options_Data $options WP Rocket options instance.
19
+
*/
20
+
public function __construct( Options_Data $options ) {
21
+
$this->options = $options;
22
+
}
23
+
24
+
/**
25
+
* Returns an array of events that this subscriber wants to listen to.
26
+
*
27
+
* @return array
28
+
*/
29
+
public static function get_subscribed_events() {
30
+
return [
31
+
'after_switch_theme' => 'disabling_concat_on_theme',
32
+
'update_option_' . rocket_get_constant( 'WP_ROCKET_SLUG', 'wp_rocket_settings' ) => [ 'disabling_concat_on_rucss', 10, 2 ],
33
+
'themify_save_data' => 'disable_concat_on_saving_data',
34
+
'themify_dev_mode' => 'maybe_enable_dev_mode',
35
+
];
36
+
}
37
+
38
+
/**
39
+
* Change the value on change theme.
40
+
*
41
+
* @return void
42
+
*/
43
+
public function disabling_concat_on_theme() {
44
+
// @phpstan-ignore-next-line
45
+
$data = themify_get_data();
46
+
47
+
$remove_unused_css = $this->options->get( 'remove_unused_css', false );
48
+
49
+
if ( ! $remove_unused_css ) {
50
+
$data = $this->maybe_disable( $data );
51
+
}
52
+
53
+
if ( $remove_unused_css ) {
54
+
$data = $this->maybe_enable( $data );
55
+
}
56
+
57
+
// @phpstan-ignore-next-line
58
+
themify_set_data( $data );
59
+
}
60
+
61
+
/**
62
+
* Disable concat on saving theme options.
63
+
*
64
+
* @param array $value theme options.
65
+
* @return array
66
+
*/
67
+
public function disable_concat_on_saving_data( $value ) {
68
+
if ( ! $this->options->get( 'remove_unused_css', false ) ) {
69
+
return $value;
70
+
}
71
+
72
+
return $this->maybe_enable( $value );
73
+
}
74
+
75
+
/**
76
+
* Disable concat on RUCSS enabled.
77
+
*
78
+
* @param array $old Old configurations.
79
+
* @param array $new New configurations.
80
+
*
81
+
* @return void
82
+
*/
83
+
public function disabling_concat_on_rucss( $old, $new ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.newFound
84
+
85
+
if ( ! key_exists( 'remove_unused_css', $old ) || ! key_exists( 'remove_unused_css', $new ) || $old['remove_unused_css'] === $new['remove_unused_css'] ) {
86
+
return;
87
+
}
88
+
89
+
// @phpstan-ignore-next-line
90
+
$data = themify_get_data();
91
+
92
+
if ( ! $new['remove_unused_css'] ) {
93
+
$data = $this->maybe_disable( $data );
94
+
}
95
+
96
+
if ( $new['remove_unused_css'] ) {
97
+
$data = $this->maybe_enable( $data );
98
+
}
99
+
100
+
// @phpstan-ignore-next-line
101
+
themify_set_data( $data );
102
+
}
103
+
104
+
/**
105
+
* Maybe disable concate CSS.
106
+
*
107
+
* @param array $data Themify data.
108
+
*
109
+
* @return array
110
+
*/
111
+
protected function maybe_disable( array $data ): array {
112
+
if ( key_exists( 'setting-dev-mode-concate', $data ) && ! $data['setting-dev-mode-concate'] && key_exists( 'setting-dev-mode', $data ) && ! $data['setting-dev-mode'] ) {
113
+
return $data;
114
+
}
115
+
116
+
$data['setting-dev-mode-concate'] = false;
117
+
$data['setting-dev-mode'] = false;
118
+
119
+
return $data;
120
+
}
121
+
122
+
/**
123
+
* Maybe enable dev mode and concat.
124
+
*
125
+
* @param array $data Themify data.
126
+
*
127
+
* @return array
128
+
*/
129
+
protected function maybe_enable( array $data ): array {
130
+
131
+
if ( key_exists( 'setting-dev-mode-concate', $data ) && $data['setting-dev-mode-concate'] && key_exists( 'setting-dev-mode', $data ) && $data['setting-dev-mode'] ) {
132
+
return $data;
133
+
}
134
+
135
+
$data['setting-dev-mode'] = true;
136
+
$data['setting-dev-mode-concate'] = true;
137
+
138
+
return $data;
139
+
}
140
+
141
+
/**
142
+
* Enable the dev mode when RUCSS is activated.
143
+
*
144
+
* @param bool $is_enabled Is dev mode enabled.
145
+
* @return bool
146
+
*/
147
+
public function maybe_enable_dev_mode( $is_enabled ) {
148
+
149
+
if ( $this->options->get( 'remove_unused_css', false ) ) {
150
+
return true;
151
+
}
152
+
153
+
return $is_enabled;
154
+
}
155
+
}
156
+