/
notices.php
executable file
·852 lines (729 loc) · 29.4 KB
/
notices.php
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
<?php
defined( 'ABSPATH' ) || exit;
/**
* This warnings are displayed when the plugin can not be deactivated correctly
*
* @since 2.0.0
*/
function rocket_bad_deactivations() {
global $current_user;
$screen = get_current_screen();
if ( 'plugins' !== $screen->id ) {
return;
}
$msgs = get_transient( $current_user->ID . '_donotdeactivaterocket' );
if ( current_user_can( 'rocket_manage_options' ) && $msgs ) {
delete_transient( $current_user->ID . '_donotdeactivaterocket' );
$errors = [];
foreach ( $msgs as $msg ) {
switch ( $msg ) {
case 'wpconfig':
$errors['wpconfig'] = '<p>' . sprintf(
// translators: %1$s WP Rocket plugin name; %2$s = file name.
__(
'<strong>%1$s</strong> has not been deactivated due to missing writing permissions.<br>
Make <strong>%2$s</strong> writeable and retry deactivation, or force deactivation now:',
'rocket'
),
WP_ROCKET_PLUGIN_NAME,
'wp-config.php'
) . '</p>';
break;
case 'htaccess':
$errors['htaccess'] = '<p>' . sprintf(
// translators: %1$s WP Rocket plugin name; %2$s = file name.
__(
'<strong>%1$s</strong> has not been deactivated due to missing writing permissions.<br>
Make <strong>%2$s</strong> writeable and retry deactivation, or force deactivation now:',
'rocket'
),
WP_ROCKET_PLUGIN_NAME,
'.htaccess'
) . '</p>';
break;
}
/**
* Filter the output messages for each bad deactivation attempt.
*
* @since 2.0.0
*
* @param array $errors Contains the error messages to be filtered
* @param string $msg Contains the error type (wpconfig or htaccess)
*/
$errors = apply_filters( 'rocket_bad_deactivations', $errors, $msg );
}
rocket_notice_html(
[
'status' => 'error',
'dismissible' => '',
'message' => implode( '', $errors ),
'action' => 'force_deactivation',
]
);
}
}
add_action( 'admin_notices', 'rocket_bad_deactivations' );
/**
* This warning is displayed to inform the user that a plugin de/activation can be followed by a cache clear
*
* @since 1.3.0
*/
function rocket_warning_plugin_modification() {
if ( current_user_can( 'rocket_manage_options' ) && rocket_valid_key() ) {
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
return;
}
rocket_notice_html(
[
'status' => 'warning',
'dismissible' => '',
// translators: %s is WP Rocket plugin name.
'message' => sprintf( __( '<strong>%s</strong>: One or more plugins have been enabled or disabled, clear the cache if they affect the front end of your site.', 'rocket' ), WP_ROCKET_PLUGIN_NAME ),
'action' => 'clear_cache',
'dismiss_button' => __FUNCTION__,
]
);
}
}
add_action( 'admin_notices', 'rocket_warning_plugin_modification' );
/**
* This warning is displayed when some plugins may conflict with WP Rocket
*
* @since 1.3.0
*/
function rocket_plugins_to_deactivate() {
$plugins = [];
$plugins_explanations = [];
// Deactivate all plugins who can cause conflicts with WP Rocket.
$plugins = [
'w3-total-cache' => 'w3-total-cache/w3-total-cache.php',
'wp-super-cache' => 'wp-super-cache/wp-cache.php',
'litespeed-cache' => 'litespeed-cache/litespeed-cache.php',
'quick-cache' => 'quick-cache/quick-cache.php',
'hyper-cache' => 'hyper-cache/plugin.php',
'hyper-cache-extended' => 'hyper-cache-extended/plugin.php',
'wp-fast-cache' => 'wp-fast-cache/wp-fast-cache.php',
'flexicache' => 'flexicache/wp-plugin.php',
'wp-fastest-cache' => 'wp-fastest-cache/wpFastestCache.php',
'lite-cache' => 'lite-cache/plugin.php',
'gator-cache' => 'gator-cache/gator-cache.php',
'cache-enabler' => 'cache-enabler/cache-enabler.php',
'swift-performance-lite' => 'swift-performance-lite/performance.php',
'swift-performance' => 'swift-performance/performance.php',
'speed-booster-pack' => 'speed-booster-pack/speed-booster-pack.php',
'wp-http-compression' => 'wp-http-compression/wp-http-compression.php',
'wordpress-gzip-compression' => 'wordpress-gzip-compression/ezgz.php',
'gzip-ninja-speed-compression' => 'gzip-ninja-speed-compression/gzip-ninja-speed.php',
'wp-performance-score-booster' => 'wp-performance-score-booster/wp-performance-score-booster.php',
'remove-query-strings-from-static-resources' => 'remove-query-strings-from-static-resources/remove-query-strings.php',
'query-strings-remover' => 'query-strings-remover/query-strings-remover.php',
'wp-ffpc' => 'wp-ffpc/wp-ffpc.php',
'far-future-expiry-header' => 'far-future-expiry-header/far-future-expiration.php',
'combine-css' => 'combine-css/combine-css.php',
'super-static-cache' => 'super-static-cache/super-static-cache.php',
'wpcompressor' => 'wpcompressor/wpcompressor.php',
'check-and-enable-gzip-compression' => 'check-and-enable-gzip-compression/richards-toolbox.php',
'leverage-browser-caching-ninjas' => 'leverage-browser-caching-ninjas/leverage-browser-caching-ninja.php',
'force-gzip' => 'force-gzip/force-gzip.php',
'enable-gzip-compression' => 'enable-gzip-compression/enable-gzip-compression.php',
'leverage-browser-caching' => 'leverage-browser-caching/leverage-browser-caching.php',
'add-expires-headers' => 'add-expires-headers/add-expires-headers.php',
'page-optimize' => 'page-optimize/page-optimize.php',
'psn-pagespeed-ninja' => 'psn-pagespeed-ninja/pagespeedninja.php',
'wp-optimize' => 'wp-optimize/wp-optimize.php',
];
if ( get_rocket_option( 'lazyload' ) ) {
$plugins['bj-lazy-load'] = 'bj-lazy-load/bj-lazy-load.php';
$plugins['lazy-load'] = 'lazy-load/lazy-load.php';
$plugins['jquery-image-lazy-loading'] = 'jquery-image-lazy-loading/jq_img_lazy_load.php';
$plugins['advanced-lazy-load'] = 'advanced-lazy-load/advanced_lazyload.php';
$plugins['crazy-lazy'] = 'crazy-lazy/crazy-lazy.php';
$plugins['specify-image-dimensions'] = 'specify-image-dimensions/specify-image-dimensions.php';
}
if ( get_rocket_option( 'lazyload_iframes' ) ) {
$plugins['lazy-load-for-videos'] = 'lazy-load-for-videos/codeispoetry.php';
}
if ( get_rocket_option( 'minify_css' ) || get_rocket_option( 'minify_js' ) ) {
$plugins['wp-super-minify'] = 'wp-super-minify/wp-super-minify.php';
$plugins['bwp-minify'] = 'bwp-minify/bwp-minify.php';
$plugins['wp-minify'] = 'wp-minify/wp-minify.php';
$plugins['scripts-gzip'] = 'scripts-gzip/scripts_gzip.php';
$plugins['minqueue'] = 'minqueue/plugin.php';
$plugins['dependency-minification'] = 'dependency-minification/dependency-minification.php';
$plugins['fast-velocity-minify'] = 'fast-velocity-minify/fvm.php';
}
if ( get_rocket_option( 'minify_css' ) || get_rocket_option( 'minify_js' ) ) {
$plugins['async-js-and-css'] = 'async-js-and-css/asyncJSandCSS.php';
$plugins['merge-minify-refresh'] = 'merge-minify-refresh/merge-minify-refresh.php';
}
if ( get_rocket_option( 'minify_js' ) ) {
$plugins['wp-js'] = 'wp-js/wp-js.php';
$plugins['combine-js'] = 'combine-js/combine-js.php';
$plugins['footer-javascript'] = 'footer-javascript/footer-javascript.php';
$plugins['scripts-to-footerphp'] = 'scripts-to-footerphp/scripts-to-footer.php';
}
if ( get_rocket_option( 'control_heartbeat' ) ) {
$plugins['heartbeat-control'] = 'heartbeat-control/heartbeat-control.php';
}
/**
* Filter the recommended plugins to deactivate to prevent conflicts
*
* @since 2.6.4
*
* @param array $plugins List of recommended plugins to deactivate.
*/
$plugins = apply_filters( 'rocket_plugins_to_deactivate', $plugins );
/**
* Filter the recommended plugins to deactivate explanations
*
* @since 3.10.5
*
* @param array $plugins List of recommended plugins to deactivate explanations.
*/
$plugins_explanations = apply_filters( 'rocket_plugins_to_deactivate_explanations', $plugins_explanations );
$plugins = array_filter( $plugins, 'is_plugin_active' );
if ( current_user_can( 'rocket_manage_options' )
&& count( $plugins )
&& rocket_valid_key()
) {
// translators: %s is WP Rocket plugin name.
$warning = '<p>' . sprintf( __( '<strong>%s</strong>: The following plugins are not compatible with this plugin and may cause unexpected results:', 'rocket' ), WP_ROCKET_PLUGIN_NAME ) . '</p>';
$warning .= '<ul class="rocket-plugins-error">';
foreach ( $plugins as $k => $plugin ) {
$plugin_data = get_plugin_data( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $plugin );
$warning .= '<li><b>' . $plugin_data['Name'] . '</b>' . ( isset( $plugins_explanations[ $k ] ) ? ' - ' . $plugins_explanations[ $k ] : '' ) . '</span> <a href="' . wp_nonce_url( admin_url( 'admin-post.php?action=deactivate_plugin&plugin=' . rawurlencode( $plugin ) ), 'deactivate_plugin' ) . '" class="button-secondary alignright">' . __( 'Deactivate', 'rocket' ) . '</a></li>';
}
$warning .= '</ul>';
rocket_notice_html(
[
'status' => 'error',
'dismissible' => '',
'message' => $warning,
]
);
}
}
add_action( 'admin_notices', 'rocket_plugins_to_deactivate' );
/**
* Displays a warning if Rocket Footer JS plugin is active
*
* @since 3.2.3
* @author Remy Perona
*
* @return void
*/
function rocket_warning_footer_js_plugin() {
$screen = get_current_screen();
if ( ! current_user_can( 'rocket_manage_options' ) ) {
return;
}
if ( 'settings_page_wprocket' !== $screen->id ) {
return;
}
if ( ! is_plugin_active( 'rocket-footer-js/rocket-footer-js.php' ) ) {
return;
}
rocket_notice_html(
[
'status' => 'warning',
'message' => __( 'WP Rocket Footer JS is not an official add-on. It prevents some options in WP Rocket from working correctly. Please deactivate it if you have problems.', 'rocket' ),
'dismiss_button' => true,
]
);
}
add_action( 'admin_notices', 'rocket_warning_footer_js_plugin' );
/**
* Display a warning if Endurance Cache is not disabled
*
* @since 3.3.7
* @author Remy Perona
*
* @return void
*/
function rocket_warning_endurance_cache() {
$screen = get_current_screen();
// This filter is documented in inc/admin-bar.php.
if ( ! current_user_can( apply_filters( 'rocket_capacity', 'manage_options' ) ) ) {
return;
}
if ( 'settings_page_wprocket' !== $screen->id ) {
return;
}
if ( ! class_exists( 'Endurance_Page_Cache' ) ) {
return;
}
if ( 0 === (int) get_option( 'endurance_cache_level' ) ) {
return;
}
rocket_notice_html(
[
'status' => 'error',
'message' => sprintf(
// translators: %1$s = opening link tag, %2$s = closing link tag.
__( 'Endurance Cache is currently enabled, which will conflict with WP Rocket Cache. Please set the Endurance Cache cache level to Off (Level 0) on the %1$sSettings > General%2$s page to prevent any issues.', 'rocket' ),
'<a href="' . admin_url( 'options-general.php#epc_settings' ) . '">',
'</a>'
),
]
);
}
add_action( 'admin_notices', 'rocket_warning_endurance_cache' );
/**
* This warning is displayed when there is no permalink structure in the configuration.
*
* @since 1.0
*/
function rocket_warning_using_permalinks() {
if ( current_user_can( 'rocket_manage_options' )
&& ! $GLOBALS['wp_rewrite']->using_permalinks()
&& rocket_valid_key()
) {
$message = sprintf(
/* translators: %1$s WP Rocket plugin name; %2$s = opening link; %3$s = closing link */
__( '%1$s: A custom permalink structure is required for the plugin to work properly. %2$sGo to permalinks settings%3$s', 'rocket' ),
'<strong>' . WP_ROCKET_PLUGIN_NAME . '</strong>',
'<a href="' . admin_url( 'options-permalink.php' ) . '">',
'</a>'
);
rocket_notice_html(
[
'status' => 'error',
'dismissible' => '',
'message' => $message,
]
);
}
}
add_action( 'admin_notices', 'rocket_warning_using_permalinks' );
/**
* This warning is displayed when the .htaccess file doesn't exist or isn't writeable
*
* @since 1.0
*/
function rocket_warning_htaccess_permissions() {
global $is_apache;
$htaccess_file = get_home_path() . '.htaccess';
if ( ! current_user_can( 'rocket_manage_options' )
|| ( rocket_direct_filesystem()->is_writable( $htaccess_file ) )
|| ! $is_apache
// This filter is documented in inc/functions/htaccess.php.
|| apply_filters( 'rocket_disable_htaccess', false )
|| ! rocket_valid_key() ) {
return;
}
if ( rocket_check_htaccess_rules() ) {
return;
}
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
return;
}
$message = sprintf(
// translators: %s = plugin name.
__( '%s could not modify the .htaccess file due to missing writing permissions.', 'rocket' ),
'<strong>' . WP_ROCKET_PLUGIN_NAME . '</strong>'
);
$message .= '<br>' . sprintf(
/* translators: This is a doc title! %1$s = opening link; %2$s = closing link */
__( 'Troubleshoot: %1$sHow to make system files writeable%2$s', 'rocket' ),
/* translators: Documentation exists in EN, DE, FR, ES, IT; use loaclised URL if applicable */
'<a href="' . __( 'https://docs.wp-rocket.me/article/626-how-to-make-system-files-htaccess-wp-config-writeable/?utm_source=wp_plugin&utm_medium=wp_rocket', 'rocket' ) . '" target="_blank">',
'</a>'
);
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 42 );
$message .= '<p>' . __( 'Don’t worry, WP Rocket’s page caching and settings will still function correctly.', 'rocket' ) . '<br>' . __( 'For optimal performance, adding the following lines into your .htaccess is recommended (not required):', 'rocket' ) . '<br><textarea readonly="readonly" id="rocket_htaccess_rules" name="rocket_htaccess_rules" class="large-text readonly" rows="6">' . esc_textarea( get_rocket_htaccess_marker() ) . '</textarea></p>';
remove_filter( 'rocket_htaccess_mod_rewrite', '__return_false', 42 );
rocket_notice_html(
[
'status' => 'warning',
'dismissible' => '',
'message' => $message,
'dismiss_button' => __FUNCTION__,
]
);
}
add_action( 'admin_notices', 'rocket_warning_htaccess_permissions' );
/**
* This warning is displayed when the config dir isn't writeable
*
* @since 2.0.2
*/
function rocket_warning_config_dir_permissions() {
if ( current_user_can( 'rocket_manage_options' )
&& ( ! rocket_direct_filesystem()->is_writable( WP_ROCKET_CONFIG_PATH ) )
&& rocket_valid_key() ) {
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
return;
}
$message = rocket_notice_writing_permissions( trim( str_replace( ABSPATH, '', WP_ROCKET_CONFIG_PATH ), '/' ) );
rocket_notice_html(
[
'status' => 'error',
'dismissible' => '',
'message' => $message,
]
);
}
}
add_action( 'admin_notices', 'rocket_warning_config_dir_permissions' );
/**
* This warning is displayed when the cache dir isn't writeable
*
* @since 1.0
*/
function rocket_warning_cache_dir_permissions() {
if ( current_user_can( 'rocket_manage_options' )
&& ( ! rocket_direct_filesystem()->is_writable( WP_ROCKET_CACHE_PATH ) )
&& rocket_valid_key() ) {
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
return;
}
$message = rocket_notice_writing_permissions( trim( str_replace( ABSPATH, '', WP_ROCKET_CACHE_PATH ), '/' ) );
rocket_notice_html(
[
'status' => 'error',
'dismissible' => '',
'message' => $message,
]
);
}
}
add_action( 'admin_notices', 'rocket_warning_cache_dir_permissions' );
/**
* This warning is displayed when the minify cache dir isn't writeable
*
* @since 2.1
*/
function rocket_warning_minify_cache_dir_permissions() {
if ( current_user_can( 'rocket_manage_options' )
&& ( ! rocket_direct_filesystem()->is_writable( WP_ROCKET_MINIFY_CACHE_PATH ) )
&& ( get_rocket_option( 'minify_css', false ) || get_rocket_option( 'minify_js', false ) )
&& rocket_valid_key() ) {
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
return;
}
$message = rocket_notice_writing_permissions( trim( str_replace( ABSPATH, '', WP_ROCKET_MINIFY_CACHE_PATH ), '/' ) );
rocket_notice_html(
[
'status' => 'error',
'dismissible' => '',
'message' => $message,
]
);
}
}
add_action( 'admin_notices', 'rocket_warning_minify_cache_dir_permissions' );
/**
* This warning is displayed when the busting cache dir isn't writeable
*
* @since 2.9
*/
function rocket_warning_busting_cache_dir_permissions() {
if ( current_user_can( 'rocket_manage_options' )
&& ( ! rocket_direct_filesystem()->is_writable( WP_ROCKET_CACHE_BUSTING_PATH ) )
&& rocket_valid_key() ) {
$boxes = get_user_meta( get_current_user_id(), 'rocket_boxes', true );
if ( in_array( __FUNCTION__, (array) $boxes, true ) ) {
return;
}
$message = rocket_notice_writing_permissions( trim( str_replace( ABSPATH, '', WP_ROCKET_CACHE_BUSTING_PATH ), '/' ) );
rocket_notice_html(
[
'status' => 'error',
'dismissible' => '',
'message' => $message,
]
);
}
}
add_action( 'admin_notices', 'rocket_warning_busting_cache_dir_permissions' );
/**
* Confirming notice when the site has been added
*
* @since 2.2
*/
function rocket_thank_you_license() {
if ( '1' === get_rocket_option( 'license' ) ) {
$options = get_option( WP_ROCKET_SLUG );
$options['license'] = time();
$options['ignore'] = true;
update_option( WP_ROCKET_SLUG, $options );
$message = sprintf(
/* translators: %1$s = plugin name, %2$s + %3$s = opening links, %4$s = closing link */
__( '%1$s is good to go! %2$sTest your load time%4$s, or visit your %3$ssettings%4$s.', 'rocket' ),
'<strong>' . WP_ROCKET_PLUGIN_NAME . '</strong>',
'<a href="https://wp-rocket.me/blog/how-to-test-wordpress-site-performance-measure-speed-results/?utm_source=wp_plugin&utm_medium=wp_rocket" target="_blank">',
'<a href="' . admin_url( 'options-general.php?page=' . WP_ROCKET_PLUGIN_SLUG ) . '">',
'</a>'
);
rocket_notice_html( [ 'message' => $message ] );
}
}
add_action( 'admin_notices', 'rocket_thank_you_license' );
/**
* Displays a notice for analytics opt-in
*
* @since 2.11
* @author Remy Perona
*/
function rocket_analytics_optin_notice() {
$screen = get_current_screen();
if ( ! current_user_can( 'rocket_manage_options' ) ) {
return;
}
if ( 'settings_page_wprocket' !== $screen->id ) {
return;
}
if ( 1 === (int) get_option( 'rocket_analytics_notice_displayed' ) ) {
return;
}
if ( get_rocket_option( 'analytics_enabled' ) ) {
return;
}
$analytics_notice = sprintf(
// Opening <p> provided by rocket_notice_html().
'<strong>%1$s</strong><br>%2$s</p>',
__( 'Would you allow WP Rocket to collect non-sensitive diagnostic data from this website?', 'rocket' ),
__( 'This would help us to improve WP Rocket for you in the future.', 'rocket' )
);
$analytics_notice .= sprintf(
'<p><button class="hide-if-no-js button-rocket-reveal rocket-preview-analytics-data">%s</button></p>',
/* translators: button text, click will expand data collection preview */
__( 'What info will we collect?', 'rocket' )
);
$analytics_notice .= sprintf(
'<div class="rocket-analytics-data-container"><p class="description">%1$s</p>%2$s</div>',
__( 'Below is a detailed view of all data WP Rocket will collect if granted permission. WP Rocket will never transmit any domain names or email addresses (except for license validation), IP addresses, or third-party API keys.', 'rocket' ),
rocket_data_collection_preview_table()
);
$analytics_notice .= sprintf(
'<p><a href="%1$s" class="button button-primary">%2$s</a> <a href="%3$s" class="button button-secondary">%4$s</a>',
// Closing </p> provided by rocket_notice_html().
wp_nonce_url( admin_url( 'admin-post.php?action=rocket_analytics_optin&value=yes' ), 'analytics_optin' ),
/* translators: button text for data collection opt-in */
__( 'Yes, allow', 'rocket' ),
wp_nonce_url( admin_url( 'admin-post.php?action=rocket_analytics_optin&value=no' ), 'analytics_optin' ),
/* translators: button text for data collection opt-in */
__( 'No, thanks', 'rocket' )
);
// Status should be as neutral as possible; nothing has happened yet.
rocket_notice_html(
[
'status' => 'info',
'message' => $analytics_notice,
]
);
}
add_action( 'admin_notices', 'rocket_analytics_optin_notice' );
/**
* Displays a notice after analytics opt-in
*
* @since 2.11
* @author Remy Perona
*/
function rocket_analytics_optin_thankyou_notice() {
$screen = get_current_screen();
if ( ! current_user_can( 'rocket_manage_options' ) ) {
return;
}
if ( 'settings_page_wprocket' !== $screen->id ) {
return;
}
$analytics_optin = get_transient( 'rocket_analytics_optin' );
if ( ! $analytics_optin ) {
return;
}
$thankyou_message = sprintf(
// Opening <p> provided by rocket_notice_html().
'<strong>%s</strong></p>',
__( 'Thank you!', 'rocket' )
);
$thankyou_message .= sprintf(
'<p>%1$s</p><div>%2$s</div>',
__( 'WP Rocket now collects these metrics from your website:', 'rocket' ),
rocket_data_collection_preview_table()
);
// Closing </p> provided by rocket_notice_html().
$thankyou_message .= '<p>';
rocket_notice_html(
[
'message' => $thankyou_message,
]
);
delete_transient( 'rocket_analytics_optin' );
}
add_action( 'admin_notices', 'rocket_analytics_optin_thankyou_notice' );
/**
* Displays a notice after clearing the cache
*
* @since 2.11
* @author Remy Perona
*/
function rocket_clear_cache_notice() {
$cleared_cache = get_transient( 'rocket_clear_cache' );
if ( ! $cleared_cache ) {
return;
}
delete_transient( 'rocket_clear_cache' );
$notice = '';
switch ( $cleared_cache ) {
case 'all':
if ( current_user_can( 'rocket_purge_cache' ) ) {
// translators: %s = plugin name.
$notice = sprintf( __( '%s: Cache cleared.', 'rocket' ), '<strong>' . WP_ROCKET_PLUGIN_NAME . '</strong>' );
$notice .= '<em> (' . date_i18n( get_option( 'date_format' ) ) . ' @ ' . date_i18n( get_option( 'time_format' ) ) . ') </em>';
}
break;
case 'post':
if ( current_user_can( 'rocket_purge_posts' ) ) {
// translators: %s = plugin name.
$notice = sprintf( __( '%s: Post cache cleared.', 'rocket' ), '<strong>' . WP_ROCKET_PLUGIN_NAME . '</strong>' );
$notice .= '<em> (' . date_i18n( get_option( 'date_format' ) ) . ' @ ' . date_i18n( get_option( 'time_format' ) ) . ') </em>';
}
break;
case 'term':
if ( current_user_can( 'rocket_purge_terms' ) ) {
// translators: %s = plugin name.
$notice = sprintf( __( '%s: Term cache cleared.', 'rocket' ), '<strong>' . WP_ROCKET_PLUGIN_NAME . '</strong>' );
$notice .= '<em> (' . date_i18n( get_option( 'date_format' ) ) . ' @ ' . date_i18n( get_option( 'time_format' ) ) . ') </em>';
}
break;
case 'user':
if ( current_user_can( 'rocket_purge_users' ) ) {
// translators: %s = plugin name).
$notice = sprintf( __( '%s: User cache cleared.', 'rocket' ), '<strong>' . WP_ROCKET_PLUGIN_NAME . '</strong>' );
$notice .= '<em> (' . date_i18n( get_option( 'date_format' ) ) . ' @ ' . date_i18n( get_option( 'time_format' ) ) . ') </em>';
}
break;
default:
break;
}
if ( empty( $notice ) ) {
return;
}
rocket_notice_html(
[
'message' => $notice,
]
);
}
add_action( 'admin_notices', 'rocket_clear_cache_notice' );
/**
* Outputs notice HTML
*
* @since 2.11
* @author Remy Perona
*
* @param array $args An array of arguments used to determine the notice output.
* @return void
*/
function rocket_notice_html( $args ) {
$defaults = [
'status' => 'success',
'dismissible' => 'is-dismissible',
'message' => '',
'action' => '',
'dismiss_button' => false,
'dismiss_button_message' => __( 'Dismiss this notice', 'rocket' ),
'readonly_content' => '',
'id' => '',
];
$args = wp_parse_args( $args, $defaults );
switch ( $args['action'] ) {
case 'clear_cache':
$args['action'] = '<a class="wp-core-ui button" href="' . wp_nonce_url( admin_url( 'admin-post.php?action=purge_cache&type=all' ), 'purge_cache_all' ) . '">' . __( 'Clear cache', 'rocket' ) . '</a>';
break;
case 'stop_preload':
$args['action'] = '<a class="wp-core-ui button" href="' . wp_nonce_url( admin_url( 'admin-post.php?action=rocket_stop_preload&type=all' ), 'rocket_stop_preload' ) . '">' . __( 'Stop Preload', 'rocket' ) . '</a>';
break;
case 'switch_to_rucss':
$params = [
'action' => 'switch_to_rucss',
];
$args['action'] = '<a class="wp-core-ui button" href="' . add_query_arg( $params, wp_nonce_url( admin_url( 'admin-post.php' ), 'rucss_switch' ) ) . '">' . __( 'Turn on Remove Unused CSS', 'rocket' ) . '</a>';
break;
case 'enable_separate_mobile_cache':
$params = [
'action' => 'rocket_enable_separate_mobile_cache',
];
$args['action'] = '<a class="wp-core-ui button" href="' . add_query_arg( $params, wp_nonce_url( admin_url( 'admin-post.php' ), 'rocket_enable_separate_mobile_cache' ) ) . '">' . __( 'Enable “Separate Cache Files for Mobile Devices” now', 'rocket' ) . '</a>';
break;
case 'force_deactivation':
/**
* Allow a "force deactivation" link to be printed, use at your own risks
*
* @since 2.0.0
*
* @param bool $permit_force_deactivation true will print the link.
*/
$permit_force_deactivation = apply_filters( 'rocket_permit_force_deactivation', true );
// We add a link to permit "force deactivation", use at your own risks.
if ( $permit_force_deactivation ) {
global $status, $page, $s;
$plugin_file = 'wp-rocket/wp-rocket.php';
$rocket_nonce = wp_create_nonce( 'force_deactivation' );
$args['action'] = '<a href="' . wp_nonce_url( 'plugins.php?action=deactivate&rocket_nonce=' . $rocket_nonce . '&plugin=' . $plugin_file . '&plugin_status=' . $status . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file ) . '">' . __( 'Force deactivation ', 'rocket' ) . '</a>';
}
break;
}
$notice_id = '';
if ( ! empty( $args['id'] ) ) {
$notice_id = ' id="' . esc_attr( $args['id'] ) . '"';
}
?>
<div class="notice notice-<?php echo esc_attr( $args['status'] ); ?> <?php echo esc_attr( $args['dismissible'] ); ?>"<?php echo $notice_id; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<?php
$tag = 0 !== strpos( $args['message'], '<p' ) && 0 !== strpos( $args['message'], '<ul' );
echo ( $tag ? '<p>' : '' ) . $args['message'] . ( $tag ? '</p>' : '' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
?>
<?php if ( ! empty( $args['readonly_content'] ) ) : ?>
<p><?php esc_html_e( 'The following code should have been written to this file:', 'rocket' ); ?>
<br><textarea readonly="readonly" id="rules" name="rules" class="large-text readonly" rows="6"><?php echo esc_textarea( $args['readonly_content'] ); ?></textarea>
</p>
<?php
endif;
if ( $args['action'] || $args['dismiss_button'] ) :
?>
<p>
<?php echo $args['action']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php if ( $args['dismiss_button'] ) : ?>
<a class="rocket-dismiss <?php echo $args['dismiss_button_class'] ?? ''; ?>" href="<?php echo wp_nonce_url( admin_url( 'admin-post.php?action=rocket_ignore&box=' . $args['dismiss_button'] ), 'rocket_ignore_' . $args['dismiss_button'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>"><?php echo esc_html( $args['dismiss_button_message'] ); ?></a>
<?php endif; ?>
</p>
<?php endif; ?>
</div>
<?php
}
/**
* Outputs formatted notice about issues with writing permissions
*
* @since 2.11
* @author Caspar Hübinger
*
* @param string $file File or folder name.
* @return string Message HTML
*/
function rocket_notice_writing_permissions( $file ) {
$message = sprintf(
// translators: %s = plugin name.
__( '%s cannot configure itself due to missing writing permissions.', 'rocket' ),
'<strong>' . WP_ROCKET_PLUGIN_NAME . '</strong>'
);
$message .= '<br>' . sprintf(
/* translators: %s = file/folder name */
__( 'Affected file/folder: %s', 'rocket' ),
'<code>' . $file . '</code>'
);
$message .= '<br>' . sprintf(
/* translators: This is a doc title! %1$s = opening link; %2$s = closing link */
__( 'Troubleshoot: %1$sHow to make system files writeable%2$s', 'rocket' ),
/* translators: Documentation exists in EN, DE, FR, ES, IT; use loaclised URL if applicable */
'<a href="' . __( 'https://docs.wp-rocket.me/article/626-how-to-make-system-files-htaccess-wp-config-writeable/?utm_source=wp_plugin&utm_medium=wp_rocket', 'rocket' ) . '" target="_blank">',
'</a>'
);
return $message;
}