Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/wp-rocket/inc/Engine/Saas/Admin/Notices.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
declare(strict_types=1);
3
+
4
+
namespace WP_Rocket\Engine\Saas\Admin;
5
+
6
+
use WP_Rocket\Admin\Options_Data;
7
+
use WP_Rocket\Engine\Admin\Beacon\Beacon;
8
+
use WP_Rocket\Engine\Common\Context\ContextInterface;
9
+
10
+
class Notices {
11
+
/**
12
+
* Options Data instance
13
+
*
14
+
* @var Options_Data
15
+
*/
16
+
private $options;
17
+
18
+
/**
19
+
* Beacon instance.
20
+
*
21
+
* @var Beacon
22
+
*/
23
+
private $beacon;
24
+
25
+
/**
26
+
* Constructor
27
+
*
28
+
* @param Options_Data $options Options_Data instance.
29
+
* @param Beacon $beacon Beacon instance.
30
+
*/
31
+
public function __construct( Options_Data $options, Beacon $beacon ) {
32
+
$this->options = $options;
33
+
$this->beacon = $beacon;
34
+
}
35
+
36
+
/**
37
+
* Show admin notice after clearing SaaS tables.
38
+
*
39
+
* @return void
40
+
*/
41
+
public function clean_saas_result() {
42
+
if ( ! current_user_can( 'rocket_manage_options' ) ) {
43
+
return;
44
+
}
45
+
46
+
if ( ! $this->options->get( 'remove_unused_css', 0 ) ) {
47
+
return;
48
+
}
49
+
50
+
$response = get_transient( 'rocket_saas_clean_message' );
51
+
52
+
if ( ! $response ) {
53
+
return;
54
+
}
55
+
56
+
delete_transient( 'rocket_saas_clean_message' );
57
+
58
+
rocket_notice_html( $response );
59
+
}
60
+
61
+
/**
62
+
* Displays the SaaS currently processing notice
63
+
*
64
+
* @return void
65
+
*/
66
+
public function display_processing_notice() {
67
+
if ( $this->has_saas_error_notice() ) {
68
+
return;
69
+
}
70
+
71
+
if ( ! $this->can_display_notice() ) {
72
+
return;
73
+
}
74
+
75
+
$transient = get_transient( 'rocket_saas_processing' );
76
+
77
+
if ( false === $transient ) {
78
+
return;
79
+
}
80
+
81
+
$current_time = time();
82
+
83
+
if ( $transient < $current_time ) {
84
+
return;
85
+
}
86
+
87
+
$remaining = $transient - $current_time;
88
+
89
+
$message = sprintf(
90
+
// translators: %1$s = plugin name, %2$s = number of seconds.
91
+
__( '%1$s: Please wait %2$s seconds. The Remove Unused CSS service is processing your pages, the plugin is optimizing LCP and the images above the fold.', 'rocket' ),
92
+
'<strong>WP Rocket</strong>',
93
+
'<span id="rocket-rucss-timer">' . $remaining . '</span>'
94
+
);
95
+
96
+
rocket_notice_html(
97
+
[
98
+
'status' => 'info',
99
+
'message' => $message,
100
+
'id' => 'rocket-notice-saas-processing',
101
+
]
102
+
);
103
+
}
104
+
105
+
/**
106
+
* Displays the SaaS success notice
107
+
*
108
+
* @return void
109
+
*/
110
+
public function display_success_notice() {
111
+
if ( ! $this->can_display_notice() ) {
112
+
return;
113
+
}
114
+
115
+
if ( $this->has_saas_error_notice() ) {
116
+
return;
117
+
}
118
+
119
+
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
120
+
121
+
if ( in_array( 'saas_success_notice', (array) $boxes, true ) ) {
122
+
return;
123
+
}
124
+
125
+
$transient = get_transient( 'rocket_saas_processing' );
126
+
$class = '';
127
+
128
+
if ( false !== $transient || ( ! $this->options->get( 'remove_unused_css', 0 ) ) ) {
129
+
$class = 'hidden';
130
+
}
131
+
132
+
$message = sprintf(
133
+
// translators: %1$s = plugin name, %2$s = number of URLs, %3$s = number of seconds.
134
+
__(
135
+
'%1$s: The LCP element has been optimized, and the images above the fold were excluded from lazyload. The Used CSS of your homepage has been processed.
136
+
WP Rocket will continue to generate Used CSS for up to %2$s URLs per %3$s second(s).',
137
+
'rocket'
138
+
),
139
+
'<strong>WP Rocket</strong>',
140
+
rocket_apply_filter_and_deprecated(
141
+
'rocket_saas_pending_jobs_cron_rows_count',
142
+
[ 100 ],
143
+
'3.16',
144
+
'rocket_rucss_pending_jobs_cron_rows_count'
145
+
),
146
+
rocket_apply_filter_and_deprecated(
147
+
'rocket_saas_pending_jobs_cron_interval',
148
+
[ MINUTE_IN_SECONDS ],
149
+
'3.16',
150
+
'rocket_rucss_pending_jobs_cron_interval'
151
+
)
152
+
);
153
+
154
+
if ( ! $this->options->get( 'manual_preload', 0 ) ) {
155
+
$message .= ' ' . sprintf(
156
+
// translators: %1$s = opening link tag, %2$s = closing link tag.
157
+
__( 'We suggest enabling %1$sPreload%2$s for the fastest results.', 'rocket' ),
158
+
'<a href="#preload">',
159
+
'</a>'
160
+
);
161
+
}
162
+
163
+
$beacon = $this->beacon->get_suggest( 'async_opti' );
164
+
165
+
$message .= '<br>' . sprintf(
166
+
// translators: %1$s = opening link tag, %2$s = closing link tag.
167
+
__( 'To learn more about the process check our %1$sdocumentation%2$s.', 'rocket' ),
168
+
'<a href="' . esc_url( $beacon['url'] ) . '" data-beacon-article="' . esc_attr( $beacon['id'] ) . '" rel="noopener noreferrer" target="_blank">',
169
+
'</a>'
170
+
);
171
+
172
+
rocket_notice_html(
173
+
[
174
+
'message' => $message,
175
+
'dismissible' => $class,
176
+
'id' => 'rocket-notice-saas-success',
177
+
'dismiss_button' => 'saas_success_notice',
178
+
'dismiss_button_class' => 'button-primary',
179
+
]
180
+
);
181
+
}
182
+
183
+
/**
184
+
* Adds the notice end time to WP Rocket localize script data
185
+
*
186
+
* @since 3.11
187
+
*
188
+
* @param array $data Localize script data.
189
+
*
190
+
* @return array
191
+
*/
192
+
public function add_localize_script_data( array $data ): array {
193
+
if ( ! $this->options->get( 'remove_unused_css', 0 ) ) {
194
+
return $data;
195
+
}
196
+
197
+
$transient = get_transient( 'rocket_saas_processing' );
198
+
199
+
if ( false === $transient ) {
200
+
return $data;
201
+
}
202
+
203
+
$data['notice_end_time'] = $transient;
204
+
$data['cron_disabled'] = rocket_get_constant( 'DISABLE_WP_CRON', false );
205
+
206
+
return $data;
207
+
}
208
+
209
+
/**
210
+
* Display a notification on wrong license.
211
+
*
212
+
* @return void
213
+
*/
214
+
public function display_wrong_license_notice() {
215
+
$transient = get_option( 'wp_rocket_no_licence' );
216
+
217
+
if ( ! $transient ) {
218
+
return;
219
+
}
220
+
221
+
if ( ! $this->can_display_notice() ) {
222
+
return;
223
+
}
224
+
225
+
$main_message = __( "We couldn't generate the used CSS because you're using a nulled version of WP Rocket. You need an active license to use the Remove Unused CSS feature and further improve your website's performance.", 'rocket' );
226
+
$cta_message = sprintf(
227
+
// translators: %1$s = promo percentage.
228
+
__( 'Click here to get a WP Rocket single license at %1$s off!', 'rocket' ),
229
+
'10%%'
230
+
);
231
+
232
+
$message = sprintf(
233
+
// translators: %1$s = plugin name, %2$s = opening anchor tag, %3$s = closing anchor tag.
234
+
"%1\$s: <p>$main_message</p>%2\$s$cta_message%3\$s",
235
+
'<strong>WP Rocket</strong>',
236
+
'<a href="https://wp-rocket.me/?add-to-cart=191&coupon_code=iamnotapirate10" class="button button-primary" rel="noopener noreferrer" target="_blank">',
237
+
'</a>'
238
+
);
239
+
240
+
rocket_notice_html(
241
+
[
242
+
'status' => 'error',
243
+
'dismissible' => '',
244
+
'message' => $message,
245
+
'id' => 'rocket-notice-rucss-wrong-licence',
246
+
]
247
+
);
248
+
}
249
+
250
+
/**
251
+
* Display an error notice when the connection to the server fails
252
+
*
253
+
* @return void
254
+
*/
255
+
public function display_saas_error_notice() {
256
+
257
+
if ( ! $this->has_saas_error_notice() ) {
258
+
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
259
+
if ( in_array( 'rucss_saas_error_notice', (array) $boxes, true ) ) {
260
+
unset( $boxes['rucss_saas_error_notice'] );
261
+
update_user_meta( get_current_user_id(), 'rocket_boxes', $boxes );
262
+
}
263
+
264
+
return;
265
+
}
266
+
267
+
if ( ! $this->can_display_notice() ) {
268
+
return;
269
+
}
270
+
271
+
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
272
+
273
+
if ( in_array( 'saas_error_notice', (array) $boxes, true ) ) {
274
+
return;
275
+
}
276
+
277
+
$firewall_beacon = $this->beacon->get_suggest( 'rucss_firewall_ips' );
278
+
279
+
$main_message = sprintf(
280
+
// translators: %1$s = <a> open tag, %2$s = </a> closing tag.
281
+
__( 'It seems a security plugin or the server\'s firewall prevents WP Rocket from accessing the SaaS features. IPs listed %1$shere in our documentation%2$s should be added to your allowlists:', 'rocket' ),
282
+
'<a href="' . esc_url( $firewall_beacon['url'] ) . '" data-beacon-article="' . esc_attr( $firewall_beacon['id'] ) . '" rel="noopener noreferrer" target="_blank">',
283
+
'</a>'
284
+
);
285
+
286
+
$security_message = __( '- In the security plugin, if you are using one', 'rocket' );
287
+
$firewall_message = __( "- In the server's firewall. Your host can help you with this", 'rocket' );
288
+
289
+
$message = "<strong>WP Rocket</strong>: $main_message<ul><li>$security_message</li><li>$firewall_message</li></ul>";
290
+
291
+
rocket_notice_html(
292
+
[
293
+
'status' => 'error',
294
+
'message' => $message,
295
+
'dismissible' => '',
296
+
'id' => 'rocket-notice-rucss-error-http',
297
+
'dismiss_button' => 'saas_error_notice',
298
+
'dismiss_button_class' => 'button-primary',
299
+
]
300
+
);
301
+
}
302
+
303
+
/**
304
+
* Checks if we can display the SaaS notices
305
+
*
306
+
* @return bool
307
+
*/
308
+
private function can_display_notice(): bool {
309
+
$screen = get_current_screen();
310
+
311
+
if (
312
+
isset( $screen->id )
313
+
&&
314
+
'settings_page_wprocket' !== $screen->id
315
+
) {
316
+
return false;
317
+
}
318
+
319
+
if ( ! current_user_can( 'rocket_manage_options' ) ) {
320
+
return false;
321
+
}
322
+
323
+
return true;
324
+
}
325
+
326
+
/**
327
+
* Is the error notice present.
328
+
*
329
+
* @return bool
330
+
*/
331
+
private function has_saas_error_notice() {
332
+
return (bool) get_transient( 'wp_rocket_rucss_errors_count' );
333
+
}
334
+
}
335
+