-
Notifications
You must be signed in to change notification settings - Fork 125
/
wp-cache.php
4458 lines (3919 loc) · 182 KB
/
wp-cache.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
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* Plugin Name: WP Super Cache
* Plugin URI: https://wordpress.org/plugins/wp-super-cache/
* Description: Very fast caching plugin for WordPress.
* Version: 1.12.5-alpha
* Author: Automattic
* Author URI: https://automattic.com/
* License: GPL2+
* License URI: https://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: wp-super-cache
*/
/*
Copyright Automattic and many other contributors.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
define( 'WPSC_VERSION_ID', '1.12.1' );
require_once( __DIR__. '/inc/delete-cache-button.php');
require_once( __DIR__. '/inc/preload-notification.php');
require_once __DIR__ . '/inc/boost.php';
if ( ! function_exists( 'wp_cache_phase2' ) ) {
require_once( __DIR__. '/wp-cache-phase2.php');
}
if ( ! defined( 'PHP_VERSION_ID' ) ) {
// For versions of PHP below 5.2.7, this constant doesn't exist.
$wpsc_php_version = explode( '.', PHP_VERSION );
define( 'PHP_VERSION_ID', intval( $wpsc_php_version[0] * 10000 + $wpsc_php_version[1] * 100 + $wpsc_php_version[2] ) );
unset( $wpsc_php_version );
}
/**
* Defines how many posts to preload per loop.
*/
if ( ! defined( 'WPSC_PRELOAD_POST_COUNT' ) ) {
define( 'WPSC_PRELOAD_POST_COUNT', 10 );
}
/**
* Defines the interval in seconds between preloading pages.
*/
if ( ! defined( 'WPSC_PRELOAD_POST_INTERVAL' ) ) {
define( 'WPSC_PRELOAD_POST_INTERVAL', 1 );
}
/**
* Defines the interval in seconds between preloading loops.
*/
if ( ! defined( 'WPSC_PRELOAD_LOOP_INTERVAL' ) ) {
define( 'WPSC_PRELOAD_LOOP_INTERVAL', 0 );
}
function wpsc_init() {
global $wp_cache_config_file, $wp_cache_config_file_sample, $wpsc_advanced_cache_dist_filename, $wp_cache_check_wp_config, $wpsc_advanced_cache_filename, $wpsc_promo_links;
if ( ! defined( 'WPCACHECONFIGPATH' ) ) {
define( 'WPCACHECONFIGPATH', WP_CONTENT_DIR );
}
$wp_cache_config_file = WPCACHECONFIGPATH . '/wp-cache-config.php';
// Centralise the promotional links to other products
$wpsc_promo_links = array(
'boost' => 'https://jetpack.com/boost/?utm_source=wporg&utm_medium=plugin&utm_campaign=wp-super-cache&utm_id=wp-super-cache',
'photon' => 'https://jetpack.com/features/design/content-delivery-network/?utm_source=wporg&utm_medium=plugin&utm_campaign=wp-super-cache&utm_id=wp-super-cache',
'videopress' => 'https://jetpack.com/videopress/?utm_source=wporg&utm_medium=plugin&utm_campaign=wp-super-cache&utm_id=wp-super-cache',
'crowdsignal' => 'https://crowdsignal.com/?utm_source=wporg&utm_medium=plugin&utm_campaign=wp-super-cache&utm_id=wp-super-cache',
'jetpack' => 'https://jetpack.com/?utm_source=wporg&utm_medium=plugin&utm_campaign=wp-super-cache&utm_id=wp-super-cache',
);
if ( !defined( 'WPCACHEHOME' ) ) {
define( 'WPCACHEHOME', __DIR__ . '/' );
$wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
$wpsc_advanced_cache_dist_filename = WPCACHEHOME . 'advanced-cache.php';
} elseif ( realpath( WPCACHEHOME ) != realpath( __DIR__ ) ) {
$wp_cache_config_file_sample = __DIR__. '/wp-cache-config-sample.php';
$wpsc_advanced_cache_dist_filename = __DIR__. '/advanced-cache.php';
if ( ! defined( 'ADVANCEDCACHEPROBLEM' ) ) {
define( 'ADVANCEDCACHEPROBLEM', 1 ); // force an update of WPCACHEHOME
}
} else {
$wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
$wpsc_advanced_cache_dist_filename = WPCACHEHOME . 'advanced-cache.php';
}
$wpsc_advanced_cache_filename = WP_CONTENT_DIR . '/advanced-cache.php';
if ( !defined( 'WP_CACHE' ) || ( defined( 'WP_CACHE' ) && constant( 'WP_CACHE' ) == false ) ) {
$wp_cache_check_wp_config = true;
}
}
wpsc_init();
/**
* WP-CLI requires explicit declaration of global variables.
* It's minimal list of global variables.
*/
global $super_cache_enabled, $cache_enabled, $wp_cache_mod_rewrite, $wp_cache_home_path, $cache_path, $file_prefix;
global $wp_cache_mutex_disabled, $mutex_filename, $sem_id, $wp_super_cache_late_init;
global $cache_compression, $cache_max_time, $wp_cache_shutdown_gc, $cache_rebuild_files;
global $wp_super_cache_debug, $wp_super_cache_advanced_debug, $wp_cache_debug_level, $wp_cache_debug_to_file;
global $wp_cache_debug_log, $wp_cache_debug_ip, $wp_cache_debug_username, $wp_cache_debug_email;
global $cache_time_interval, $cache_scheduled_time, $cache_schedule_interval, $cache_schedule_type, $cache_gc_email_me;
global $wp_cache_preload_on, $wp_cache_preload_interval, $wp_cache_preload_posts, $wp_cache_preload_taxonomies;
// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- these are used by various functions but the linter complains.
global $wp_cache_preload_email_me, $wp_cache_preload_email_volume;
global $wp_cache_mobile, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes;
global $wp_cache_config_file, $wp_cache_config_file_sample;
// Check is cache config already loaded.
if ( ! isset( $cache_enabled, $super_cache_enabled, $wp_cache_mod_rewrite, $cache_path ) &&
empty( $wp_cache_phase1_loaded ) &&
// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
! @include( $wp_cache_config_file )
) {
@include $wp_cache_config_file_sample; // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
}
include(WPCACHEHOME . 'wp-cache-base.php');
if ( class_exists( 'WP_REST_Controller' ) ) {
include( __DIR__. '/rest/load.php' );
}
function wp_super_cache_init_action() {
load_plugin_textdomain( 'wp-super-cache', false, basename( __DIR__ ) . '/languages' );
wpsc_register_post_hooks();
}
add_action( 'init', 'wp_super_cache_init_action' );
function wp_cache_set_home() {
global $wp_cache_is_home;
$wp_cache_is_home = ( is_front_page() || is_home() );
if ( $wp_cache_is_home && is_paged() )
$wp_cache_is_home = false;
}
add_action( 'template_redirect', 'wp_cache_set_home' );
function wpsc_enqueue_styles() {
wp_enqueue_style(
'wpsc_styles',
plugins_url( 'styling/dashboard.css', __FILE__ ),
array(),
filemtime( plugin_dir_path( __FILE__ ) . 'styling/dashboard.css' )
);
}
// Check for the page parameter to see if we're on a WPSC page.
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['page'] ) && $_GET['page'] === 'wpsupercache' ) {
add_action( 'admin_enqueue_scripts', 'wpsc_enqueue_styles' );
}
// OSSDL CDN plugin (https://wordpress.org/plugins/ossdl-cdn-off-linker/)
include_once( WPCACHEHOME . 'ossdl-cdn.php' );
function get_wpcachehome() {
if ( function_exists( '_deprecated_function' ) ) {
_deprecated_function( __FUNCTION__, 'WP Super Cache 1.6.5' );
}
if ( ! defined( 'WPCACHEHOME' ) ) {
if ( is_file( __DIR__ . '/wp-cache-config-sample.php' ) ) {
define( 'WPCACHEHOME', trailingslashit( __DIR__ ) );
} elseif ( is_file( __DIR__ . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
define( 'WPCACHEHOME', __DIR__ . '/wp-super-cache/' );
} else {
die( sprintf( esc_html__( 'Please create %s/wp-cache-config.php from wp-super-cache/wp-cache-config-sample.php', 'wp-super-cache' ), esc_attr( WPCACHECONFIGPATH ) ) );
}
}
}
function wpsc_remove_advanced_cache() {
global $wpsc_advanced_cache_filename;
if ( file_exists( $wpsc_advanced_cache_filename ) ) {
$file = file_get_contents( $wpsc_advanced_cache_filename );
if (
strpos( $file, "WP SUPER CACHE 0.8.9.1" ) ||
strpos( $file, "WP SUPER CACHE 1.2" )
) {
unlink( $wpsc_advanced_cache_filename );
}
}
}
function wpsupercache_uninstall() {
global $wp_cache_config_file, $cache_path;
wpsc_remove_advanced_cache();
if ( file_exists( $wp_cache_config_file ) ) {
unlink( $wp_cache_config_file );
}
wp_cache_remove_index();
if ( ! empty( $cache_path ) ) {
@unlink( $cache_path . '.htaccess' );
@unlink( $cache_path . 'meta' );
@unlink( $cache_path . 'supercache' );
}
wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
wp_clear_scheduled_hook( 'wp_cache_gc' );
wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
wp_cache_disable_plugin();
delete_site_option( 'wp_super_cache_index_detected' );
}
if ( is_admin() ) {
register_uninstall_hook( __FILE__, 'wpsupercache_uninstall' );
}
function wpsupercache_deactivate() {
global $wp_cache_config_file, $wpsc_advanced_cache_filename, $cache_path;
wpsc_remove_advanced_cache();
if ( ! empty( $cache_path ) ) {
prune_super_cache( $cache_path, true );
wp_cache_remove_index();
@unlink( $cache_path . '.htaccess' );
@unlink( $cache_path . 'meta' );
@unlink( $cache_path . 'supercache' );
}
wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
wp_clear_scheduled_hook( 'wp_cache_gc' );
wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = false;', $wp_cache_config_file);
wp_cache_disable_plugin( false ); // don't delete configuration file
delete_user_option( get_current_user_id(), 'wpsc_dismissed_boost_banner' );
}
register_deactivation_hook( __FILE__, 'wpsupercache_deactivate' );
function wpsupercache_activate() {
global $cache_path;
if ( ! isset( $cache_path ) || $cache_path == '' )
$cache_path = WP_CONTENT_DIR . '/cache/'; // from sample config file
ob_start();
wpsc_init();
if (
! wp_cache_verify_cache_dir() ||
! wpsc_check_advanced_cache() ||
! wp_cache_verify_config_file()
) {
$text = ob_get_contents();
ob_end_clean();
return false;
}
$text = ob_get_contents();
wp_cache_check_global_config();
ob_end_clean();
wp_schedule_single_event( time() + 10, 'wp_cache_add_site_cache_index' );
}
register_activation_hook( __FILE__, 'wpsupercache_activate' );
function wpsupercache_site_admin() {
global $wp_version;
if ( version_compare( $wp_version, '4.8', '>=' ) ) {
return current_user_can( 'setup_network' );
}
return is_super_admin();
}
function wp_cache_add_pages() {
if ( wpsupercache_site_admin() ) {
// In single or MS mode add this menu item too, but only for superadmins in MS mode.
add_options_page( 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager' );
}
}
add_action( 'admin_menu', 'wp_cache_add_pages' );
function wp_cache_network_pages() {
add_submenu_page( 'settings.php', 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager' );
}
add_action( 'network_admin_menu', 'wp_cache_network_pages' );
/**
* Load JavaScript on admin pages.
*/
function wp_super_cache_admin_enqueue_scripts( $hook ) {
if ( 'settings_page_wpsupercache' !== $hook ) {
return;
}
wp_enqueue_script(
'wp-super-cache-admin',
trailingslashit( plugin_dir_url( __FILE__ ) ) . 'js/admin.js',
array( 'jquery' ),
WPSC_VERSION_ID,
false
);
wp_localize_script(
'wp-super-cache-admin',
'wpscAdmin',
array(
'boostNoticeDismissNonce' => wp_create_nonce( 'wpsc_dismiss_boost_notice' ),
'boostDismissNonce' => wp_create_nonce( 'wpsc_dismiss_boost_banner' ),
'boostInstallNonce' => wp_create_nonce( 'updates' ),
'boostActivateNonce' => wp_create_nonce( 'activate-boost' ),
)
);
}
add_action( 'admin_enqueue_scripts', 'wp_super_cache_admin_enqueue_scripts' );
/**
* Use the standard WordPress plugin installation ajax handler.
*/
add_action( 'wp_ajax_wpsc_install_plugin', 'wp_ajax_install_plugin' );
/**
* Check if Jetpack Boost has been installed.
*/
function wpsc_is_boost_installed() {
$plugins = array_keys( get_plugins() );
foreach ( $plugins as $plugin ) {
if ( str_contains( $plugin, 'jetpack-boost/jetpack-boost.php' ) ) {
return true;
}
}
return false;
}
/**
* Check if Jetpack Boost is active.
*/
function wpsc_is_boost_active() {
return class_exists( '\Automattic\Jetpack_Boost\Jetpack_Boost' );
}
/**
* Admin ajax action: hide the Boost Banner.
*/
function wpsc_hide_boost_banner() {
check_ajax_referer( 'wpsc_dismiss_boost_banner', 'nonce' );
update_user_option( get_current_user_id(), 'wpsc_dismissed_boost_banner', '1' );
wp_die();
}
add_action( 'wp_ajax_wpsc-hide-boost-banner', 'wpsc_hide_boost_banner' );
/**
* Admin ajax action: activate Jetpack Boost.
*/
function wpsc_ajax_activate_boost() {
check_ajax_referer( 'activate-boost' );
if ( ! isset( $_POST['source'] ) ) {
wp_send_json_error( 'no source specified' );
}
$source = sanitize_text_field( wp_unslash( $_POST['source'] ) );
$result = activate_plugin( 'jetpack-boost/jetpack-boost.php' );
if ( is_wp_error( $result ) ) {
wp_send_json_error( $result->get_error_message() );
}
wpsc_notify_migration_to_boost( $source );
wp_send_json_success();
}
add_action( 'wp_ajax_wpsc_activate_boost', 'wpsc_ajax_activate_boost' );
/**
* Show a Jetpack Boost installation banner (unless dismissed or installed)
*/
function wpsc_jetpack_boost_install_banner() {
if ( ! wpsc_is_boost_current() ) {
return;
}
// Don't show the banner if Boost is installed, or the banner has been dismissed.
$is_dismissed = '1' === get_user_option( 'wpsc_dismissed_boost_banner' );
if ( wpsc_is_boost_active() || $is_dismissed ) {
return;
}
$config = wpsc_get_boost_migration_config();
$button_url = $config['is_installed'] ? $config['activate_url'] : $config['install_url'];
$button_label = $config['is_installed'] ? __( 'Set up Jetpack Boost', 'wp-super-cache' ) : __( 'Install Jetpack Boost', 'wp-super-cache' );
$button_class = $config['is_installed'] ? 'wpsc-activate-boost-button' : 'wpsc-install-boost-button';
$plugin_url = plugin_dir_url( __FILE__ );
?>
<div class="wpsc-boost-banner">
<div class="wpsc-boost-banner-inner">
<div class="wpsc-boost-banner-content">
<img style="width:282px" src="<?php echo esc_url( $plugin_url . '/assets/jetpack-logo.svg' ); ?>" height="36" />
<h3>
<?php esc_html_e( 'Speed up your site with our top‑rated performance tool', 'wp-super-cache' ); ?>
</h3>
<p id="wpsc-install-invitation">
<?php
esc_html_e(
'Caching is a great start, but there is more to maximize your site speed. Find out how much your cache speeds up your site and make it blazing fast with Jetpack Boost, the easiest WordPress speed optimization plugin developed by WP Super Cache engineers.',
'wp-super-cache'
);
?>
</p>
<div class="wpsc-boost-migration-error" style="display:none; color:red; margin-bottom: 20px;"></div>
<div style="display: flex; gap: 24px;">
<a style="font-weight: 500; line-height: 1; padding: 10px 20px 15px;" data-source='banner' href="<?php echo esc_url( $button_url ); ?>" class="wpsc-boost-migration-button button button-primary <?php echo esc_attr( $button_class ); ?>">
<div class='spinner' style='display:none; margin-top: 8px'></div>
<label><?php echo esc_html( $button_label ); ?></label>
</a>
<a style="display: flex; align-items: center; font-weight: 500; color: #000; " href="https://jetpack.com/blog/discover-how-to-improve-your-site-performance-with-jetpack-boost/">
Learn More
</a>
</div>
</div>
<div class="wpsc-boost-banner-image-container">
<img
width="350"
height="452"
src="<?php echo esc_url( $plugin_url . 'assets/boost-install-card-main.png' ); ?>"
title="<?php esc_attr_e( 'Check how your web site performance scores for desktop and mobile.', 'wp-super-cache' ); ?>"
alt="<?php esc_attr_e( 'An image showing the Jetpack Boost dashboard.', 'wp-super-cache' ); ?>"
srcset="<?php echo esc_url( $plugin_url . 'assets/boost-install-card-main.png' ); ?> 400w, <?php echo esc_url( $plugin_url . 'assets/boost-install-card-main-2x.png' ); ?> 800w"
sizes="(max-width: 782px) 350px, 700px"
>
</div>
</div>
<span class="wpsc-boost-dismiss dashicons dashicons-dismiss"></span>
</div>
<?php
}
function wp_cache_manager_error_checks() {
global $wp_cache_debug, $wp_cache_cron_check, $cache_enabled, $super_cache_enabled, $wp_cache_config_file, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_mobile_enabled, $wp_cache_mod_rewrite;
global $dismiss_htaccess_warning, $dismiss_readable_warning, $dismiss_gc_warning, $wp_cache_shutdown_gc, $is_nginx;
global $htaccess_path;
if ( ! wpsupercache_site_admin() ) {
return false;
}
if ( PHP_VERSION_ID < 50300 && ( ini_get( 'safe_mode' ) === '1' || strtolower( ini_get( 'safe_mode' ) ) === 'on' ) ) { // @codingStandardsIgnoreLine
echo '<div class="notice notice-error"><h4>' . esc_html__( 'Warning! PHP Safe Mode Enabled!', 'wp-super-cache' ) . '</h4>';
echo '<p>' . esc_html__( 'You may experience problems running this plugin because SAFE MODE is enabled.', 'wp-super-cache' ) . '<br />';
if ( ! ini_get( 'safe_mode_gid' ) ) { // @codingStandardsIgnoreLine
esc_html_e( 'Your server is set up to check the owner of PHP scripts before allowing them to read and write files.', 'wp-super-cache' );
echo '<br />';
printf( __( 'You or an administrator may be able to make it work by changing the group owner of the plugin scripts to match that of the web server user. The group owner of the %s/cache/ directory must also be changed. See the <a href="http://php.net/features.safe-mode">safe mode manual page</a> for further details.', 'wp-super-cache' ), esc_attr( WP_CONTENT_DIR ) );
} else {
_e( 'You or an administrator must disable this. See the <a href="http://php.net/features.safe-mode">safe mode manual page</a> for further details. This cannot be disabled in a .htaccess file unfortunately. It must be done in the php.ini config file.', 'wp-super-cache' );
}
echo '</p></div>';
}
if ( '' == get_option( 'permalink_structure' ) ) {
echo '<div class="notice notice-error"><h4>' . __( 'Permlink Structure Error', 'wp-super-cache' ) . '</h4>';
echo "<p>" . __( 'A custom url or permalink structure is required for this plugin to work correctly. Please go to the <a href="options-permalink.php">Permalinks Options Page</a> to configure your permalinks.', 'wp-super-cache' ) . "</p>";
echo '</div>';
return false;
}
if ( $wp_cache_debug || ! $wp_cache_cron_check ) {
if ( defined( 'DISABLE_WP_CRON' ) && constant( 'DISABLE_WP_CRON' ) ) {
?>
<div class="notice notice-error"><h4><?php _e( 'CRON System Disabled', 'wp-super-cache' ); ?></h4>
<p><?php _e( 'The WordPress CRON jobs system is disabled. This means the garbage collection system will not work unless you run the CRON system manually.', 'wp-super-cache' ); ?></p>
</div>
<?php
} elseif ( function_exists( "wp_remote_get" ) == false ) {
$hostname = str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'siteurl' ) ) );
if( strpos( $hostname, '/' ) )
$hostname = substr( $hostname, 0, strpos( $hostname, '/' ) );
$ip = gethostbyname( $hostname );
if( substr( $ip, 0, 3 ) == '127' || substr( $ip, 0, 7 ) == '192.168' ) {
?><div class="notice notice-warning"><h4><?php printf( __( 'Warning! Your hostname "%s" resolves to %s', 'wp-super-cache' ), $hostname, $ip ); ?></h4>
<p><?php printf( __( 'Your server thinks your hostname resolves to %s. Some services such as garbage collection by this plugin, and WordPress scheduled posts may not operate correctly.', 'wp-super-cache' ), $ip ); ?></p>
<p><?php printf( __( 'Please see entry 16 in the <a href="%s">Troubleshooting section</a> of the readme.txt', 'wp-super-cache' ), 'https://wordpress.org/plugins/wp-super-cache/faq/' ); ?></p>
</div>
<?php
return false;
} else {
wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
}
} else {
$cron_url = get_option( 'siteurl' ) . '/wp-cron.php?check=' . wp_hash('187425');
$cron = wp_remote_get($cron_url, array('timeout' => 0.01, 'blocking' => true));
if( is_array( $cron ) ) {
if( $cron[ 'response' ][ 'code' ] == '404' ) {
?><div class="notice notice-error"><h4>Warning! wp-cron.php not found!</h4>
<p><?php _e( 'Unfortunately, WordPress cannot find the file wp-cron.php. This script is required for the correct operation of garbage collection by this plugin, WordPress scheduled posts as well as other critical activities.', 'wp-super-cache' ); ?></p>
<p><?php printf( __( 'Please see entry 16 in the <a href="%s">Troubleshooting section</a> of the readme.txt', 'wp-super-cache' ), 'https://wordpress.org/plugins/wp-super-cache/faq/' ); ?></p>
</div>
<?php
} else {
wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
}
}
}
}
if (
! wpsc_check_advanced_cache() ||
! wp_cache_verify_config_file() ||
! wp_cache_verify_cache_dir()
) {
echo '<p>' . __( "Cannot continue... fix previous problems and retry.", 'wp-super-cache' ) . '</p>';
return false;
}
if ( false == function_exists( 'wpsc_deep_replace' ) ) {
$msg = __( 'Warning! You must set WP_CACHE and WPCACHEHOME in your wp-config.php for this plugin to work correctly:' ) . '<br />';
$msg .= "<code>define( 'WP_CACHE', true );</code><br />";
$msg .= "<code>define( 'WPCACHEHOME', '" . __DIR__ . "/' );</code><br />";
wp_die( $msg );
}
if (!wp_cache_check_global_config()) {
return false;
}
if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) {
?><div class="notice notice-warning"><h4><?php _e( 'Zlib Output Compression Enabled!', 'wp-super-cache' ); ?></h4>
<p><?php _e( 'PHP is compressing the data sent to the visitors of your site. Disabling this is recommended as the plugin caches the compressed output once instead of compressing the same page over and over again. Also see #21 in the Troubleshooting section. See <a href="http://php.net/manual/en/zlib.configuration.php">this page</a> for instructions on modifying your php.ini.', 'wp-super-cache' ); ?></p></div><?php
}
if (
$cache_enabled == true &&
$super_cache_enabled == true &&
$wp_cache_mod_rewrite &&
! got_mod_rewrite() &&
! $is_nginx
) {
?><div class="notice notice-warning"><h4><?php _e( 'Mod rewrite may not be installed!', 'wp-super-cache' ); ?></h4>
<p><?php _e( 'It appears that mod_rewrite is not installed. Sometimes this check isn’t 100% reliable, especially if you are not using Apache. Please verify that the mod_rewrite module is loaded. It is required for serving Super Cache static files in expert mode. You will still be able to simple mode.', 'wp-super-cache' ); ?></p></div><?php
}
if( !is_writeable_ACLSafe( $wp_cache_config_file ) ) {
if ( !defined( 'SUBMITDISABLED' ) )
define( "SUBMITDISABLED", 'disabled style="color: #aaa" ' );
?><div class="notice notice-error"><h4><?php _e( 'Read Only Mode. Configuration cannot be changed.', 'wp-super-cache' ); ?></h4>
<p><?php printf( __( 'The WP Super Cache configuration file is <code>%s/wp-cache-config.php</code> and cannot be modified. That file must be writeable by the web server to make any changes.', 'wp-super-cache' ), WPCACHECONFIGPATH ); ?>
<?php _e( 'A simple way of doing that is by changing the permissions temporarily using the CHMOD command or through your ftp client. Make sure it’s globally writeable and it should be fine.', 'wp-super-cache' ); ?></p>
<p><?php _e( '<a href="https://codex.wordpress.org/Changing_File_Permissions">This page</a> explains how to change file permissions.', 'wp-super-cache' ); ?></p>
<?php _e( 'Writeable:', 'wp-super-cache' ); ?> <code>chmod 666 <?php echo WPCACHECONFIGPATH; ?>/wp-cache-config.php</code><br />
<?php _e( 'Read-only:', 'wp-super-cache' ); ?> <code>chmod 644 <?php echo WPCACHECONFIGPATH; ?>/wp-cache-config.php</code></p>
</div><?php
} elseif ( !defined( 'SUBMITDISABLED' ) ) {
define( "SUBMITDISABLED", ' ' );
}
$valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
// Check that garbage collection is running
if ( $valid_nonce && isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'dismiss_gc_warning' ) {
wp_cache_replace_line('^ *\$dismiss_gc_warning', "\$dismiss_gc_warning = 1;", $wp_cache_config_file);
$dismiss_gc_warning = 1;
} elseif ( !isset( $dismiss_gc_warning ) ) {
$dismiss_gc_warning = 0;
}
if ( $cache_enabled && ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) && function_exists( 'get_gc_flag' ) ) {
$gc_flag = get_gc_flag();
if ( $dismiss_gc_warning == 0 ) {
if ( false == maybe_stop_gc( $gc_flag ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) {
?><div class="notice notice-warning"><h4><?php _e( 'Warning! Garbage collection is not scheduled!', 'wp-super-cache' ); ?></h4>
<p><?php _e( 'Garbage collection by this plugin clears out expired and old cached pages on a regular basis. Use <a href="#expirytime">this form</a> to enable it.', 'wp-super-cache' ); ?> </p>
<form action="" method="POST">
<input type="hidden" name="action" value="dismiss_gc_warning" />
<input type="hidden" name="page" value="wpsupercache" />
<?php wp_nonce_field( 'wp-cache' ); ?>
<input class='button-secondary' type='submit' value='<?php _e( 'Dismiss', 'wp-super-cache' ); ?>' />
</form>
<br />
</div>
<?php
}
}
}
// Server could be running as the owner of the wp-content directory. Therefore, if it's
// writable, issue a warning only if the permissions aren't 755.
if ( $valid_nonce && isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'dismiss_readable_warning' ) {
wp_cache_replace_line('^ *\$dismiss_readable_warning', "\$dismiss_readable_warning = 1;", $wp_cache_config_file);
$dismiss_readable_warning = 1;
} elseif ( !isset( $dismiss_readable_warning ) ) {
$dismiss_readable_warning = 0;
}
if( $dismiss_readable_warning == 0 && is_writeable_ACLSafe( WP_CONTENT_DIR . '/' ) ) {
$wp_content_stat = stat(WP_CONTENT_DIR . '/');
$wp_content_mode = decoct( $wp_content_stat[ 'mode' ] & 0777 );
if( substr( $wp_content_mode, -2 ) == '77' ) {
?><div class="notice notice-warning"><h4><?php printf( __( 'Warning! %s is writeable!', 'wp-super-cache' ), WP_CONTENT_DIR ); ?></h4>
<p><?php printf( __( 'You should change the permissions on %s and make it more restrictive. Use your ftp client, or the following command to fix things:', 'wp-super-cache' ), WP_CONTENT_DIR ); ?> <code>chmod 755 <?php echo WP_CONTENT_DIR; ?>/</code></p>
<p><?php _e( '<a href="https://codex.wordpress.org/Changing_File_Permissions">This page</a> explains how to change file permissions.', 'wp-super-cache' ); ?></p>
<form action="" method="POST">
<input type="hidden" name="action" value="dismiss_readable_warning" />
<input type="hidden" name="page" value="wpsupercache" />
<?php wp_nonce_field( 'wp-cache' ); ?>
<input class='button-secondary' type='submit' value='<?php _e( 'Dismiss', 'wp-super-cache' ); ?>' />
</form>
<br />
</div>
<?php
}
}
if ( ! $is_nginx && function_exists( "is_main_site" ) && true == is_main_site() ) {
if ( ! isset( $htaccess_path ) ) {
$home_path = trailingslashit( get_home_path() );
} else {
$home_path = $htaccess_path;
}
$scrules = implode( "\n", extract_from_markers( $home_path . '.htaccess', 'WPSuperCache' ) );
if (
$cache_enabled
&& $wp_cache_mod_rewrite
&& ! $wp_cache_mobile_enabled
&& strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) )
) {
echo '<div class="notice notice-warning"><h4>' . esc_html__( 'Mobile rewrite rules detected', 'wp-super-cache' ) . '</h4>';
echo '<p>' . esc_html__( 'For best performance you should enable "Mobile device support" or delete the mobile rewrite rules in your .htaccess. Look for the 2 lines with the text "2.0\ MMP|240x320" and delete those.', 'wp-super-cache' ) . '</p><p>' . esc_html__( 'This will have no affect on ordinary users but mobile users will see uncached pages.', 'wp-super-cache' ) . '</p></div>';
} elseif (
$wp_cache_mod_rewrite
&& $cache_enabled
&& $wp_cache_mobile_enabled
&& $scrules != '' // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual
&& (
(
'' != $wp_cache_mobile_prefixes // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual
&& ! str_contains( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_prefixes ), ' ' ) )
)
|| (
'' != $wp_cache_mobile_browsers // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual
&& ! str_contains( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) )
)
)
) {
?>
<div class="notice notice-warning"><h4><?php _e( 'Rewrite rules must be updated', 'wp-super-cache' ); ?></h4>
<p><?php _e( 'The rewrite rules required by this plugin have changed or are missing. ', 'wp-super-cache' ); ?>
<?php _e( 'Mobile support requires extra rules in your .htaccess file, or you can set the plugin to simple mode. Here are your options (in order of difficulty):', 'wp-super-cache' ); ?>
<ol><li> <?php _e( 'Set the plugin to simple mode and enable mobile support.', 'wp-super-cache' ); ?></li>
<li> <?php _e( 'Scroll down the Advanced Settings page and click the <strong>Update Mod_Rewrite Rules</strong> button.', 'wp-super-cache' ); ?></li>
<li> <?php printf( __( 'Delete the plugin mod_rewrite rules in %s.htaccess enclosed by <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code> and let the plugin regenerate them by reloading this page.', 'wp-super-cache' ), $home_path ); ?></li>
<li> <?php printf( __( 'Add the rules yourself. Edit %s.htaccess and find the block of code enclosed by the lines <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code>. There are two sections that look very similar. Just below the line <code>%%{HTTP:Cookie} !^.*(comment_author_|%s|wp-postpass_).*$</code> add these lines: (do it twice, once for each section)', 'wp-super-cache' ), $home_path, wpsc_get_logged_in_cookie() ); ?></p>
<div style='padding: 2px; margin: 2px; border: 1px solid #333; width:400px; overflow: scroll'><pre><?php echo "RewriteCond %{HTTP_user_agent} !^.*(" . addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) . ").*\nRewriteCond %{HTTP_user_agent} !^(" . addcslashes( str_replace( ', ', '|', $wp_cache_mobile_prefixes ), ' ' ) . ").*"; ?></pre></div></li></ol></div><?php
}
if (
$cache_enabled
&& $super_cache_enabled
&& $wp_cache_mod_rewrite
&& $scrules == '' // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
) {
?>
<div class='notice notice-warning'><h4><?php esc_html_e( 'Rewrite rules must be updated', 'wp-super-cache' ); ?></h4>
<p><?php esc_html_e( 'The rewrite rules required by this plugin have changed or are missing. ', 'wp-super-cache' ); ?>
<?php esc_html_e( 'Scroll down the Advanced Settings page and click the <strong>Update Mod_Rewrite Rules</strong> button.', 'wp-super-cache' ); ?></p></div>
<?php
}
}
if ( ! $is_nginx && $wp_cache_mod_rewrite && $super_cache_enabled && function_exists( 'apache_get_modules' ) ) {
$mods = apache_get_modules();
$required_modules = array( 'mod_mime' => __( 'Required to serve compressed supercache files properly.', 'wp-super-cache' ), 'mod_headers' => __( 'Required to set caching information on supercache pages. IE7 users will see old pages without this module.', 'wp-super-cache' ), 'mod_expires' => __( 'Set the expiry date on supercached pages. Visitors may not see new pages when they refresh or leave comments without this module.', 'wp-super-cache' ) );
foreach( $required_modules as $req => $desc ) {
if( !in_array( $req, $mods ) ) {
$missing_mods[ $req ] = $desc;
}
}
if( isset( $missing_mods) && is_array( $missing_mods ) ) {
?><div class='notice notice-warning'><h4><?php _e( 'Missing Apache Modules', 'wp-super-cache' ); ?></h4>
<p><?php __( 'The following Apache modules are missing. The plugin will work in simple mode without them but in expert mode, your visitors may see corrupted pages or out of date content however.', 'wp-super-cache' ); ?></p><?php
echo "<ul>";
foreach( $missing_mods as $req => $desc ) {
echo "<li> $req - $desc</li>";
}
echo "</ul>";
echo "</div>";
}
}
if ( $valid_nonce && isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'dismiss_htaccess_warning' ) {
wp_cache_replace_line('^ *\$dismiss_htaccess_warning', "\$dismiss_htaccess_warning = 1;", $wp_cache_config_file);
$dismiss_htaccess_warning = 1;
} elseif ( !isset( $dismiss_htaccess_warning ) ) {
$dismiss_htaccess_warning = 0;
}
if ( isset( $disable_supercache_htaccess_warning ) == false )
$disable_supercache_htaccess_warning = false;
if ( ! $is_nginx && $dismiss_htaccess_warning == 0 && $wp_cache_mod_rewrite && $super_cache_enabled && $disable_supercache_htaccess_warning == false && get_option( 'siteurl' ) != get_option( 'home' ) ) {
?><div class="notice notice-info"><h4><?php _e( '.htaccess file may need to be moved', 'wp-super-cache' ); ?></h4>
<p><?php _e( 'It appears you have WordPress installed in a sub directory as described <a href="https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory">here</a>. Unfortunately, WordPress writes to the .htaccess in the install directory, not where your site is served from.<br />When you update the rewrite rules in this plugin you will have to copy the file to where your site is hosted. This will be fixed in the future.', 'wp-super-cache' ); ?></p>
<form action="" method="POST">
<input type="hidden" name="action" value="dismiss_htaccess_warning" />
<input type="hidden" name="page" value="wpsupercache" />
<?php wp_nonce_field( 'wp-cache' ); ?>
<input class='button-secondary' type='submit' value='<?php _e( 'Dismiss', 'wp-super-cache' ); ?>' />
</form>
<br />
</div><?php
}
return true;
}
add_filter( 'wp_super_cache_error_checking', 'wp_cache_manager_error_checks' );
function wp_cache_manager_updates() {
global $wp_cache_mobile_enabled, $wp_cache_mfunc_enabled, $wp_supercache_cache_list, $wp_cache_config_file, $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_not_logged_in, $wp_cache_make_known_anon, $cache_path, $wp_cache_refresh_single_only, $cache_compression, $wp_cache_mod_rewrite, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $cache_page_secret, $wp_cache_disable_utf8, $wp_cache_no_cache_for_get;
global $cache_schedule_type, $cache_max_time, $cache_time_interval, $wp_cache_shutdown_gc, $wpsc_save_headers;
if ( !wpsupercache_site_admin() )
return false;
if ( false == isset( $cache_page_secret ) ) {
$cache_page_secret = md5( date( 'H:i:s' ) . mt_rand() );
wp_cache_replace_line('^ *\$cache_page_secret', "\$cache_page_secret = '" . $cache_page_secret . "';", $wp_cache_config_file);
}
$valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
if ( $valid_nonce == false )
return false;
if ( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'easysetup' ) {
$_POST[ 'action' ] = 'scupdates';
if( isset( $_POST[ 'wp_cache_easy_on' ] ) && $_POST[ 'wp_cache_easy_on' ] == 1 ) {
$_POST[ 'wp_cache_enabled' ] = 1;
$_POST[ 'super_cache_enabled' ] = 1;
$_POST[ 'cache_rebuild_files' ] = 1;
unset( $_POST[ 'cache_compression' ] );
if ( $cache_path != WP_CONTENT_DIR . '/cache/' )
$_POST[ 'wp_cache_location' ] = $cache_path;
//
// set up garbage collection with some default settings
if ( ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) {
if ( false == isset( $cache_schedule_type ) ) {
$cache_schedule_type = 'interval';
$cache_time_interval = 600;
$cache_max_time = 1800;
wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
wp_cache_replace_line('^ *\$cache_time_interval', "\$cache_time_interval = '$cache_time_interval';", $wp_cache_config_file);
wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = '$cache_max_time';", $wp_cache_config_file);
}
wp_schedule_single_event( time() + 600, 'wp_cache_gc' );
}
} else {
unset( $_POST[ 'wp_cache_enabled' ] );
wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
wp_clear_scheduled_hook( 'wp_cache_gc' );
wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
}
$advanced_settings = array( 'wp_super_cache_late_init', 'wp_cache_disable_utf8', 'wp_cache_no_cache_for_get', 'wp_supercache_304', 'wp_cache_mfunc_enabled', 'wp_cache_front_page_checks', 'wp_supercache_cache_list', 'wp_cache_clear_on_post_edit', 'wp_cache_make_known_anon', 'wp_cache_refresh_single_only', 'cache_compression' );
foreach( $advanced_settings as $setting ) {
if ( isset( $GLOBALS[ $setting ] ) && $GLOBALS[ $setting ] == 1 ) {
$_POST[ $setting ] = 1;
}
}
$_POST['wp_cache_not_logged_in'] = 2;
}
if( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'scupdates' ) {
if( isset( $_POST[ 'wp_cache_location' ] ) && $_POST[ 'wp_cache_location' ] != '' ) {
$dir = realpath( trailingslashit( dirname( $_POST[ 'wp_cache_location' ] ) ) );
if ( $dir === realpath( '.' ) || false === $dir ) {
$dir = WP_CONTENT_DIR . '/cache/';
} else {
$dir = trailingslashit( $dir ) . trailingslashit(wpsc_deep_replace( array( '..', '\\' ), basename( $_POST[ 'wp_cache_location' ] ) ) );
}
$new_cache_path = $dir;
} else {
$new_cache_path = WP_CONTENT_DIR . '/cache/';
}
if ( $new_cache_path != $cache_path ) {
if ( file_exists( $new_cache_path ) == false )
rename( $cache_path, $new_cache_path );
$cache_path = preg_replace('/[ <>\'\"\r\n\t\(\)\$\[\];#]/', '', $new_cache_path );
wp_cache_replace_line('^ *\$cache_path', "\$cache_path = " . var_export( $cache_path, true ) . ";", $wp_cache_config_file);
}
if( isset( $_POST[ 'wp_super_cache_late_init' ] ) ) {
$wp_super_cache_late_init = 1;
} else {
$wp_super_cache_late_init = 0;
}
wp_cache_replace_line('^ *\$wp_super_cache_late_init', "\$wp_super_cache_late_init = " . $wp_super_cache_late_init . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_cache_disable_utf8' ] ) ) {
$wp_cache_disable_utf8 = 1;
} else {
$wp_cache_disable_utf8 = 0;
}
wp_cache_replace_line('^ *\$wp_cache_disable_utf8', "\$wp_cache_disable_utf8 = " . $wp_cache_disable_utf8 . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_cache_no_cache_for_get' ] ) ) {
$wp_cache_no_cache_for_get = 1;
} else {
$wp_cache_no_cache_for_get = 0;
}
wp_cache_replace_line('^ *\$wp_cache_no_cache_for_get', "\$wp_cache_no_cache_for_get = " . $wp_cache_no_cache_for_get . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_supercache_304' ] ) ) {
$wp_supercache_304 = 1;
} else {
$wp_supercache_304 = 0;
}
wp_cache_replace_line('^ *\$wp_supercache_304', "\$wp_supercache_304 = " . $wp_supercache_304 . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_cache_mfunc_enabled' ] ) ) {
$wp_cache_mfunc_enabled = 1;
} else {
$wp_cache_mfunc_enabled = 0;
}
wp_cache_replace_line('^ *\$wp_cache_mfunc_enabled', "\$wp_cache_mfunc_enabled = " . $wp_cache_mfunc_enabled . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_cache_mobile_enabled' ] ) ) {
$wp_cache_mobile_enabled = 1;
} else {
$wp_cache_mobile_enabled = 0;
}
wp_cache_replace_line('^ *\$wp_cache_mobile_enabled', "\$wp_cache_mobile_enabled = " . $wp_cache_mobile_enabled . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_cache_front_page_checks' ] ) ) {
$wp_cache_front_page_checks = 1;
} else {
$wp_cache_front_page_checks = 0;
}
wp_cache_replace_line('^ *\$wp_cache_front_page_checks', "\$wp_cache_front_page_checks = " . $wp_cache_front_page_checks . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_supercache_cache_list' ] ) ) {
$wp_supercache_cache_list = 1;
} else {
$wp_supercache_cache_list = 0;
}
wp_cache_replace_line('^ *\$wp_supercache_cache_list', "\$wp_supercache_cache_list = " . $wp_supercache_cache_list . ";", $wp_cache_config_file);
if ( isset( $_POST[ 'wp_cache_enabled' ] ) ) {
wp_cache_enable();
if ( ! defined( 'DISABLE_SUPERCACHE' ) ) {
wp_cache_debug( 'DISABLE_SUPERCACHE is not set, super_cache enabled.' );
wp_super_cache_enable();
$super_cache_enabled = true;
}
} else {
wp_cache_disable();
wp_super_cache_disable();
$super_cache_enabled = false;
}
if ( isset( $_POST[ 'wp_cache_mod_rewrite' ] ) && $_POST[ 'wp_cache_mod_rewrite' ] == 1 ) {
$wp_cache_mod_rewrite = 1;
add_mod_rewrite_rules();
} else {
$wp_cache_mod_rewrite = 0; // cache files served by PHP
remove_mod_rewrite_rules();
}
wp_cache_setting( 'wp_cache_mod_rewrite', $wp_cache_mod_rewrite );
if( isset( $_POST[ 'wp_cache_clear_on_post_edit' ] ) ) {
$wp_cache_clear_on_post_edit = 1;
} else {
$wp_cache_clear_on_post_edit = 0;
}
wp_cache_replace_line('^ *\$wp_cache_clear_on_post_edit', "\$wp_cache_clear_on_post_edit = " . $wp_cache_clear_on_post_edit . ";", $wp_cache_config_file);
if( isset( $_POST[ 'cache_rebuild_files' ] ) ) {
$cache_rebuild_files = 1;
} else {
$cache_rebuild_files = 0;
}
wp_cache_replace_line('^ *\$cache_rebuild_files', "\$cache_rebuild_files = " . $cache_rebuild_files . ";", $wp_cache_config_file);
if ( isset( $_POST[ 'wpsc_save_headers' ] ) ) {
$wpsc_save_headers = 1;
} else {
$wpsc_save_headers = 0;
}
wp_cache_replace_line('^ *\$wpsc_save_headers', "\$wpsc_save_headers = " . $wpsc_save_headers . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_cache_mutex_disabled' ] ) ) {
$wp_cache_mutex_disabled = 0;
} else {
$wp_cache_mutex_disabled = 1;
}
if( defined( 'WPSC_DISABLE_LOCKING' ) ) {
$wp_cache_mutex_disabled = 1;
}
wp_cache_replace_line('^ *\$wp_cache_mutex_disabled', "\$wp_cache_mutex_disabled = " . $wp_cache_mutex_disabled . ";", $wp_cache_config_file);
if ( isset( $_POST['wp_cache_not_logged_in'] ) && $_POST['wp_cache_not_logged_in'] != 0 ) {
if ( $wp_cache_not_logged_in == 0 && function_exists( 'prune_super_cache' ) ) {
prune_super_cache( $cache_path, true );
}
$wp_cache_not_logged_in = (int)$_POST['wp_cache_not_logged_in'];
} else {
$wp_cache_not_logged_in = 0;
}
wp_cache_replace_line('^ *\$wp_cache_not_logged_in', "\$wp_cache_not_logged_in = " . $wp_cache_not_logged_in . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_cache_make_known_anon' ] ) ) {
if( $wp_cache_make_known_anon == 0 && function_exists( 'prune_super_cache' ) )
prune_super_cache ($cache_path, true);
$wp_cache_make_known_anon = 1;
} else {
$wp_cache_make_known_anon = 0;
}
wp_cache_replace_line('^ *\$wp_cache_make_known_anon', "\$wp_cache_make_known_anon = " . $wp_cache_make_known_anon . ";", $wp_cache_config_file);
if( isset( $_POST[ 'wp_cache_refresh_single_only' ] ) ) {
$wp_cache_refresh_single_only = 1;
} else {
$wp_cache_refresh_single_only = 0;
}
wp_cache_setting( 'wp_cache_refresh_single_only', $wp_cache_refresh_single_only );
if ( defined( 'WPSC_DISABLE_COMPRESSION' ) ) {
$cache_compression = 0;
wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
} else {
if ( isset( $_POST[ 'cache_compression' ] ) ) {
$new_cache_compression = 1;
} else {
$new_cache_compression = 0;
}
if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) {
echo '<div class="notice notice-error">' . __( "<strong>Warning!</strong> You attempted to enable compression but <code>zlib.output_compression</code> is enabled. See #21 in the Troubleshooting section of the readme file.", 'wp-super-cache' ) . '</div>';
} elseif ( $new_cache_compression !== (int) $cache_compression ) {
$cache_compression = $new_cache_compression;
wp_cache_replace_line( '^ *\$cache_compression', "\$cache_compression = $cache_compression;", $wp_cache_config_file );
if ( function_exists( 'prune_super_cache' ) ) {
prune_super_cache( $cache_path, true );
}
delete_option( 'super_cache_meta' );
}
}
}
}
if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'wpsupercache' )
add_action( 'admin_init', 'wp_cache_manager_updates' );
function wp_cache_manager() {
global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled;
global $wp_cache_clear_on_post_edit, $cache_rebuild_files, $wp_cache_mutex_disabled, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_no_cache_for_get;
global $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_supercache_cache_list, $cache_page_secret;
global $wp_super_cache_front_page_check, $wp_cache_refresh_single_only, $wp_cache_mobile_prefixes;
global $wp_cache_mod_rewrite, $wp_supercache_304, $wp_super_cache_late_init, $wp_cache_front_page_checks, $wp_cache_disable_utf8, $wp_cache_mfunc_enabled;
global $wp_super_cache_comments, $wp_cache_home_path, $wpsc_save_headers, $is_nginx;
global $wpsc_promo_links;
if ( !wpsupercache_site_admin() )
return false;
// used by mod_rewrite rules and config file
if ( function_exists( "cfmobi_default_browsers" ) ) {
$wp_cache_mobile_browsers = cfmobi_default_browsers( "mobile" );
$wp_cache_mobile_browsers = array_merge( $wp_cache_mobile_browsers, cfmobi_default_browsers( "touch" ) );
} elseif ( function_exists( 'lite_detection_ua_contains' ) ) {
$wp_cache_mobile_browsers = explode( '|', lite_detection_ua_contains() );
} else {
$wp_cache_mobile_browsers = array( '2.0 MMP', '240x320', '400X240', 'AvantGo', 'BlackBerry', 'Blazer', 'Cellphone', 'Danger', 'DoCoMo', 'Elaine/3.0', 'EudoraWeb', 'Googlebot-Mobile', 'hiptop', 'IEMobile', 'KYOCERA/WX310K', 'LG/U990', 'MIDP-2.', 'MMEF20', 'MOT-V', 'NetFront', 'Newt', 'Nintendo Wii', 'Nitro', 'Nokia', 'Opera Mini', 'Palm', 'PlayStation Portable', 'portalmmm', 'Proxinet', 'ProxiNet', 'SHARP-TQ-GX10', 'SHG-i900', 'Small', 'SonyEricsson', 'Symbian OS', 'SymbianOS', 'TS21i-10', 'UP.Browser', 'UP.Link', 'webOS', 'Windows CE', 'WinWAP', 'YahooSeeker/M1A1-R2D2', 'iPhone', 'iPod', 'iPad', 'Android', 'BlackBerry9530', 'LG-TU915 Obigo', 'LGE VX', 'webOS', 'Nokia5800' );
}
if ( function_exists( "lite_detection_ua_prefixes" ) ) {
$wp_cache_mobile_prefixes = lite_detection_ua_prefixes();
} else {
$wp_cache_mobile_prefixes = array( 'w3c ', 'w3c-', 'acs-', 'alav', 'alca', 'amoi', 'audi', 'avan', 'benq', 'bird', 'blac', 'blaz', 'brew', 'cell', 'cldc', 'cmd-', 'dang', 'doco', 'eric', 'hipt', 'htc_', 'inno', 'ipaq', 'ipod', 'jigs', 'kddi', 'keji', 'leno', 'lg-c', 'lg-d', 'lg-g', 'lge-', 'lg/u', 'maui', 'maxo', 'midp', 'mits', 'mmef', 'mobi', 'mot-', 'moto', 'mwbp', 'nec-', 'newt', 'noki', 'palm', 'pana', 'pant', 'phil', 'play', 'port', 'prox', 'qwap', 'sage', 'sams', 'sany', 'sch-', 'sec-', 'send', 'seri', 'sgh-', 'shar', 'sie-', 'siem', 'smal', 'smar', 'sony', 'sph-', 'symb', 't-mo', 'teli', 'tim-', 'tosh', 'tsm-', 'upg1', 'upsi', 'vk-v', 'voda', 'wap-', 'wapa', 'wapi', 'wapp', 'wapr', 'webc', 'winw', 'winw', 'xda ', 'xda-' ); // from http://svn.wp-plugins.org/wordpress-mobile-pack/trunk/plugins/wpmp_switcher/lite_detection.php
}
$wp_cache_mobile_browsers = apply_filters( 'cached_mobile_browsers', $wp_cache_mobile_browsers ); // Allow mobile plugins access to modify the mobile UA list
$wp_cache_mobile_prefixes = apply_filters( 'cached_mobile_prefixes', $wp_cache_mobile_prefixes ); // Allow mobile plugins access to modify the mobile UA prefix list
if ( function_exists( 'do_cacheaction' ) ) {
$wp_cache_mobile_browsers = do_cacheaction( 'wp_super_cache_mobile_browsers', $wp_cache_mobile_browsers );
$wp_cache_mobile_prefixes = do_cacheaction( 'wp_super_cache_mobile_prefixes', $wp_cache_mobile_prefixes );
}
$mobile_groups = apply_filters( 'cached_mobile_groups', array() ); // Group mobile user agents by capabilities. Lump them all together by default