PluginProbe ʕ •ᴥ•ʔ
WP Super Cache / 2.0.0
WP Super Cache v2.0.0
3.1.1 trunk 0.1 0.2 0.3 0.3.1 0.4 0.5 0.5.1 0.5.2 0.5.3 0.6.2 0.6.3 0.6.4 0.6.5 0.6.6 0.6.7 0.6.8 0.7 0.7.1 0.8 0.8.1 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.8.8 0.8.9 0.9 0.9.1 0.9.2 0.9.3 0.9.3.1 0.9.4 0.9.4.1 0.9.4.2 0.9.4.3 0.9.5 0.9.6 0.9.6.1 0.9.7 0.9.8 0.9.9 0.9.9.1 0.9.9.2 0.9.9.3 0.9.9.4 0.9.9.5 0.9.9.6 0.9.9.7 0.9.9.8 0.9.9.9 1.0 1.0.1 1.1 1.1.1 1.10.0 1.11.0 1.12.0 1.12.1 1.12.2 1.12.3 1.12.4 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.7.1 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8 1.9 1.9.1 1.9.2 1.9.3 1.9.4 2.0.0 2.0.1 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0
wp-super-cache / wp-cache.php
wp-super-cache Last commit date
assets 1 year ago inc 1 year ago js 1 year ago languages 2 years ago partials 1 year ago plugins 3 years ago rest 2 years ago src 3 years ago styling 1 year ago vendor 1 year ago CHANGELOG.md 1 year ago LICENSE.txt 3 years ago README.md 2 years ago SECURITY.md 2 years ago advanced-cache.php 2 years ago composer.json 1 year ago composer.lock 1 year ago ossdl-cdn.php 2 years ago package.json 1 year ago readme.txt 1 year ago wp-cache-base.php 2 years ago wp-cache-config-sample.php 4 years ago wp-cache-phase1.php 2 years ago wp-cache-phase2.php 1 year ago wp-cache.php 1 year ago
wp-cache.php
4441 lines
1 <?php
2 /*
3 * Plugin Name: WP Super Cache
4 * Plugin URI: https://wordpress.org/plugins/wp-super-cache/
5 * Description: Very fast caching plugin for WordPress.
6 * Version: 2.0.0
7 * Author: Automattic
8 * Author URI: https://automattic.com/
9 * License: GPL2+
10 * License URI: https://www.gnu.org/licenses/gpl-2.0.txt
11 * Text Domain: wp-super-cache
12 */
13
14 /*
15 Copyright Automattic and many other contributors.
16
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation; either version 2 of the License, or
20 (at your option) any later version.
21
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
26
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 */
31
32 define( 'WPSC_VERSION_ID', '1.12.1' );
33
34 require_once( __DIR__. '/inc/delete-cache-button.php');
35 require_once( __DIR__. '/inc/preload-notification.php');
36 require_once __DIR__ . '/inc/boost.php';
37
38 if ( ! function_exists( 'wp_cache_phase2' ) ) {
39 require_once( __DIR__. '/wp-cache-phase2.php');
40 }
41
42 if ( ! defined( 'PHP_VERSION_ID' ) ) {
43 // For versions of PHP below 5.2.7, this constant doesn't exist.
44 $wpsc_php_version = explode( '.', PHP_VERSION );
45 define( 'PHP_VERSION_ID', intval( $wpsc_php_version[0] * 10000 + $wpsc_php_version[1] * 100 + $wpsc_php_version[2] ) );
46 unset( $wpsc_php_version );
47 }
48
49 /**
50 * Defines how many posts to preload per loop.
51 */
52 if ( ! defined( 'WPSC_PRELOAD_POST_COUNT' ) ) {
53 define( 'WPSC_PRELOAD_POST_COUNT', 10 );
54 }
55
56 /**
57 * Defines the interval in seconds between preloading pages.
58 */
59 if ( ! defined( 'WPSC_PRELOAD_POST_INTERVAL' ) ) {
60 define( 'WPSC_PRELOAD_POST_INTERVAL', 1 );
61 }
62
63 /**
64 * Defines the interval in seconds between preloading loops.
65 */
66 if ( ! defined( 'WPSC_PRELOAD_LOOP_INTERVAL' ) ) {
67 define( 'WPSC_PRELOAD_LOOP_INTERVAL', 0 );
68 }
69
70 function wpsc_init() {
71 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;
72
73 if ( ! defined( 'WPCACHECONFIGPATH' ) ) {
74 define( 'WPCACHECONFIGPATH', WP_CONTENT_DIR );
75 }
76
77 $wp_cache_config_file = WPCACHECONFIGPATH . '/wp-cache-config.php';
78
79 // Centralise the promotional links to other products
80 $wpsc_promo_links = array(
81 'boost' => 'https://jetpack.com/boost/?utm_source=wporg&utm_medium=plugin&utm_campaign=wp-super-cache&utm_id=wp-super-cache',
82 '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',
83 'videopress' => 'https://jetpack.com/videopress/?utm_source=wporg&utm_medium=plugin&utm_campaign=wp-super-cache&utm_id=wp-super-cache',
84 'crowdsignal' => 'https://crowdsignal.com/?utm_source=wporg&utm_medium=plugin&utm_campaign=wp-super-cache&utm_id=wp-super-cache',
85 'jetpack' => 'https://jetpack.com/?utm_source=wporg&utm_medium=plugin&utm_campaign=wp-super-cache&utm_id=wp-super-cache',
86 );
87
88 if ( !defined( 'WPCACHEHOME' ) ) {
89 define( 'WPCACHEHOME', __DIR__ . '/' );
90 $wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
91 $wpsc_advanced_cache_dist_filename = WPCACHEHOME . 'advanced-cache.php';
92 } elseif ( realpath( WPCACHEHOME ) != realpath( __DIR__ ) ) {
93 $wp_cache_config_file_sample = __DIR__. '/wp-cache-config-sample.php';
94 $wpsc_advanced_cache_dist_filename = __DIR__. '/advanced-cache.php';
95 if ( ! defined( 'ADVANCEDCACHEPROBLEM' ) ) {
96 define( 'ADVANCEDCACHEPROBLEM', 1 ); // force an update of WPCACHEHOME
97 }
98 } else {
99 $wp_cache_config_file_sample = WPCACHEHOME . 'wp-cache-config-sample.php';
100 $wpsc_advanced_cache_dist_filename = WPCACHEHOME . 'advanced-cache.php';
101 }
102 $wpsc_advanced_cache_filename = WP_CONTENT_DIR . '/advanced-cache.php';
103
104 if ( !defined( 'WP_CACHE' ) || ( defined( 'WP_CACHE' ) && constant( 'WP_CACHE' ) == false ) ) {
105 $wp_cache_check_wp_config = true;
106 }
107 }
108
109 wpsc_init();
110
111 /**
112 * WP-CLI requires explicit declaration of global variables.
113 * It's minimal list of global variables.
114 */
115 global $super_cache_enabled, $cache_enabled, $wp_cache_mod_rewrite, $wp_cache_home_path, $cache_path, $file_prefix;
116 global $wp_cache_mutex_disabled, $mutex_filename, $sem_id, $wp_super_cache_late_init;
117 global $cache_compression, $cache_max_time, $wp_cache_shutdown_gc, $cache_rebuild_files;
118 global $wp_super_cache_debug, $wp_super_cache_advanced_debug, $wp_cache_debug_level, $wp_cache_debug_to_file;
119 global $wp_cache_debug_log, $wp_cache_debug_ip, $wp_cache_debug_username, $wp_cache_debug_email;
120 global $cache_time_interval, $cache_scheduled_time, $cache_schedule_interval, $cache_schedule_type, $cache_gc_email_me;
121 global $wp_cache_preload_on, $wp_cache_preload_interval, $wp_cache_preload_posts, $wp_cache_preload_taxonomies;
122
123 // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- these are used by various functions but the linter complains.
124 global $wp_cache_preload_email_me, $wp_cache_preload_email_volume;
125 global $wp_cache_mobile, $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes;
126 global $wp_cache_config_file, $wp_cache_config_file_sample;
127
128 // Check is cache config already loaded.
129 if ( ! isset( $cache_enabled, $super_cache_enabled, $wp_cache_mod_rewrite, $cache_path ) &&
130 empty( $wp_cache_phase1_loaded ) &&
131 // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
132 ! @include( $wp_cache_config_file )
133 ) {
134 @include $wp_cache_config_file_sample; // phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
135 }
136
137 include(WPCACHEHOME . 'wp-cache-base.php');
138 if ( class_exists( 'WP_REST_Controller' ) ) {
139 include( __DIR__. '/rest/load.php' );
140 }
141
142 function wp_super_cache_init_action() {
143
144 load_plugin_textdomain( 'wp-super-cache', false, basename( __DIR__ ) . '/languages' );
145
146 wpsc_register_post_hooks();
147 }
148 add_action( 'init', 'wp_super_cache_init_action' );
149
150 function wp_cache_set_home() {
151 global $wp_cache_is_home;
152 $wp_cache_is_home = ( is_front_page() || is_home() );
153 if ( $wp_cache_is_home && is_paged() )
154 $wp_cache_is_home = false;
155 }
156 add_action( 'template_redirect', 'wp_cache_set_home' );
157
158 function wpsc_enqueue_styles() {
159 wp_enqueue_style(
160 'wpsc_styles',
161 plugins_url( 'styling/dashboard.css', __FILE__ ),
162 array(),
163 filemtime( plugin_dir_path( __FILE__ ) . 'styling/dashboard.css' )
164 );
165 }
166
167 // Check for the page parameter to see if we're on a WPSC page.
168 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
169 if ( isset( $_GET['page'] ) && $_GET['page'] === 'wpsupercache' ) {
170 add_action( 'admin_enqueue_scripts', 'wpsc_enqueue_styles' );
171 }
172
173 // OSSDL CDN plugin (https://wordpress.org/plugins/ossdl-cdn-off-linker/)
174 include_once( WPCACHEHOME . 'ossdl-cdn.php' );
175
176 function get_wpcachehome() {
177 if ( function_exists( '_deprecated_function' ) ) {
178 _deprecated_function( __FUNCTION__, 'WP Super Cache 1.6.5' );
179 }
180
181 if ( ! defined( 'WPCACHEHOME' ) ) {
182 if ( is_file( __DIR__ . '/wp-cache-config-sample.php' ) ) {
183 define( 'WPCACHEHOME', trailingslashit( __DIR__ ) );
184 } elseif ( is_file( __DIR__ . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
185 define( 'WPCACHEHOME', __DIR__ . '/wp-super-cache/' );
186 } else {
187 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 ) ) );
188 }
189 }
190 }
191
192 function wpsc_remove_advanced_cache() {
193 global $wpsc_advanced_cache_filename;
194 if ( file_exists( $wpsc_advanced_cache_filename ) ) {
195 $file = file_get_contents( $wpsc_advanced_cache_filename );
196 if (
197 strpos( $file, "WP SUPER CACHE 0.8.9.1" ) ||
198 strpos( $file, "WP SUPER CACHE 1.2" )
199 ) {
200 unlink( $wpsc_advanced_cache_filename );
201 }
202 }
203 }
204
205 function wpsupercache_uninstall() {
206 global $wp_cache_config_file, $cache_path;
207
208 wpsc_remove_advanced_cache();
209
210 if ( file_exists( $wp_cache_config_file ) ) {
211 unlink( $wp_cache_config_file );
212 }
213
214 wp_cache_remove_index();
215
216 if ( ! empty( $cache_path ) ) {
217 @unlink( $cache_path . '.htaccess' );
218 @unlink( $cache_path . 'meta' );
219 @unlink( $cache_path . 'supercache' );
220 }
221
222 wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
223 wp_clear_scheduled_hook( 'wp_cache_gc' );
224 wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
225 wp_cache_disable_plugin();
226 delete_site_option( 'wp_super_cache_index_detected' );
227 }
228 if ( is_admin() ) {
229 register_uninstall_hook( __FILE__, 'wpsupercache_uninstall' );
230 }
231
232 function wpsupercache_deactivate() {
233 global $wp_cache_config_file, $wpsc_advanced_cache_filename, $cache_path;
234
235 wpsc_remove_advanced_cache();
236
237 if ( ! empty( $cache_path ) ) {
238 prune_super_cache( $cache_path, true );
239 wp_cache_remove_index();
240 @unlink( $cache_path . '.htaccess' );
241 @unlink( $cache_path . 'meta' );
242 @unlink( $cache_path . 'supercache' );
243 }
244
245 wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
246 wp_clear_scheduled_hook( 'wp_cache_gc' );
247 wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
248 wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = false;', $wp_cache_config_file);
249 wp_cache_disable_plugin( false ); // don't delete configuration file
250 delete_user_option( get_current_user_id(), 'wpsc_dismissed_boost_banner' );
251 }
252 register_deactivation_hook( __FILE__, 'wpsupercache_deactivate' );
253
254 function wpsupercache_activate() {
255 global $cache_path;
256 if ( ! isset( $cache_path ) || $cache_path == '' )
257 $cache_path = WP_CONTENT_DIR . '/cache/'; // from sample config file
258
259 ob_start();
260 wpsc_init();
261
262 if (
263 ! wp_cache_verify_cache_dir() ||
264 ! wpsc_check_advanced_cache() ||
265 ! wp_cache_verify_config_file()
266 ) {
267 $text = ob_get_contents();
268 ob_end_clean();
269 return false;
270 }
271 $text = ob_get_contents();
272 wp_cache_check_global_config();
273 ob_end_clean();
274 wp_schedule_single_event( time() + 10, 'wp_cache_add_site_cache_index' );
275 }
276 register_activation_hook( __FILE__, 'wpsupercache_activate' );
277
278 function wpsupercache_site_admin() {
279 return current_user_can( 'setup_network' );
280 }
281
282 function wp_cache_add_pages() {
283 if ( wpsupercache_site_admin() ) {
284 // In single or MS mode add this menu item too, but only for superadmins in MS mode.
285 add_options_page( 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager' );
286 }
287 }
288 add_action( 'admin_menu', 'wp_cache_add_pages' );
289
290
291 function wp_cache_network_pages() {
292 add_submenu_page( 'settings.php', 'WP Super Cache', 'WP Super Cache', 'manage_options', 'wpsupercache', 'wp_cache_manager' );
293 }
294 add_action( 'network_admin_menu', 'wp_cache_network_pages' );
295
296 /**
297 * Load JavaScript on admin pages.
298 */
299 function wp_super_cache_admin_enqueue_scripts( $hook ) {
300 if ( 'settings_page_wpsupercache' !== $hook ) {
301 return;
302 }
303
304 wp_enqueue_script(
305 'wp-super-cache-admin',
306 trailingslashit( plugin_dir_url( __FILE__ ) ) . 'js/admin.js',
307 array( 'jquery' ),
308 WPSC_VERSION_ID,
309 false
310 );
311
312 wp_localize_script(
313 'wp-super-cache-admin',
314 'wpscAdmin',
315 array(
316 'boostNoticeDismissNonce' => wp_create_nonce( 'wpsc_dismiss_boost_notice' ),
317 'boostDismissNonce' => wp_create_nonce( 'wpsc_dismiss_boost_banner' ),
318 'boostInstallNonce' => wp_create_nonce( 'updates' ),
319 'boostActivateNonce' => wp_create_nonce( 'activate-boost' ),
320 )
321 );
322 }
323 add_action( 'admin_enqueue_scripts', 'wp_super_cache_admin_enqueue_scripts' );
324
325 /**
326 * Use the standard WordPress plugin installation ajax handler.
327 */
328 add_action( 'wp_ajax_wpsc_install_plugin', 'wp_ajax_install_plugin' );
329
330 /**
331 * Check if Jetpack Boost has been installed.
332 */
333 function wpsc_is_boost_installed() {
334 $plugins = array_keys( get_plugins() );
335
336 foreach ( $plugins as $plugin ) {
337 if ( str_contains( $plugin, 'jetpack-boost/jetpack-boost.php' ) ) {
338 return true;
339 }
340 }
341
342 return false;
343 }
344
345 /**
346 * Check if Jetpack Boost is active.
347 */
348 function wpsc_is_boost_active() {
349 return class_exists( '\Automattic\Jetpack_Boost\Jetpack_Boost' );
350 }
351
352 /**
353 * Admin ajax action: hide the Boost Banner.
354 */
355 function wpsc_hide_boost_banner() {
356 check_ajax_referer( 'wpsc_dismiss_boost_banner', 'nonce' );
357 update_user_option( get_current_user_id(), 'wpsc_dismissed_boost_banner', '1' );
358
359 wp_die();
360 }
361 add_action( 'wp_ajax_wpsc-hide-boost-banner', 'wpsc_hide_boost_banner' );
362
363 /**
364 * Admin ajax action: activate Jetpack Boost.
365 */
366 function wpsc_ajax_activate_boost() {
367 check_ajax_referer( 'activate-boost' );
368
369 if ( ! isset( $_POST['source'] ) ) {
370 wp_send_json_error( 'no source specified' );
371 }
372
373 $source = sanitize_text_field( wp_unslash( $_POST['source'] ) );
374 $result = activate_plugin( 'jetpack-boost/jetpack-boost.php' );
375 if ( is_wp_error( $result ) ) {
376 wp_send_json_error( $result->get_error_message() );
377 }
378
379 wpsc_notify_migration_to_boost( $source );
380
381 wp_send_json_success();
382 }
383 add_action( 'wp_ajax_wpsc_activate_boost', 'wpsc_ajax_activate_boost' );
384
385 /**
386 * Show a Jetpack Boost installation banner (unless dismissed or installed)
387 */
388 function wpsc_jetpack_boost_install_banner() {
389 if ( ! wpsc_is_boost_current() ) {
390 return;
391 }
392 // Don't show the banner if Boost is installed, or the banner has been dismissed.
393 $is_dismissed = '1' === get_user_option( 'wpsc_dismissed_boost_banner' );
394 if ( wpsc_is_boost_active() || $is_dismissed ) {
395 return;
396 }
397
398 $config = wpsc_get_boost_migration_config();
399 $button_url = $config['is_installed'] ? $config['activate_url'] : $config['install_url'];
400 $button_label = $config['is_installed'] ? __( 'Set up Jetpack Boost', 'wp-super-cache' ) : __( 'Install Jetpack Boost', 'wp-super-cache' );
401 $button_class = $config['is_installed'] ? 'wpsc-activate-boost-button' : 'wpsc-install-boost-button';
402 $plugin_url = plugin_dir_url( __FILE__ );
403
404 ?>
405 <div class="wpsc-boost-banner">
406 <div class="wpsc-boost-banner-inner">
407 <div class="wpsc-boost-banner-content">
408 <img style="width:282px" src="<?php echo esc_url( $plugin_url . '/assets/jetpack-logo.svg' ); ?>" height="36" />
409
410 <h3>
411 <?php esc_html_e( 'Speed up your site with our top&#8209;rated performance tool', 'wp-super-cache' ); ?>
412 </h3>
413
414 <p id="wpsc-install-invitation">
415 <?php
416 esc_html_e(
417 '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.',
418 'wp-super-cache'
419 );
420 ?>
421 </p>
422
423 <div class="wpsc-boost-migration-error" style="display:none; color:red; margin-bottom: 20px;"></div>
424
425 <div style="display: flex; gap: 24px;">
426 <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 ); ?>">
427 <div class='spinner' style='display:none; margin-top: 8px'></div>
428 <label><?php echo esc_html( $button_label ); ?></label>
429 </a>
430 <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/">
431 Learn More
432 </a>
433 </div>
434 </div>
435
436 <div class="wpsc-boost-banner-image-container">
437 <img
438 width="350"
439 height="452"
440 src="<?php echo esc_url( $plugin_url . 'assets/boost-install-card-main.png' ); ?>"
441 title="<?php esc_attr_e( 'Check how your web site performance scores for desktop and mobile.', 'wp-super-cache' ); ?>"
442 alt="<?php esc_attr_e( 'An image showing the Jetpack Boost dashboard.', 'wp-super-cache' ); ?>"
443 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"
444 sizes="(max-width: 782px) 350px, 700px"
445 >
446 </div>
447 </div>
448
449 <span class="wpsc-boost-dismiss dashicons dashicons-dismiss"></span>
450 </div>
451 <?php
452 }
453
454 function wp_cache_manager_error_checks() {
455 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;
456 global $dismiss_htaccess_warning, $dismiss_readable_warning, $dismiss_gc_warning, $wp_cache_shutdown_gc, $is_nginx;
457 global $htaccess_path;
458
459 if ( ! wpsupercache_site_admin() ) {
460 return false;
461 }
462
463 if ( PHP_VERSION_ID < 50300 && ( ini_get( 'safe_mode' ) === '1' || strtolower( ini_get( 'safe_mode' ) ) === 'on' ) ) { // @codingStandardsIgnoreLine
464 echo '<div class="notice notice-error"><h4>' . esc_html__( 'Warning! PHP Safe Mode Enabled!', 'wp-super-cache' ) . '</h4>';
465 echo '<p>' . esc_html__( 'You may experience problems running this plugin because SAFE MODE is enabled.', 'wp-super-cache' ) . '<br />';
466
467 if ( ! ini_get( 'safe_mode_gid' ) ) { // @codingStandardsIgnoreLine
468 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' );
469 echo '<br />';
470 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 ) );
471 } else {
472 _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' );
473 }
474 echo '</p></div>';
475 }
476
477 if ( '' == get_option( 'permalink_structure' ) ) {
478 echo '<div class="notice notice-error"><h4>' . __( 'Permlink Structure Error', 'wp-super-cache' ) . '</h4>';
479 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>";
480 echo '</div>';
481 return false;
482 }
483
484 if ( $wp_cache_debug || ! $wp_cache_cron_check ) {
485 if ( defined( 'DISABLE_WP_CRON' ) && constant( 'DISABLE_WP_CRON' ) ) {
486 ?>
487 <div class="notice notice-error"><h4><?php _e( 'CRON System Disabled', 'wp-super-cache' ); ?></h4>
488 <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>
489 </div>
490 <?php
491 } elseif ( function_exists( "wp_remote_get" ) == false ) {
492 $hostname = str_replace( 'http://', '', str_replace( 'https://', '', get_option( 'siteurl' ) ) );
493 if( strpos( $hostname, '/' ) )
494 $hostname = substr( $hostname, 0, strpos( $hostname, '/' ) );
495 $ip = gethostbyname( $hostname );
496 if( substr( $ip, 0, 3 ) == '127' || substr( $ip, 0, 7 ) == '192.168' ) {
497 ?><div class="notice notice-warning"><h4><?php printf( __( 'Warning! Your hostname "%s" resolves to %s', 'wp-super-cache' ), $hostname, $ip ); ?></h4>
498 <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>
499 <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>
500 </div>
501 <?php
502 return false;
503 } else {
504 wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
505 }
506 } else {
507 $cron_url = get_option( 'siteurl' ) . '/wp-cron.php?check=' . wp_hash('187425');
508 $cron = wp_remote_get($cron_url, array('timeout' => 0.01, 'blocking' => true));
509 if( is_array( $cron ) ) {
510 if( $cron[ 'response' ][ 'code' ] == '404' ) {
511 ?><div class="notice notice-error"><h4>Warning! wp-cron.php not found!</h4>
512 <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>
513 <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>
514 </div>
515 <?php
516 } else {
517 wp_cache_replace_line('^ *\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
518 }
519 }
520 }
521 }
522
523 if (
524 ! wpsc_check_advanced_cache() ||
525 ! wp_cache_verify_config_file() ||
526 ! wp_cache_verify_cache_dir()
527 ) {
528 echo '<p>' . __( "Cannot continue... fix previous problems and retry.", 'wp-super-cache' ) . '</p>';
529 return false;
530 }
531
532 if ( false == function_exists( 'wpsc_deep_replace' ) ) {
533 $msg = __( 'Warning! You must set WP_CACHE and WPCACHEHOME in your wp-config.php for this plugin to work correctly:' ) . '<br />';
534 $msg .= "<code>define( 'WP_CACHE', true );</code><br />";
535 $msg .= "<code>define( 'WPCACHEHOME', '" . __DIR__ . "/' );</code><br />";
536 wp_die( $msg );
537 }
538
539 if (!wp_cache_check_global_config()) {
540 return false;
541 }
542
543 if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) {
544 ?><div class="notice notice-warning"><h4><?php _e( 'Zlib Output Compression Enabled!', 'wp-super-cache' ); ?></h4>
545 <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
546 }
547
548 if (
549 $cache_enabled == true &&
550 $super_cache_enabled == true &&
551 $wp_cache_mod_rewrite &&
552 ! got_mod_rewrite() &&
553 ! $is_nginx
554 ) {
555 ?><div class="notice notice-warning"><h4><?php _e( 'Mod rewrite may not be installed!', 'wp-super-cache' ); ?></h4>
556 <p><?php _e( 'It appears that mod_rewrite is not installed. Sometimes this check isn&#8217;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
557 }
558
559 if( !is_writeable_ACLSafe( $wp_cache_config_file ) ) {
560 if ( !defined( 'SUBMITDISABLED' ) )
561 define( "SUBMITDISABLED", 'disabled style="color: #aaa" ' );
562 ?><div class="notice notice-error"><h4><?php _e( 'Read Only Mode. Configuration cannot be changed.', 'wp-super-cache' ); ?></h4>
563 <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 ); ?>
564 <?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&#8217;s globally writeable and it should be fine.', 'wp-super-cache' ); ?></p>
565 <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>
566 <?php _e( 'Writeable:', 'wp-super-cache' ); ?> <code>chmod 666 <?php echo WPCACHECONFIGPATH; ?>/wp-cache-config.php</code><br />
567 <?php _e( 'Read-only:', 'wp-super-cache' ); ?> <code>chmod 644 <?php echo WPCACHECONFIGPATH; ?>/wp-cache-config.php</code></p>
568 </div><?php
569 } elseif ( !defined( 'SUBMITDISABLED' ) ) {
570 define( "SUBMITDISABLED", ' ' );
571 }
572
573 $valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
574 // Check that garbage collection is running
575 if ( $valid_nonce && isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'dismiss_gc_warning' ) {
576 wp_cache_replace_line('^ *\$dismiss_gc_warning', "\$dismiss_gc_warning = 1;", $wp_cache_config_file);
577 $dismiss_gc_warning = 1;
578 } elseif ( !isset( $dismiss_gc_warning ) ) {
579 $dismiss_gc_warning = 0;
580 }
581 if ( $cache_enabled && ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) && function_exists( 'get_gc_flag' ) ) {
582 $gc_flag = get_gc_flag();
583 if ( $dismiss_gc_warning == 0 ) {
584 if ( false == maybe_stop_gc( $gc_flag ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) {
585 ?><div class="notice notice-warning"><h4><?php _e( 'Warning! Garbage collection is not scheduled!', 'wp-super-cache' ); ?></h4>
586 <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>
587 <form action="" method="POST">
588 <input type="hidden" name="action" value="dismiss_gc_warning" />
589 <input type="hidden" name="page" value="wpsupercache" />
590 <?php wp_nonce_field( 'wp-cache' ); ?>
591 <input class='button-secondary' type='submit' value='<?php _e( 'Dismiss', 'wp-super-cache' ); ?>' />
592 </form>
593 <br />
594 </div>
595 <?php
596 }
597 }
598 }
599
600 // Server could be running as the owner of the wp-content directory. Therefore, if it's
601 // writable, issue a warning only if the permissions aren't 755.
602 if ( $valid_nonce && isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'dismiss_readable_warning' ) {
603 wp_cache_replace_line('^ *\$dismiss_readable_warning', "\$dismiss_readable_warning = 1;", $wp_cache_config_file);
604 $dismiss_readable_warning = 1;
605 } elseif ( !isset( $dismiss_readable_warning ) ) {
606 $dismiss_readable_warning = 0;
607 }
608 if( $dismiss_readable_warning == 0 && is_writeable_ACLSafe( WP_CONTENT_DIR . '/' ) ) {
609 $wp_content_stat = stat(WP_CONTENT_DIR . '/');
610 $wp_content_mode = decoct( $wp_content_stat[ 'mode' ] & 0777 );
611 if( substr( $wp_content_mode, -2 ) == '77' ) {
612 ?><div class="notice notice-warning"><h4><?php printf( __( 'Warning! %s is writeable!', 'wp-super-cache' ), WP_CONTENT_DIR ); ?></h4>
613 <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>
614 <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>
615 <form action="" method="POST">
616 <input type="hidden" name="action" value="dismiss_readable_warning" />
617 <input type="hidden" name="page" value="wpsupercache" />
618 <?php wp_nonce_field( 'wp-cache' ); ?>
619 <input class='button-secondary' type='submit' value='<?php _e( 'Dismiss', 'wp-super-cache' ); ?>' />
620 </form>
621 <br />
622 </div>
623 <?php
624 }
625 }
626
627 if ( ! $is_nginx && function_exists( "is_main_site" ) && true == is_main_site() ) {
628 if ( ! isset( $htaccess_path ) ) {
629 $home_path = trailingslashit( get_home_path() );
630 } else {
631 $home_path = $htaccess_path;
632 }
633
634 $scrules = implode( "\n", extract_from_markers( $home_path . '.htaccess', 'WPSuperCache' ) );
635 if (
636 $cache_enabled
637 && $wp_cache_mod_rewrite
638 && ! $wp_cache_mobile_enabled
639 && strpos( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) )
640 ) {
641 echo '<div class="notice notice-warning"><h4>' . esc_html__( 'Mobile rewrite rules detected', 'wp-super-cache' ) . '</h4>';
642 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>';
643 } elseif (
644 $wp_cache_mod_rewrite
645 && $cache_enabled
646 && $wp_cache_mobile_enabled
647 && $scrules != '' // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual
648 && (
649 (
650 '' != $wp_cache_mobile_prefixes // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual
651 && ! str_contains( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_prefixes ), ' ' ) )
652 )
653 || (
654 '' != $wp_cache_mobile_browsers // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual
655 && ! str_contains( $scrules, addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) )
656 )
657 )
658 ) {
659 ?>
660 <div class="notice notice-warning"><h4><?php _e( 'Rewrite rules must be updated', 'wp-super-cache' ); ?></h4>
661 <p><?php _e( 'The rewrite rules required by this plugin have changed or are missing. ', 'wp-super-cache' ); ?>
662 <?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' ); ?>
663 <ol><li> <?php _e( 'Set the plugin to simple mode and enable mobile support.', 'wp-super-cache' ); ?></li>
664 <li> <?php _e( 'Scroll down the Advanced Settings page and click the <strong>Update Mod_Rewrite Rules</strong> button.', 'wp-super-cache' ); ?></li>
665 <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>
666 <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>
667 <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
668 }
669
670 if (
671 $cache_enabled
672 && $super_cache_enabled
673 && $wp_cache_mod_rewrite
674 && $scrules == '' // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
675 ) {
676 ?>
677 <div class='notice notice-warning'><h4><?php esc_html_e( 'Rewrite rules must be updated', 'wp-super-cache' ); ?></h4>
678 <p><?php esc_html_e( 'The rewrite rules required by this plugin have changed or are missing. ', 'wp-super-cache' ); ?>
679 <?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>
680 <?php
681 }
682 }
683
684 if ( ! $is_nginx && $wp_cache_mod_rewrite && $super_cache_enabled && function_exists( 'apache_get_modules' ) ) {
685 $mods = apache_get_modules();
686 $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' ) );
687 foreach( $required_modules as $req => $desc ) {
688 if( !in_array( $req, $mods ) ) {
689 $missing_mods[ $req ] = $desc;
690 }
691 }
692 if( isset( $missing_mods) && is_array( $missing_mods ) ) {
693 ?><div class='notice notice-warning'><h4><?php _e( 'Missing Apache Modules', 'wp-super-cache' ); ?></h4>
694 <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
695 echo "<ul>";
696 foreach( $missing_mods as $req => $desc ) {
697 echo "<li> $req - $desc</li>";
698 }
699 echo "</ul>";
700 echo "</div>";
701 }
702 }
703
704 if ( $valid_nonce && isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'dismiss_htaccess_warning' ) {
705 wp_cache_replace_line('^ *\$dismiss_htaccess_warning', "\$dismiss_htaccess_warning = 1;", $wp_cache_config_file);
706 $dismiss_htaccess_warning = 1;
707 } elseif ( !isset( $dismiss_htaccess_warning ) ) {
708 $dismiss_htaccess_warning = 0;
709 }
710 if ( isset( $disable_supercache_htaccess_warning ) == false )
711 $disable_supercache_htaccess_warning = false;
712 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' ) ) {
713 ?><div class="notice notice-info"><h4><?php _e( '.htaccess file may need to be moved', 'wp-super-cache' ); ?></h4>
714 <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>
715 <form action="" method="POST">
716 <input type="hidden" name="action" value="dismiss_htaccess_warning" />
717 <input type="hidden" name="page" value="wpsupercache" />
718 <?php wp_nonce_field( 'wp-cache' ); ?>
719 <input class='button-secondary' type='submit' value='<?php _e( 'Dismiss', 'wp-super-cache' ); ?>' />
720 </form>
721 <br />
722 </div><?php
723 }
724
725 return true;
726 }
727 add_filter( 'wp_super_cache_error_checking', 'wp_cache_manager_error_checks' );
728
729 function wp_cache_manager_updates() {
730 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;
731 global $cache_schedule_type, $cache_max_time, $cache_time_interval, $wp_cache_shutdown_gc, $wpsc_save_headers;
732
733 if ( !wpsupercache_site_admin() )
734 return false;
735
736 if ( false == isset( $cache_page_secret ) ) {
737 $cache_page_secret = md5( date( 'H:i:s' ) . mt_rand() );
738 wp_cache_replace_line('^ *\$cache_page_secret', "\$cache_page_secret = '" . $cache_page_secret . "';", $wp_cache_config_file);
739 }
740
741 $valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
742 if ( $valid_nonce == false )
743 return false;
744
745 if ( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'easysetup' ) {
746 $_POST[ 'action' ] = 'scupdates';
747 if( isset( $_POST[ 'wp_cache_easy_on' ] ) && $_POST[ 'wp_cache_easy_on' ] == 1 ) {
748 $_POST[ 'wp_cache_enabled' ] = 1;
749 $_POST[ 'super_cache_enabled' ] = 1;
750 $_POST[ 'cache_rebuild_files' ] = 1;
751 unset( $_POST[ 'cache_compression' ] );
752 if ( $cache_path != WP_CONTENT_DIR . '/cache/' )
753 $_POST[ 'wp_cache_location' ] = $cache_path;
754 //
755 // set up garbage collection with some default settings
756 if ( ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) {
757 if ( false == isset( $cache_schedule_type ) ) {
758 $cache_schedule_type = 'interval';
759 $cache_time_interval = 600;
760 $cache_max_time = 1800;
761 wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
762 wp_cache_replace_line('^ *\$cache_time_interval', "\$cache_time_interval = '$cache_time_interval';", $wp_cache_config_file);
763 wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = '$cache_max_time';", $wp_cache_config_file);
764 }
765 wp_schedule_single_event( time() + 600, 'wp_cache_gc' );
766 }
767
768 } else {
769 unset( $_POST[ 'wp_cache_enabled' ] );
770 wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
771 wp_clear_scheduled_hook( 'wp_cache_gc' );
772 wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
773 }
774 $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' );
775 foreach( $advanced_settings as $setting ) {
776 if ( isset( $GLOBALS[ $setting ] ) && $GLOBALS[ $setting ] == 1 ) {
777 $_POST[ $setting ] = 1;
778 }
779 }
780 $_POST['wp_cache_not_logged_in'] = 2;
781 }
782
783 if( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'scupdates' ) {
784 if( isset( $_POST[ 'wp_cache_location' ] ) && $_POST[ 'wp_cache_location' ] != '' ) {
785 $dir = realpath( trailingslashit( dirname( $_POST[ 'wp_cache_location' ] ) ) );
786 if ( $dir === realpath( '.' ) || false === $dir ) {
787 $dir = WP_CONTENT_DIR . '/cache/';
788 } else {
789 $dir = trailingslashit( $dir ) . trailingslashit(wpsc_deep_replace( array( '..', '\\' ), basename( $_POST[ 'wp_cache_location' ] ) ) );
790 }
791 $new_cache_path = $dir;
792 } else {
793 $new_cache_path = WP_CONTENT_DIR . '/cache/';
794 }
795 if ( $new_cache_path != $cache_path ) {
796 if ( file_exists( $new_cache_path ) == false )
797 rename( $cache_path, $new_cache_path );
798 $cache_path = preg_replace('/[ <>\'\"\r\n\t\(\)\$\[\];#]/', '', $new_cache_path );
799 wp_cache_replace_line('^ *\$cache_path', "\$cache_path = " . var_export( $cache_path, true ) . ";", $wp_cache_config_file);
800 }
801
802 if( isset( $_POST[ 'wp_super_cache_late_init' ] ) ) {
803 $wp_super_cache_late_init = 1;
804 } else {
805 $wp_super_cache_late_init = 0;
806 }
807 wp_cache_replace_line('^ *\$wp_super_cache_late_init', "\$wp_super_cache_late_init = " . $wp_super_cache_late_init . ";", $wp_cache_config_file);
808
809 if( isset( $_POST[ 'wp_cache_disable_utf8' ] ) ) {
810 $wp_cache_disable_utf8 = 1;
811 } else {
812 $wp_cache_disable_utf8 = 0;
813 }
814 wp_cache_replace_line('^ *\$wp_cache_disable_utf8', "\$wp_cache_disable_utf8 = " . $wp_cache_disable_utf8 . ";", $wp_cache_config_file);
815
816 if( isset( $_POST[ 'wp_cache_no_cache_for_get' ] ) ) {
817 $wp_cache_no_cache_for_get = 1;
818 } else {
819 $wp_cache_no_cache_for_get = 0;
820 }
821 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);
822
823 if( isset( $_POST[ 'wp_supercache_304' ] ) ) {
824 $wp_supercache_304 = 1;
825 } else {
826 $wp_supercache_304 = 0;
827 }
828 wp_cache_replace_line('^ *\$wp_supercache_304', "\$wp_supercache_304 = " . $wp_supercache_304 . ";", $wp_cache_config_file);
829
830 if( isset( $_POST[ 'wp_cache_mfunc_enabled' ] ) ) {
831 $wp_cache_mfunc_enabled = 1;
832 } else {
833 $wp_cache_mfunc_enabled = 0;
834 }
835 wp_cache_replace_line('^ *\$wp_cache_mfunc_enabled', "\$wp_cache_mfunc_enabled = " . $wp_cache_mfunc_enabled . ";", $wp_cache_config_file);
836
837 if( isset( $_POST[ 'wp_cache_mobile_enabled' ] ) ) {
838 $wp_cache_mobile_enabled = 1;
839 } else {
840 $wp_cache_mobile_enabled = 0;
841 }
842 wp_cache_replace_line('^ *\$wp_cache_mobile_enabled', "\$wp_cache_mobile_enabled = " . $wp_cache_mobile_enabled . ";", $wp_cache_config_file);
843
844 if( isset( $_POST[ 'wp_cache_front_page_checks' ] ) ) {
845 $wp_cache_front_page_checks = 1;
846 } else {
847 $wp_cache_front_page_checks = 0;
848 }
849 wp_cache_replace_line('^ *\$wp_cache_front_page_checks', "\$wp_cache_front_page_checks = " . $wp_cache_front_page_checks . ";", $wp_cache_config_file);
850
851 if( isset( $_POST[ 'wp_supercache_cache_list' ] ) ) {
852 $wp_supercache_cache_list = 1;
853 } else {
854 $wp_supercache_cache_list = 0;
855 }
856 wp_cache_replace_line('^ *\$wp_supercache_cache_list', "\$wp_supercache_cache_list = " . $wp_supercache_cache_list . ";", $wp_cache_config_file);
857
858 if ( isset( $_POST[ 'wp_cache_enabled' ] ) ) {
859 wp_cache_enable();
860 if ( ! defined( 'DISABLE_SUPERCACHE' ) ) {
861 wp_cache_debug( 'DISABLE_SUPERCACHE is not set, super_cache enabled.' );
862 wp_super_cache_enable();
863 $super_cache_enabled = true;
864 }
865 } else {
866 wp_cache_disable();
867 wp_super_cache_disable();
868 $super_cache_enabled = false;
869 }
870
871 if ( isset( $_POST[ 'wp_cache_mod_rewrite' ] ) && $_POST[ 'wp_cache_mod_rewrite' ] == 1 ) {
872 $wp_cache_mod_rewrite = 1;
873 add_mod_rewrite_rules();
874 } else {
875 $wp_cache_mod_rewrite = 0; // cache files served by PHP
876 remove_mod_rewrite_rules();
877 }
878 wp_cache_setting( 'wp_cache_mod_rewrite', $wp_cache_mod_rewrite );
879
880 if( isset( $_POST[ 'wp_cache_clear_on_post_edit' ] ) ) {
881 $wp_cache_clear_on_post_edit = 1;
882 } else {
883 $wp_cache_clear_on_post_edit = 0;
884 }
885 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);
886
887 if( isset( $_POST[ 'cache_rebuild_files' ] ) ) {
888 $cache_rebuild_files = 1;
889 } else {
890 $cache_rebuild_files = 0;
891 }
892 wp_cache_replace_line('^ *\$cache_rebuild_files', "\$cache_rebuild_files = " . $cache_rebuild_files . ";", $wp_cache_config_file);
893
894 if ( isset( $_POST[ 'wpsc_save_headers' ] ) ) {
895 $wpsc_save_headers = 1;
896 } else {
897 $wpsc_save_headers = 0;
898 }
899 wp_cache_replace_line('^ *\$wpsc_save_headers', "\$wpsc_save_headers = " . $wpsc_save_headers . ";", $wp_cache_config_file);
900
901 if( isset( $_POST[ 'wp_cache_mutex_disabled' ] ) ) {
902 $wp_cache_mutex_disabled = 0;
903 } else {
904 $wp_cache_mutex_disabled = 1;
905 }
906 if( defined( 'WPSC_DISABLE_LOCKING' ) ) {
907 $wp_cache_mutex_disabled = 1;
908 }
909 wp_cache_replace_line('^ *\$wp_cache_mutex_disabled', "\$wp_cache_mutex_disabled = " . $wp_cache_mutex_disabled . ";", $wp_cache_config_file);
910
911 if ( isset( $_POST['wp_cache_not_logged_in'] ) && $_POST['wp_cache_not_logged_in'] != 0 ) {
912 if ( $wp_cache_not_logged_in == 0 && function_exists( 'prune_super_cache' ) ) {
913 prune_super_cache( $cache_path, true );
914 }
915 $wp_cache_not_logged_in = (int)$_POST['wp_cache_not_logged_in'];
916 } else {
917 $wp_cache_not_logged_in = 0;
918 }
919 wp_cache_replace_line('^ *\$wp_cache_not_logged_in', "\$wp_cache_not_logged_in = " . $wp_cache_not_logged_in . ";", $wp_cache_config_file);
920
921 if( isset( $_POST[ 'wp_cache_make_known_anon' ] ) ) {
922 if( $wp_cache_make_known_anon == 0 && function_exists( 'prune_super_cache' ) )
923 prune_super_cache ($cache_path, true);
924 $wp_cache_make_known_anon = 1;
925 } else {
926 $wp_cache_make_known_anon = 0;
927 }
928 wp_cache_replace_line('^ *\$wp_cache_make_known_anon', "\$wp_cache_make_known_anon = " . $wp_cache_make_known_anon . ";", $wp_cache_config_file);
929
930 if( isset( $_POST[ 'wp_cache_refresh_single_only' ] ) ) {
931 $wp_cache_refresh_single_only = 1;
932 } else {
933 $wp_cache_refresh_single_only = 0;
934 }
935 wp_cache_setting( 'wp_cache_refresh_single_only', $wp_cache_refresh_single_only );
936
937 if ( defined( 'WPSC_DISABLE_COMPRESSION' ) ) {
938 $cache_compression = 0;
939 wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
940 } else {
941 if ( isset( $_POST[ 'cache_compression' ] ) ) {
942 $new_cache_compression = 1;
943 } else {
944 $new_cache_compression = 0;
945 }
946 if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) {
947 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>';
948 } elseif ( $new_cache_compression !== (int) $cache_compression ) {
949 $cache_compression = $new_cache_compression;
950 wp_cache_replace_line( '^ *\$cache_compression', "\$cache_compression = $cache_compression;", $wp_cache_config_file );
951 if ( function_exists( 'prune_super_cache' ) ) {
952 prune_super_cache( $cache_path, true );
953 }
954 delete_option( 'super_cache_meta' );
955 }
956 }
957 }
958 }
959 if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'wpsupercache' )
960 add_action( 'admin_init', 'wp_cache_manager_updates' );
961
962 function wp_cache_manager() {
963 global $wp_cache_config_file, $valid_nonce, $supercachedir, $cache_path, $cache_enabled, $cache_compression, $super_cache_enabled;
964 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;
965 global $wp_cache_not_logged_in, $wp_cache_make_known_anon, $wp_supercache_cache_list, $cache_page_secret;
966 global $wp_super_cache_front_page_check, $wp_cache_refresh_single_only, $wp_cache_mobile_prefixes;
967 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;
968 global $wp_super_cache_comments, $wp_cache_home_path, $wpsc_save_headers, $is_nginx;
969 global $wpsc_promo_links;
970
971 if ( !wpsupercache_site_admin() )
972 return false;
973
974 // used by mod_rewrite rules and config file
975 if ( function_exists( "cfmobi_default_browsers" ) ) {
976 $wp_cache_mobile_browsers = cfmobi_default_browsers( "mobile" );
977 $wp_cache_mobile_browsers = array_merge( $wp_cache_mobile_browsers, cfmobi_default_browsers( "touch" ) );
978 } elseif ( function_exists( 'lite_detection_ua_contains' ) ) {
979 $wp_cache_mobile_browsers = explode( '|', lite_detection_ua_contains() );
980 } else {
981 $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' );
982 }
983 if ( function_exists( "lite_detection_ua_prefixes" ) ) {
984 $wp_cache_mobile_prefixes = lite_detection_ua_prefixes();
985 } else {
986 $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
987 }
988 $wp_cache_mobile_browsers = apply_filters( 'cached_mobile_browsers', $wp_cache_mobile_browsers ); // Allow mobile plugins access to modify the mobile UA list
989 $wp_cache_mobile_prefixes = apply_filters( 'cached_mobile_prefixes', $wp_cache_mobile_prefixes ); // Allow mobile plugins access to modify the mobile UA prefix list
990 if ( function_exists( 'do_cacheaction' ) ) {
991 $wp_cache_mobile_browsers = do_cacheaction( 'wp_super_cache_mobile_browsers', $wp_cache_mobile_browsers );
992 $wp_cache_mobile_prefixes = do_cacheaction( 'wp_super_cache_mobile_prefixes', $wp_cache_mobile_prefixes );
993 }
994 $mobile_groups = apply_filters( 'cached_mobile_groups', array() ); // Group mobile user agents by capabilities. Lump them all together by default
995 // mobile_groups = array( 'apple' => array( 'ipod', 'iphone' ), 'nokia' => array( 'nokia5800', 'symbianos' ) );
996
997 $wp_cache_mobile_browsers = implode( ', ', $wp_cache_mobile_browsers );
998 $wp_cache_mobile_prefixes = implode( ', ', $wp_cache_mobile_prefixes );
999
1000 if ( false == apply_filters( 'wp_super_cache_error_checking', true ) )
1001 return false;
1002
1003 if ( function_exists( 'get_supercache_dir' ) )
1004 $supercachedir = get_supercache_dir();
1005 if( get_option( 'gzipcompression' ) == 1 )
1006 update_option( 'gzipcompression', 0 );
1007 if( !isset( $cache_rebuild_files ) )
1008 $cache_rebuild_files = 0;
1009
1010 $valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
1011 /* http://www.netlobo.com/div_hiding.html */
1012 ?>
1013 <script type='text/javascript'>
1014 <!--
1015 function toggleLayer( whichLayer ) {
1016 var elem, vis;
1017 if( document.getElementById ) // this is the way the standards work
1018 elem = document.getElementById( whichLayer );
1019 else if( document.all ) // this is the way old msie versions work
1020 elem = document.all[whichLayer];
1021 else if( document.layers ) // this is the way nn4 works
1022 elem = document.layers[whichLayer];
1023 vis = elem.style;
1024 // if the style.display value is blank we try to figure it out here
1025 if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
1026 vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
1027 vis.display = (vis.display==''||vis.display=='block')?'none':'block';
1028 }
1029 // -->
1030 //Clicking header opens fieldset options
1031 jQuery(document).ready(function(){
1032 jQuery("fieldset h4").css("cursor","pointer").on("click",function(){
1033 jQuery(this).parent("fieldset").find("p,form,ul,blockquote").toggle("slow");
1034 });
1035 });
1036 </script>
1037
1038 <style type='text/css'>
1039 #nav h3 {
1040 border-bottom: 1px solid #ccc;
1041 padding-bottom: 0;
1042 height: 1.5em;
1043 }
1044 table.wpsc-settings-table {
1045 clear: both;
1046 }
1047 </style>
1048 <div id="wpsc-dashboard">
1049 <?php
1050 wpsc_render_header();
1051
1052 echo '<div class="wpsc-body">';
1053 echo '<a name="top"></a>';
1054
1055 // Set a default.
1056 if ( false === $cache_enabled && ! isset( $wp_cache_mod_rewrite ) ) {
1057 $wp_cache_mod_rewrite = 0;
1058 } elseif ( ! isset( $wp_cache_mod_rewrite ) && $cache_enabled && $super_cache_enabled ) {
1059 $wp_cache_mod_rewrite = 1;
1060 }
1061
1062 $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
1063 $curr_tab = ! empty( $_GET['tab'] ) ? sanitize_text_field( stripslashes( $_GET['tab'] ) ) : ''; // WPCS: sanitization ok.
1064 if ( empty( $curr_tab ) ) {
1065 $curr_tab = 'easy';
1066 if ( $wp_cache_mod_rewrite ) {
1067 $curr_tab = 'settings';
1068 echo '<div class="notice notice-info is-dismissible"><p>' . __( 'Notice: <em>Expert mode caching enabled</em>. Showing Advanced Settings Page by default.', 'wp-super-cache' ) . '</p></div>';
1069 }
1070 }
1071
1072 if ( 'preload' === $curr_tab ) {
1073 if ( true == $super_cache_enabled && ! defined( 'DISABLESUPERCACHEPRELOADING' ) ) {
1074 global $wp_cache_preload_interval, $wp_cache_preload_on, $wp_cache_preload_taxonomies, $wp_cache_preload_email_me, $wp_cache_preload_email_volume, $wp_cache_preload_posts, $wpdb;
1075 wpsc_preload_settings();
1076 $currently_preloading = false;
1077
1078 echo '<div id="wpsc-preload-status"></div>';
1079 }
1080 }
1081
1082 wpsc_admin_tabs( $curr_tab );
1083 echo '<div class="wpsc-body-content wrap">';
1084
1085 if ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 1 && ! wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
1086 wp_schedule_single_event( time() + 360, 'wp_cache_check_site_hook' );
1087 wp_cache_debug( 'scheduled wp_cache_check_site_hook for 360 seconds time.', 2 );
1088 }
1089
1090 if ( isset( $_REQUEST['wp_restore_config'] ) && $valid_nonce ) {
1091 unlink( $wp_cache_config_file );
1092 echo '<strong>' . esc_html__( 'Configuration file changed, some values might be wrong. Load the page again from the "Settings" menu to reset them.', 'wp-super-cache' ) . '</strong>';
1093 }
1094
1095 if ( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
1096 wp_cache_replace_line( '^ *\$wp_cache_slash_check', "\$wp_cache_slash_check = 1;", $wp_cache_config_file );
1097 } else {
1098 wp_cache_replace_line( '^ *\$wp_cache_slash_check', "\$wp_cache_slash_check = 0;", $wp_cache_config_file );
1099 }
1100 $home_path = parse_url( site_url() );
1101 $home_path = trailingslashit( array_key_exists( 'path', $home_path ) ? $home_path['path'] : '' );
1102 if ( ! isset( $wp_cache_home_path ) ) {
1103 $wp_cache_home_path = '/';
1104 wp_cache_setting( 'wp_cache_home_path', '/' );
1105 }
1106 if ( "$home_path" != "$wp_cache_home_path" ) {
1107 wp_cache_setting( 'wp_cache_home_path', $home_path );
1108 }
1109
1110 if ( $wp_cache_mobile_enabled == 1 ) {
1111 update_cached_mobile_ua_list( $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $mobile_groups );
1112 }
1113
1114 ?>
1115 <style>
1116 .wpsc-boost-banner {
1117 margin: 2px 1.25rem 1.25rem 0;
1118 box-shadow: 0px 2px 6px rgba(0, 0, 0, 0.03), 0px 1px 2px rgba(0, 0, 0, 0.03);
1119 border: 1px solid #d5d5d5;
1120 position: relative;
1121 }
1122
1123 .wpsc-boost-banner-inner {
1124 display: flex;
1125 grid-template-columns: minmax(auto, 750px) 500px;
1126 justify-content: space-between;
1127 min-height: 300px;
1128 background: #fff;
1129 overflow: hidden;
1130 }
1131
1132 .wpsc-boost-banner-content {
1133 display: inline-flex;
1134 flex-direction: column;
1135 padding: 2.5rem;
1136 text-align: left;
1137 }
1138
1139 .wpsc-boost-banner-image-container {
1140 position: relative;
1141 background-image: url( <?php echo esc_url( plugin_dir_url( __FILE__ ) . '/assets/jetpack-colors.svg' ); ?> );
1142 background-size: cover;
1143 min-width: 40%;
1144 max-width: 40%;
1145 overflow: hidden;
1146 text-align: right;
1147 }
1148
1149 .wpsc-boost-banner-image-container img {
1150 position: relative;
1151 top: 50%;
1152 transform: translateY(-50%);
1153 }
1154
1155 .wpsc-boost-banner h3 {
1156 font-size: 24px;
1157 line-height: 32px;
1158 }
1159
1160 .wpsc-boost-banner p {
1161 font-size: 14px;
1162 line-height: 24px;
1163 margin: 0 0 1.9rem;
1164 }
1165
1166 .wpsc-boost-banner .wpsc-boost-dismiss {
1167 position: absolute;
1168 top: 10px;
1169 right: 10px;
1170 color: black;
1171 cursor:pointer;
1172 }
1173
1174 .wpsc-boost-banner .button-primary {
1175 background: black;
1176 border-color: black;
1177 color: #fff;
1178 width: fit-content;
1179 padding: 0.4rem 1rem;
1180 font-size: 16px;
1181 line-height: 23px;
1182 }
1183
1184 .wpsc-boost-banner .button-primary:hover {
1185 background-color: #333;
1186 }
1187
1188 .wpsc-boost-banner .button-primary:visited {
1189 background-color: black;
1190 border-color: black;
1191 }
1192 </style>
1193
1194 <table class="wpsc-settings-table"><td valign="top">
1195
1196 <?php
1197 wpsc_jetpack_boost_install_banner();
1198
1199 switch ( $curr_tab ) {
1200 case 'cdn':
1201 scossdl_off_options();
1202 break;
1203 case 'tester':
1204 case 'contents':
1205 echo '<a name="test"></a>';
1206 wp_cache_files();
1207 break;
1208 case 'preload':
1209 wpsc_render_partial(
1210 'preload',
1211 compact(
1212 'cache_enabled',
1213 'super_cache_enabled',
1214 'admin_url',
1215 'wp_cache_preload_interval',
1216 'wp_cache_preload_on',
1217 'wp_cache_preload_taxonomies',
1218 'wp_cache_preload_email_me',
1219 'wp_cache_preload_email_volume',
1220 'currently_preloading',
1221 'wp_cache_preload_posts'
1222 )
1223 );
1224
1225 break;
1226 case 'plugins':
1227 wpsc_plugins_tab();
1228 break;
1229 case 'debug':
1230 global $wp_super_cache_debug, $wp_cache_debug_log, $wp_cache_debug_ip, $wp_cache_debug_ip;
1231 global $wp_super_cache_front_page_text, $wp_super_cache_front_page_notification;
1232 global $wp_super_cache_advanced_debug, $wp_cache_debug_username, $wp_super_cache_front_page_clear;
1233 wpsc_render_partial(
1234 'debug',
1235 compact( 'wp_super_cache_debug', 'wp_cache_debug_log', 'wp_cache_debug_ip', 'cache_path', 'valid_nonce', 'wp_cache_config_file', 'wp_super_cache_comments', 'wp_super_cache_front_page_check', 'wp_super_cache_front_page_clear', 'wp_super_cache_front_page_text', 'wp_super_cache_front_page_notification', 'wp_super_cache_advanced_debug', 'wp_cache_debug_username', 'wp_cache_home_path' )
1236 );
1237 break;
1238 case 'settings':
1239 global $cache_acceptable_files, $wpsc_rejected_cookies, $cache_rejected_uri, $wp_cache_pages;
1240 global $cache_max_time, $wp_cache_config_file, $valid_nonce, $super_cache_enabled, $cache_schedule_type, $cache_scheduled_time, $cache_schedule_interval, $cache_time_interval, $cache_gc_email_me, $wp_cache_preload_on;
1241
1242 wp_cache_update_rejected_pages();
1243 wp_cache_update_rejected_cookies();
1244 wp_cache_update_rejected_strings();
1245 wp_cache_update_accepted_strings();
1246 wp_cache_time_update();
1247
1248 wpsc_render_partial(
1249 'advanced',
1250 compact(
1251 'wp_cache_front_page_checks',
1252 'admin_url',
1253 'cache_enabled',
1254 'super_cache_enabled',
1255 'wp_cache_mod_rewrite',
1256 'is_nginx',
1257 'wp_cache_not_logged_in',
1258 'wp_cache_no_cache_for_get',
1259 'cache_compression',
1260 'cache_rebuild_files',
1261 'wpsc_save_headers',
1262 'wp_supercache_304',
1263 'wp_cache_make_known_anon',
1264 'wp_cache_mfunc_enabled',
1265 'wp_cache_mobile_enabled',
1266 'wp_cache_mobile_browsers',
1267 'wp_cache_disable_utf8',
1268 'wp_cache_clear_on_post_edit',
1269 'wp_cache_front_page_checks',
1270 'wp_cache_refresh_single_only',
1271 'wp_supercache_cache_list',
1272 'wp_cache_mutex_disabled',
1273 'wp_super_cache_late_init',
1274 'cache_page_secret',
1275 'cache_path',
1276 'cache_acceptable_files',
1277 'wpsc_rejected_cookies',
1278 'cache_rejected_uri',
1279 'wp_cache_pages',
1280 'cache_max_time',
1281 'valid_nonce',
1282 'super_cache_enabled',
1283 'cache_schedule_type',
1284 'cache_scheduled_time',
1285 'cache_schedule_interval',
1286 'cache_time_interval',
1287 'cache_gc_email_me',
1288 'wp_cache_mobile_prefixes',
1289 'wp_cache_preload_on'
1290 )
1291 );
1292
1293 wpsc_edit_tracking_parameters();
1294 wpsc_edit_rejected_ua();
1295 wpsc_lockdown();
1296 wpsc_restore_settings();
1297
1298 break;
1299 case 'easy':
1300 default:
1301 wpsc_render_partial(
1302 'easy',
1303 array(
1304 'admin_url' => $admin_url,
1305 'cache_enabled' => $cache_enabled,
1306 'is_nginx' => $is_nginx,
1307 'wp_cache_mod_rewrite' => $wp_cache_mod_rewrite,
1308 'valid_nonce' => $valid_nonce,
1309 'cache_path' => $cache_path,
1310 'wp_super_cache_comments' => $wp_super_cache_comments,
1311 )
1312 );
1313 break;
1314 }
1315 ?>
1316
1317 </fieldset>
1318 </td><td valign='top' style='width: 300px'>
1319 <!-- TODO: Hide #wpsc-callout from all pages except the Easy tab -->
1320 <div class="wpsc-card" id="wpsc-callout">
1321 <?php if ( ! empty( $wpsc_promo_links ) && is_array( $wpsc_promo_links ) ) : ?>
1322 <h4><?php esc_html_e( 'Other Site Tools', 'wp-super-cache' ); ?></h4>
1323 <ul style="list-style: square; margin-left: 2em;">
1324 <li><a href="<?php echo esc_url( $wpsc_promo_links['boost'] ); ?>"><?php esc_html_e( 'Boost your page speed scores', 'wp-super-cache' ); ?></a></li>
1325 <li><a href="<?php echo esc_url( $wpsc_promo_links['photon'] ); ?>"><?php esc_html_e( 'Speed up images and photos (free)', 'wp-super-cache' ); ?></a></li>
1326 <li><a href="<?php echo esc_url( $wpsc_promo_links['videopress'] ); ?>"><?php esc_html_e( 'Fast video hosting (paid)', 'wp-super-cache' ); ?></a></li>
1327 <li><a href="<?php echo esc_url( $wpsc_promo_links['crowdsignal'] ); ?>"><?php esc_html_e( 'Add Surveys and Polls to your site', 'wp-super-cache' ); ?></a></li>
1328 </ul>
1329 <?php endif; ?>
1330 <h4><?php _e( 'Need Help?', 'wp-super-cache' ); ?></h4>
1331 <ol>
1332 <li><?php printf( __( 'Use the <a href="%1$s">Debug tab</a> for diagnostics.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache&tab=debug' ) ); ?></li>
1333 <li>
1334 <?php
1335 echo wp_kses_post(
1336 sprintf(
1337 /* translators: %s is the URL for the documentation. */
1338 __( 'Check out the <a href="%s">plugin documentation</a>.', 'wp-super-cache' ),
1339 'https://jetpack.com/support/wp-super-cache/'
1340 )
1341 );
1342 ?>
1343 </li>
1344 <li>
1345 <?php
1346 echo wp_kses_post(
1347 sprintf(
1348 /* translators: %1$s is the URL for the support forum. */
1349 __( 'Visit the <a href="%1$s">support forum</a>.', 'wp-super-cache' ),
1350 'https://wordpress.org/support/plugin/wp-super-cache/'
1351 )
1352 );
1353 ?>
1354 </li>
1355 <li><?php printf( __( 'Try out the <a href="%1$s">development version</a> for the latest fixes (<a href="%2$s">changelog</a>).', 'wp-super-cache' ), 'https://odd.blog/y/2o', 'https://plugins.trac.wordpress.org/log/wp-super-cache/' ); ?></li>
1356 </ol>
1357 <h4><?php esc_html_e( 'Rate This Plugin', 'wp-super-cache' ); ?></h4>
1358 <p><?php printf( __( 'Please <a href="%s">rate us</a> and give feedback.', 'wp-super-cache' ), 'https://wordpress.org/support/plugin/wp-super-cache/reviews?rate=5#new-post' ); ?></p>
1359
1360 <?php
1361 if ( isset( $wp_supercache_cache_list ) && $wp_supercache_cache_list ) {
1362 $start_date = get_option( 'wpsupercache_start' );
1363 if ( ! $start_date ) {
1364 $start_date = time();
1365 }
1366 ?>
1367 <p><?php printf( __( 'Cached pages since %1$s : <strong>%2$s</strong>', 'wp-super-cache' ), date( 'M j, Y', $start_date ), number_format( get_option( 'wpsupercache_count' ) ) ); ?></p>
1368 <p><?php _e( 'Newest Cached Pages:', 'wp-super-cache' ); ?><ol>
1369 <?php
1370 foreach ( array_reverse( (array) get_option( 'supercache_last_cached' ) ) as $url ) {
1371 $since = time() - strtotime( $url['date'] );
1372 echo "<li><a title='" . sprintf( esc_html__( 'Cached %s seconds ago', 'wp-super-cache' ), (int) $since ) . "' href='" . site_url( $url['url'] ) . "'>" . substr( $url['url'], 0, 20 ) . "</a></li>\n";
1373 }
1374 ?>
1375 </ol>
1376 <small><?php esc_html_e( '(may not always be accurate on busy sites)', 'wp-super-cache' ); ?></small>
1377 </p><?php
1378 } elseif ( false == get_option( 'wpsupercache_start' ) ) {
1379 update_option( 'wpsupercache_start', time() );
1380 update_option( 'wpsupercache_count', 0 );
1381 }
1382 ?>
1383 </div>
1384 </td></table>
1385 </div>
1386 </div>
1387 <?php wpsc_render_footer(); ?>
1388 </div>
1389 <?php
1390 }
1391
1392 function wpsc_plugins_tab() {
1393 echo '<div class="wpsc-card">';
1394 echo '<p>' . esc_html__( 'Cache plugins are PHP scripts you\'ll find in a dedicated folder inside the WP Super Cache folder (wp-super-cache/plugins/). They load at the same time as WP Super Cache, and before regular WordPress plugins.', 'wp-super-cache' ) . '</p>';
1395 echo '<p>' . esc_html__( 'Keep in mind that cache plugins are for advanced users only. To create and manage them, you\'ll need extensive knowledge of both PHP and WordPress actions.', 'wp-super-cache' ) . '</p>';
1396 echo '<p>' . sprintf( __( '<strong>Warning</strong>! Due to the way WordPress upgrades plugins, the ones you upload to the WP Super Cache folder (wp-super-cache/plugins/) will be deleted when you upgrade WP Super Cache. To avoid this loss, load your cache plugins from a different location. When you set <strong>$wp_cache_plugins_dir</strong> to the new location in wp-config.php, WP Super Cache will look there instead. <br />You can find additional details in the <a href="%s">developer documentation</a>.', 'wp-super-cache' ), 'https://odd.blog/wp-super-cache-developers/' ) . '</p>';
1397 echo '</div>';
1398 echo '<div class="wpsc-card">';
1399 ob_start();
1400 if ( defined( 'WP_CACHE' ) ) {
1401 if ( function_exists( 'do_cacheaction' ) ) {
1402 do_cacheaction( 'cache_admin_page' );
1403 }
1404 }
1405 $out = ob_get_contents();
1406 ob_end_clean();
1407
1408 if ( SUBMITDISABLED == ' ' && $out != '' ) {
1409 echo '<h4>' . esc_html__( 'Available Plugins', 'wp-super-cache' ) . '</h4>';
1410 echo '<ol>';
1411 echo $out;
1412 echo '</ol>';
1413 }
1414 echo '</div>';
1415 }
1416
1417 function wpsc_admin_tabs( $current = '' ) {
1418 global $cache_enabled, $super_cache_enabled, $wp_cache_mod_rewrite;
1419
1420 if ( '' === $current ) {
1421 $current = ! empty( $_GET['tab'] ) ? stripslashes( $_GET['tab'] ) : ''; // WPCS: CSRF ok, sanitization ok.
1422 }
1423
1424 $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
1425 $admin_tabs = array(
1426 'easy' => __( 'Easy', 'wp-super-cache' ),
1427 'settings' => __( 'Advanced', 'wp-super-cache' ),
1428 'cdn' => __( 'CDN', 'wp-super-cache' ),
1429 'contents' => __( 'Contents', 'wp-super-cache' ),
1430 'preload' => __( 'Preload', 'wp-super-cache' ),
1431 'plugins' => __( 'Plugins', 'wp-super-cache' ),
1432 'debug' => __( 'Debug', 'wp-super-cache' ),
1433 );
1434
1435 echo '<div class="wpsc-nav-container"><ul class="wpsc-nav">';
1436
1437 foreach ( $admin_tabs as $tab => $name ) {
1438 printf(
1439 '<li class="%s"><a href="%s">%s</a></li>',
1440 esc_attr( $tab === $current ? 'wpsc-nav-tab wpsc-nav-tab-selected' : 'wpsc-nav-tab' ),
1441 esc_url_raw( add_query_arg( 'tab', $tab, $admin_url ) ),
1442 esc_html( $name )
1443 );
1444 }
1445
1446 echo '</ul></div>';
1447 }
1448
1449 function wpsc_restore_settings() {
1450 $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
1451 wpsc_render_partial(
1452 'restore',
1453 compact( 'admin_url' )
1454 );
1455 }
1456
1457 function comment_form_lockdown_message() {
1458 ?><p><?php _e( "Comment moderation is enabled. Your comment may take some time to appear.", 'wp-super-cache' ); ?></p><?php
1459 }
1460 if( defined( 'WPLOCKDOWN' ) && constant( 'WPLOCKDOWN' ) )
1461 add_action( 'comment_form', 'comment_form_lockdown_message' );
1462
1463 function wp_update_lock_down() {
1464 global $cache_path, $wp_cache_config_file, $valid_nonce;
1465
1466 if ( isset( $_POST[ 'wp_lock_down' ] ) && $valid_nonce ) {
1467 $wp_lock_down = $_POST[ 'wp_lock_down' ] == '1' ? '1' : '0';
1468 wp_cache_replace_line( '^.*WPLOCKDOWN', "if ( ! defined( 'WPLOCKDOWN' ) ) define( 'WPLOCKDOWN', '$wp_lock_down' );", $wp_cache_config_file );
1469 if ( false == defined( 'WPLOCKDOWN' ) )
1470 define( 'WPLOCKDOWN', $wp_lock_down );
1471 if ( $wp_lock_down == '0' && function_exists( 'prune_super_cache' ) )
1472 prune_super_cache( $cache_path, true ); // clear the cache after lockdown
1473 return $wp_lock_down;
1474 }
1475 if ( defined( 'WPLOCKDOWN' ) )
1476 return constant( 'WPLOCKDOWN' );
1477 else
1478 return 0;
1479 }
1480
1481 function wpsc_update_direct_pages() {
1482 global $cached_direct_pages, $valid_nonce, $cache_path, $wp_cache_config_file;
1483
1484 if ( false == isset( $cached_direct_pages ) )
1485 $cached_direct_pages = array();
1486 $out = '';
1487 if ( $valid_nonce && array_key_exists('direct_pages', $_POST) && is_array( $_POST[ 'direct_pages' ] ) && !empty( $_POST[ 'direct_pages' ] ) ) {
1488 $expiredfiles = array_diff( $cached_direct_pages, $_POST[ 'direct_pages' ] );
1489 unset( $cached_direct_pages );
1490 foreach( $_POST[ 'direct_pages' ] as $page ) {
1491 $page = str_replace( '..', '', preg_replace( '/[ <>\'\"\r\n\t\(\)\$\[\];#]/', '', $page ) );
1492 if ( $page != '' ) {
1493 $cached_direct_pages[] = $page;
1494 $out .= "'$page', ";
1495 }
1496 }
1497 if ( false == isset( $cached_direct_pages ) )
1498 $cached_direct_pages = array();
1499 }
1500 if ( $valid_nonce && array_key_exists('new_direct_page', $_POST) && $_POST[ 'new_direct_page' ] && '' != $_POST[ 'new_direct_page' ] ) {
1501 $page = str_replace( get_option( 'siteurl' ), '', $_POST[ 'new_direct_page' ] );
1502 $page = str_replace( '..', '', preg_replace( '/[ <>\'\"\r\n\t\(\)\$\[\];#]/', '', $page ) );
1503 if ( substr( $page, 0, 1 ) != '/' )
1504 $page = '/' . $page;
1505 if ( $page != '/' || false == is_array( $cached_direct_pages ) || in_array( $page, $cached_direct_pages ) == false ) {
1506 $cached_direct_pages[] = $page;
1507 $out .= "'$page', ";
1508
1509 @unlink( trailingslashit( ABSPATH . $page ) . "index.html" );
1510 wpsc_delete_files( get_supercache_dir() . $page );
1511 }
1512 }
1513
1514 if ( $out != '' ) {
1515 $out = substr( $out, 0, -2 );
1516 }
1517 if ( $out == "''" ) {
1518 $out = '';
1519 }
1520 $out = '$cached_direct_pages = array( ' . $out . ' );';
1521 wp_cache_replace_line('^ *\$cached_direct_pages', "$out", $wp_cache_config_file);
1522
1523 if ( !empty( $expiredfiles ) ) {
1524 foreach( $expiredfiles as $file ) {
1525 if( $file != '' ) {
1526 $firstfolder = explode( '/', $file );
1527 $firstfolder = ABSPATH . $firstfolder[1];
1528 $file = ABSPATH . $file;
1529 $file = realpath( str_replace( '..', '', preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', $file ) ) );
1530 if ( $file ) {
1531 @unlink( trailingslashit( $file ) . "index.html" );
1532 @unlink( trailingslashit( $file ) . "index.html.gz" );
1533 RecursiveFolderDelete( trailingslashit( $firstfolder ) );
1534 }
1535 }
1536 }
1537 }
1538
1539 if ( $valid_nonce && array_key_exists('deletepage', $_POST) && $_POST[ 'deletepage' ] ) {
1540 $page = str_replace( '..', '', preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', $_POST['deletepage'] ) ) . '/';
1541 $pagefile = realpath( ABSPATH . $page . 'index.html' );
1542 if ( substr( $pagefile, 0, strlen( ABSPATH ) ) != ABSPATH || false == wp_cache_confirm_delete( ABSPATH . $page ) ) {
1543 die( __( 'Cannot delete directory', 'wp-super-cache' ) );
1544 }
1545 $firstfolder = explode( '/', $page );
1546 $firstfolder = ABSPATH . $firstfolder[1];
1547 $page = ABSPATH . $page;
1548 if( is_file( $pagefile ) && is_writeable_ACLSafe( $pagefile ) && is_writeable_ACLSafe( $firstfolder ) ) {
1549 @unlink( $pagefile );
1550 @unlink( $pagefile . '.gz' );
1551 RecursiveFolderDelete( $firstfolder );
1552 }
1553 }
1554
1555 return $cached_direct_pages;
1556 }
1557
1558 function wpsc_lockdown() {
1559 global $cached_direct_pages, $cache_enabled, $super_cache_enabled;
1560
1561 $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
1562 $wp_lock_down = wp_update_lock_down();
1563
1564 wpsc_render_partial(
1565 'lockdown',
1566 compact( 'cached_direct_pages', 'cache_enabled', 'super_cache_enabled', 'admin_url', 'wp_lock_down' )
1567 );
1568 }
1569
1570 function RecursiveFolderDelete ( $folderPath ) { // from http://www.php.net/manual/en/function.rmdir.php
1571 if( trailingslashit( constant( 'ABSPATH' ) ) == trailingslashit( $folderPath ) )
1572 return false;
1573 if ( @is_dir ( $folderPath ) ) {
1574 $dh = @opendir($folderPath);
1575 while (false !== ($value = @readdir($dh))) {
1576 if ( $value != "." && $value != ".." ) {
1577 $value = $folderPath . "/" . $value;
1578 if ( @is_dir ( $value ) ) {
1579 RecursiveFolderDelete ( $value );
1580 }
1581 }
1582 }
1583 return @rmdir ( $folderPath );
1584 } else {
1585 return FALSE;
1586 }
1587 }
1588
1589 function wp_cache_time_update() {
1590 global $cache_max_time, $wp_cache_config_file, $valid_nonce, $cache_schedule_type, $cache_scheduled_time, $cache_schedule_interval, $cache_time_interval, $cache_gc_email_me;
1591 if ( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'expirytime' ) {
1592
1593 if ( false == $valid_nonce )
1594 return false;
1595
1596 if( !isset( $cache_schedule_type ) ) {
1597 $cache_schedule_type = 'interval';
1598 wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
1599 }
1600
1601 if( !isset( $cache_scheduled_time ) ) {
1602 $cache_scheduled_time = '00:00';
1603 wp_cache_replace_line('^ *\$cache_scheduled_time', "\$cache_scheduled_time = '$cache_scheduled_time';", $wp_cache_config_file);
1604 }
1605
1606 if( !isset( $cache_max_time ) ) {
1607 $cache_max_time = 3600;
1608 wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file);
1609 }
1610
1611 if ( !isset( $cache_time_interval ) ) {
1612 $cache_time_interval = $cache_max_time;
1613 wp_cache_replace_line('^ *\$cache_time_interval', "\$cache_time_interval = '$cache_time_interval';", $wp_cache_config_file);
1614 }
1615
1616 if ( isset( $_POST['wp_max_time'] ) ) {
1617 $cache_max_time = (int)$_POST['wp_max_time'];
1618 wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file);
1619 // schedule gc watcher
1620 if ( false == wp_next_scheduled( 'wp_cache_gc_watcher' ) )
1621 wp_schedule_event( time()+600, 'hourly', 'wp_cache_gc_watcher' );
1622 }
1623
1624 if ( isset( $_POST[ 'cache_gc_email_me' ] ) ) {
1625 $cache_gc_email_me = 1;
1626 wp_cache_replace_line('^ *\$cache_gc_email_me', "\$cache_gc_email_me = $cache_gc_email_me;", $wp_cache_config_file);
1627 } else {
1628 $cache_gc_email_me = 0;
1629 wp_cache_replace_line('^ *\$cache_gc_email_me', "\$cache_gc_email_me = $cache_gc_email_me;", $wp_cache_config_file);
1630 }
1631 if ( isset( $_POST[ 'cache_schedule_type' ] ) && $_POST[ 'cache_schedule_type' ] == 'interval' && isset( $_POST['cache_time_interval'] ) ) {
1632 wp_clear_scheduled_hook( 'wp_cache_gc' );
1633 $cache_schedule_type = 'interval';
1634 if ( (int)$_POST[ 'cache_time_interval' ] == 0 )
1635 $_POST[ 'cache_time_interval' ] = 600;
1636 $cache_time_interval = (int)$_POST[ 'cache_time_interval' ];
1637 wp_schedule_single_event( time() + $cache_time_interval, 'wp_cache_gc' );
1638 wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
1639 wp_cache_replace_line('^ *\$cache_time_interval', "\$cache_time_interval = '$cache_time_interval';", $wp_cache_config_file);
1640 } else { // clock
1641 wp_clear_scheduled_hook( 'wp_cache_gc' );
1642 $cache_schedule_type = 'time';
1643 if ( !isset( $_POST[ 'cache_scheduled_time' ] ) ||
1644 $_POST[ 'cache_scheduled_time' ] == '' ||
1645 5 != strlen( $_POST[ 'cache_scheduled_time' ] ) ||
1646 ":" != substr( $_POST[ 'cache_scheduled_time' ], 2, 1 )
1647 )
1648 $_POST[ 'cache_scheduled_time' ] = '00:00';
1649
1650 $cache_scheduled_time = $_POST[ 'cache_scheduled_time' ];
1651
1652 if ( ! preg_match( '/[0-9][0-9]:[0-9][0-9]/', $cache_scheduled_time ) ) {
1653 $cache_scheduled_time = '00:00';
1654 }
1655 $schedules = wp_get_schedules();
1656 if ( !isset( $cache_schedule_interval ) )
1657 $cache_schedule_interval = 'daily';
1658 if ( isset( $_POST[ 'cache_schedule_interval' ] ) && isset( $schedules[ $_POST[ 'cache_schedule_interval' ] ] ) )
1659 $cache_schedule_interval = $_POST[ 'cache_schedule_interval' ];
1660 wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
1661 wp_cache_replace_line('^ *\$cache_schedule_interval', "\$cache_schedule_interval = '{$cache_schedule_interval}';", $wp_cache_config_file);
1662 wp_cache_replace_line('^ *\$cache_scheduled_time', "\$cache_scheduled_time = '$cache_scheduled_time';", $wp_cache_config_file);
1663 wp_schedule_event( strtotime( $cache_scheduled_time ), $cache_schedule_interval, 'wp_cache_gc' );
1664 }
1665 }
1666 }
1667
1668 function wp_cache_sanitize_value($text, & $array) {
1669 $text = esc_html(strip_tags($text));
1670 $array = preg_split( '/[\s,]+/', rtrim( $text ) );
1671 $text = var_export($array, true);
1672 $text = preg_replace('/[\s]+/', ' ', $text);
1673 return $text;
1674 }
1675
1676 function wp_cache_update_rejected_ua() {
1677 global $cache_rejected_user_agent, $wp_cache_config_file, $valid_nonce;
1678
1679 if ( isset( $_POST[ 'wp_rejected_user_agent' ] ) && $valid_nonce ) {
1680 $_POST[ 'wp_rejected_user_agent' ] = str_replace( ' ', '___', $_POST[ 'wp_rejected_user_agent' ] );
1681 $text = str_replace( '___', ' ', wp_cache_sanitize_value( $_POST[ 'wp_rejected_user_agent' ], $cache_rejected_user_agent ) );
1682 wp_cache_replace_line( '^ *\$cache_rejected_user_agent', "\$cache_rejected_user_agent = $text;", $wp_cache_config_file );
1683 foreach( $cache_rejected_user_agent as $k => $ua ) {
1684 $cache_rejected_user_agent[ $k ] = str_replace( '___', ' ', $ua );
1685 }
1686 reset( $cache_rejected_user_agent );
1687 }
1688 }
1689
1690 function wpsc_edit_rejected_ua() {
1691 global $cache_rejected_user_agent;
1692
1693 $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
1694 wp_cache_update_rejected_ua();
1695 wpsc_render_partial(
1696 'rejected_user_agents',
1697 compact( 'cache_rejected_user_agent', 'admin_url' )
1698 );
1699 }
1700
1701 function wp_cache_update_rejected_pages() {
1702 global $wp_cache_config_file, $valid_nonce, $wp_cache_pages;
1703
1704 if ( isset( $_POST[ 'wp_edit_rejected_pages' ] ) && $valid_nonce ) {
1705 $pages = array( 'single', 'pages', 'archives', 'tag', 'frontpage', 'home', 'category', 'feed', 'author', 'search' );
1706 foreach( $pages as $page ) {
1707 if ( isset( $_POST[ 'wp_cache_pages' ][ $page ] ) ) {
1708 $value = 1;
1709 } else {
1710 $value = 0;
1711 }
1712 wp_cache_replace_line('^ *\$wp_cache_pages\[ "' . $page . '" \]', "\$wp_cache_pages[ \"{$page}\" ] = $value;", $wp_cache_config_file);
1713 $wp_cache_pages[ $page ] = $value;
1714 }
1715 }
1716 }
1717
1718 function wpsc_update_tracking_parameters() {
1719 global $wpsc_tracking_parameters, $valid_nonce, $wp_cache_config_file;
1720
1721 if ( isset( $_POST['tracking_parameters'] ) && $valid_nonce ) {
1722 $text = wp_cache_sanitize_value( str_replace( '\\\\', '\\', $_POST['tracking_parameters'] ), $wpsc_tracking_parameters );
1723 wp_cache_replace_line( '^ *\$wpsc_tracking_parameters', "\$wpsc_tracking_parameters = $text;", $wp_cache_config_file );
1724 wp_cache_setting( 'wpsc_ignore_tracking_parameters', isset( $_POST['wpsc_ignore_tracking_parameters'] ) ? 1 : 0 );
1725 }
1726 }
1727
1728 function wpsc_edit_tracking_parameters() {
1729 global $wpsc_tracking_parameters, $wpsc_ignore_tracking_parameters;
1730
1731 $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
1732 wpsc_update_tracking_parameters();
1733
1734 if ( ! isset( $wpsc_tracking_parameters ) ) {
1735 $wpsc_tracking_parameters = array( 'fbclid', 'ref', 'gclid', 'fb_source', 'mc_cid', 'mc_eid', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'utm_expid', 'mtm_source', 'mtm_medium', 'mtm_campaign', 'mtm_keyword', 'mtm_content', 'mtm_cid', 'mtm_group', 'mtm_placement' );
1736 }
1737
1738 if ( ! isset( $wpsc_ignore_tracking_parameters ) ) {
1739 $wpsc_ignore_tracking_parameters = 0;
1740 }
1741 wpsc_render_partial(
1742 'tracking_parameters',
1743 compact( 'wpsc_ignore_tracking_parameters', 'wpsc_tracking_parameters', 'admin_url' )
1744 );
1745 }
1746
1747 function wp_cache_update_rejected_cookies() {
1748 global $wpsc_rejected_cookies, $wp_cache_config_file, $valid_nonce;
1749
1750 if ( isset( $_POST['wp_rejected_cookies'] ) && $valid_nonce ) {
1751 $text = wp_cache_sanitize_value( str_replace( '\\\\', '\\', $_POST['wp_rejected_cookies'] ), $wpsc_rejected_cookies );
1752 wp_cache_replace_line( '^ *\$wpsc_rejected_cookies', "\$wpsc_rejected_cookies = $text;", $wp_cache_config_file );
1753 }
1754 }
1755
1756 function wp_cache_update_rejected_strings() {
1757 global $cache_rejected_uri, $wp_cache_config_file, $valid_nonce;
1758
1759 if ( isset($_REQUEST['wp_rejected_uri']) && $valid_nonce ) {
1760 $text = wp_cache_sanitize_value( str_replace( '\\\\', '\\', $_REQUEST['wp_rejected_uri'] ), $cache_rejected_uri );
1761 wp_cache_replace_line('^ *\$cache_rejected_uri', "\$cache_rejected_uri = $text;", $wp_cache_config_file);
1762 }
1763 }
1764
1765 function wp_cache_update_accepted_strings() {
1766 global $cache_acceptable_files, $wp_cache_config_file, $valid_nonce;
1767
1768 if ( isset( $_REQUEST[ 'wp_accepted_files' ] ) && $valid_nonce ) {
1769 $text = wp_cache_sanitize_value( $_REQUEST[ 'wp_accepted_files' ], $cache_acceptable_files );
1770 wp_cache_replace_line( '^ *\$cache_acceptable_files', "\$cache_acceptable_files = $text;", $wp_cache_config_file );
1771 }
1772 }
1773
1774 function wpsc_update_debug_settings() {
1775 global $wp_super_cache_debug, $wp_cache_debug_log, $wp_cache_debug_ip, $cache_path, $valid_nonce, $wp_cache_config_file, $wp_super_cache_comments;
1776 global $wp_super_cache_front_page_check, $wp_super_cache_front_page_clear, $wp_super_cache_front_page_text, $wp_super_cache_front_page_notification, $wp_super_cache_advanced_debug;
1777 global $wp_cache_debug_username;
1778
1779 if ( ! isset( $wp_super_cache_comments ) ) {
1780 $wp_super_cache_comments = 1; // defaults to "enabled".
1781 wp_cache_setting( 'wp_super_cache_comments', $wp_super_cache_comments );
1782 }
1783
1784 if ( false == $valid_nonce ) {
1785 return array (
1786 'wp_super_cache_debug' => $wp_super_cache_debug,
1787 'wp_cache_debug_log' => $wp_cache_debug_log,
1788 'wp_cache_debug_ip' => $wp_cache_debug_ip,
1789 'wp_super_cache_comments' => $wp_super_cache_comments,
1790 'wp_super_cache_front_page_check' => $wp_super_cache_front_page_check,
1791 'wp_super_cache_front_page_clear' => $wp_super_cache_front_page_clear,
1792 'wp_super_cache_front_page_text' => $wp_super_cache_front_page_text,
1793 'wp_super_cache_front_page_notification' => $wp_super_cache_front_page_notification,
1794 'wp_super_cache_advanced_debug' => $wp_super_cache_advanced_debug,
1795 'wp_cache_debug_username' => $wp_cache_debug_username,
1796 );
1797 }
1798
1799 if ( isset( $_POST[ 'wpsc_delete_log' ] ) && $_POST[ 'wpsc_delete_log' ] == 1 && $wp_cache_debug_log != '' ) {
1800 @unlink( $cache_path . $wp_cache_debug_log );
1801 extract( wpsc_create_debug_log( $wp_cache_debug_log, $wp_cache_debug_username ) ); // $wp_cache_debug_log, $wp_cache_debug_username
1802 }
1803
1804 if ( ! isset( $wp_cache_debug_log ) || $wp_cache_debug_log == '' ) {
1805 extract( wpsc_create_debug_log() ); // $wp_cache_debug_log, $wp_cache_debug_username
1806 } elseif ( ! file_exists( $cache_path . $wp_cache_debug_log ) ) { // make sure debug log exists before toggling debugging
1807 extract( wpsc_create_debug_log( $wp_cache_debug_log, $wp_cache_debug_username ) ); // $wp_cache_debug_log, $wp_cache_debug_username
1808 }
1809 $wp_super_cache_debug = ( isset( $_POST[ 'wp_super_cache_debug' ] ) && $_POST[ 'wp_super_cache_debug' ] == 1 ) ? 1 : 0;
1810 wp_cache_setting( 'wp_super_cache_debug', $wp_super_cache_debug );
1811
1812 if ( isset( $_POST[ 'wp_cache_debug' ] ) ) {
1813 wp_cache_setting( 'wp_cache_debug_username', $wp_cache_debug_username );
1814 wp_cache_setting( 'wp_cache_debug_log', $wp_cache_debug_log );
1815 $wp_super_cache_comments = isset( $_POST[ 'wp_super_cache_comments' ] ) ? 1 : 0;
1816 wp_cache_setting( 'wp_super_cache_comments', $wp_super_cache_comments );
1817 if ( isset( $_POST[ 'wp_cache_debug_ip' ] ) && filter_var( $_POST[ 'wp_cache_debug_ip' ], FILTER_VALIDATE_IP ) ) {
1818 $wp_cache_debug_ip = esc_html( preg_replace( '/[ <>\'\"\r\n\t\(\)\$\[\];#]/', '', $_POST[ 'wp_cache_debug_ip' ] ) );
1819 } else {
1820 $wp_cache_debug_ip = '';
1821 }
1822 wp_cache_setting( 'wp_cache_debug_ip', $wp_cache_debug_ip );
1823 $wp_super_cache_front_page_check = isset( $_POST[ 'wp_super_cache_front_page_check' ] ) ? 1 : 0;
1824 wp_cache_setting( 'wp_super_cache_front_page_check', $wp_super_cache_front_page_check );
1825 $wp_super_cache_front_page_clear = isset( $_POST[ 'wp_super_cache_front_page_clear' ] ) ? 1 : 0;
1826 wp_cache_setting( 'wp_super_cache_front_page_clear', $wp_super_cache_front_page_clear );
1827 if ( isset( $_POST[ 'wp_super_cache_front_page_text' ] ) ) {
1828 $wp_super_cache_front_page_text = esc_html( preg_replace( '/[ <>\'\"\r\n\t\(\)\$\[\];#]/', '', $_POST[ 'wp_super_cache_front_page_text' ] ) );
1829 } else {
1830 $wp_super_cache_front_page_text = '';
1831 }
1832 wp_cache_setting( 'wp_super_cache_front_page_text', $wp_super_cache_front_page_text );
1833 $wp_super_cache_front_page_notification = isset( $_POST[ 'wp_super_cache_front_page_notification' ] ) ? 1 : 0;
1834 wp_cache_setting( 'wp_super_cache_front_page_notification', $wp_super_cache_front_page_notification );
1835 if ( $wp_super_cache_front_page_check == 1 && !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
1836 wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
1837 wp_cache_debug( 'scheduled wp_cache_check_site_hook for 360 seconds time.' );
1838 }
1839 }
1840
1841 return array (
1842 'wp_super_cache_debug' => $wp_super_cache_debug,
1843 'wp_cache_debug_log' => $wp_cache_debug_log,
1844 'wp_cache_debug_ip' => $wp_cache_debug_ip,
1845 'wp_super_cache_comments' => $wp_super_cache_comments,
1846 'wp_super_cache_front_page_check' => $wp_super_cache_front_page_check,
1847 'wp_super_cache_front_page_clear' => $wp_super_cache_front_page_clear,
1848 'wp_super_cache_front_page_text' => $wp_super_cache_front_page_text,
1849 'wp_super_cache_front_page_notification' => $wp_super_cache_front_page_notification,
1850 'wp_super_cache_advanced_debug' => $wp_super_cache_advanced_debug,
1851 'wp_cache_debug_username' => $wp_cache_debug_username,
1852 );
1853 }
1854
1855 function wp_cache_enable() {
1856 global $wp_cache_config_file, $cache_enabled;
1857
1858 if ( $cache_enabled ) {
1859 wp_cache_debug( 'wp_cache_enable: already enabled' );
1860 return true;
1861 }
1862
1863 wp_cache_setting( 'cache_enabled', true );
1864 wp_cache_debug( 'wp_cache_enable: enable cache' );
1865
1866 $cache_enabled = true;
1867
1868 if ( wpsc_set_default_gc() ) {
1869 // gc might not be scheduled, check and schedule
1870 $timestamp = wp_next_scheduled( 'wp_cache_gc' );
1871 if ( false == $timestamp ) {
1872 wp_schedule_single_event( time() + 600, 'wp_cache_gc' );
1873 }
1874 }
1875 }
1876
1877 function wp_cache_disable() {
1878 global $wp_cache_config_file, $cache_enabled;
1879
1880 if ( ! $cache_enabled ) {
1881 wp_cache_debug( 'wp_cache_disable: already disabled' );
1882 return true;
1883 }
1884
1885 wp_cache_setting( 'cache_enabled', false );
1886 wp_cache_debug( 'wp_cache_disable: disable cache' );
1887
1888 $cache_enabled = false;
1889
1890 wp_clear_scheduled_hook( 'wp_cache_check_site_hook' );
1891 wp_clear_scheduled_hook( 'wp_cache_gc' );
1892 wp_clear_scheduled_hook( 'wp_cache_gc_watcher' );
1893 }
1894
1895 function wp_super_cache_enable() {
1896 global $supercachedir, $wp_cache_config_file, $super_cache_enabled;
1897
1898 if ( $super_cache_enabled ) {
1899 wp_cache_debug( 'wp_super_cache_enable: already enabled' );
1900 return true;
1901 }
1902
1903 wp_cache_setting( 'super_cache_enabled', true );
1904 wp_cache_debug( 'wp_super_cache_enable: enable cache' );
1905
1906 $super_cache_enabled = true;
1907
1908 if ( ! $supercachedir ) {
1909 $supercachedir = get_supercache_dir();
1910 }
1911
1912 if ( is_dir( $supercachedir . '.disabled' ) ) {
1913 if ( is_dir( $supercachedir ) ) {
1914 prune_super_cache( $supercachedir . '.disabled', true );
1915 @unlink( $supercachedir . '.disabled' );
1916 } else {
1917 @rename( $supercachedir . '.disabled', $supercachedir );
1918 }
1919 }
1920 }
1921
1922 function wp_super_cache_disable() {
1923 global $cache_path, $supercachedir, $wp_cache_config_file, $super_cache_enabled;
1924
1925 if ( ! $super_cache_enabled ) {
1926 wp_cache_debug( 'wp_super_cache_disable: already disabled' );
1927 return true;
1928 }
1929
1930 wp_cache_setting( 'super_cache_enabled', false );
1931 wp_cache_debug( 'wp_super_cache_disable: disable cache' );
1932
1933 $super_cache_enabled = false;
1934
1935 if ( ! $supercachedir ) {
1936 $supercachedir = get_supercache_dir();
1937 }
1938
1939 if ( is_dir( $supercachedir ) ) {
1940 @rename( $supercachedir, $supercachedir . '.disabled' );
1941 }
1942 sleep( 1 ); // allow existing processes to write to the supercachedir and then delete it
1943 if ( function_exists( 'prune_super_cache' ) && is_dir( $supercachedir ) ) {
1944 prune_super_cache( $cache_path, true );
1945 }
1946
1947 if ( $GLOBALS['wp_cache_mod_rewrite'] === 1 ) {
1948 remove_mod_rewrite_rules();
1949 }
1950 }
1951
1952 function wp_cache_is_enabled() {
1953 global $wp_cache_config_file;
1954
1955 if ( get_option( 'gzipcompression' ) ) {
1956 echo '<strong>' . __( 'Warning', 'wp-super-cache' ) . '</strong>: ' . __( 'GZIP compression is enabled in WordPress, wp-cache will be bypassed until you disable gzip compression.', 'wp-super-cache' );
1957 return false;
1958 }
1959
1960 $lines = file( $wp_cache_config_file );
1961 foreach ( $lines as $line ) {
1962 if ( preg_match( '/^\s*\$cache_enabled\s*=\s*true\s*;/', $line ) ) {
1963 return true;
1964 }
1965 }
1966
1967 return false;
1968 }
1969
1970 function wp_cache_remove_index() {
1971 global $cache_path;
1972
1973 if ( empty( $cache_path ) ) {
1974 return;
1975 }
1976
1977 @unlink( $cache_path . "index.html" );
1978 @unlink( $cache_path . "supercache/index.html" );
1979 @unlink( $cache_path . "blogs/index.html" );
1980 if ( is_dir( $cache_path . "blogs" ) ) {
1981 $dir = new DirectoryIterator( $cache_path . "blogs" );
1982 foreach( $dir as $fileinfo ) {
1983 if ( $fileinfo->isDot() ) {
1984 continue;
1985 }
1986 if ( $fileinfo->isDir() ) {
1987 $directory = $cache_path . "blogs/" . $fileinfo->getFilename();
1988 if ( is_file( $directory . "/index.html" ) ) {
1989 unlink( $directory . "/index.html" );
1990 }
1991 if ( is_dir( $directory . "/meta" ) ) {
1992 if ( is_file( $directory . "/meta/index.html" ) ) {
1993 unlink( $directory . "/meta/index.html" );
1994 }
1995 }
1996 }
1997 }
1998 }
1999 }
2000
2001 function wp_cache_index_notice() {
2002 global $cache_path;
2003
2004 if ( false == wpsupercache_site_admin() )
2005 return false;
2006 if ( false == get_site_option( 'wp_super_cache_index_detected' ) )
2007 return false;
2008
2009 if ( strlen( $cache_path ) < strlen( ABSPATH )
2010 || ABSPATH != substr( $cache_path, 0, strlen( ABSPATH ) ) )
2011 return false; // cache stored outside web root
2012
2013 if ( get_site_option( 'wp_super_cache_index_detected' ) == 2 ) {
2014 update_site_option( 'wp_super_cache_index_detected', 3 );
2015 echo "<div class='error' style='padding: 10px 10px 50px 10px'>";
2016 echo "<h2>" . __( 'WP Super Cache Warning!', 'wp-super-cache' ) . '</h2>';
2017 echo '<p>' . __( 'All users of this site have been logged out to refresh their login cookies.', 'wp-super-cache' ) . '</p>';
2018 echo '</div>';
2019 return false;
2020 } elseif ( get_site_option( 'wp_super_cache_index_detected' ) != 3 ) {
2021 echo "<div id='wpsc-index-warning' class='error notice' style='padding: 10px 10px 50px 10px'>";
2022 echo "<h2>" . __( 'WP Super Cache Warning!', 'wp-super-cache' ) . '</h2>';
2023 echo '<p>' . __( 'Your server is configured to show files and directories, which may expose sensitive data such as login cookies to attackers in the cache directories. That has been fixed by adding a file named index.html to each directory. If you use simple caching, consider moving the location of the cache directory on the Advanced Settings page.', 'wp-super-cache' ) . '</p>';
2024 echo "<p><strong>";
2025 _e( 'If you just installed WP Super Cache for the first time, you can dismiss this message. Otherwise, you should probably refresh the login cookies of all logged in WordPress users here by clicking the logout link below.', 'wp-super-cache' );
2026 echo "</strong></p>";
2027 echo '<p>' . esc_html__( 'The logout link will log out all WordPress users on this site except you. Your authentication cookie will be updated, but you will not be logged out.', 'wp-super-cache' ) . '</p>';
2028 echo '<a id="wpsc-dismiss" href="#">' . esc_html__( 'Dismiss', 'wp-super-cache' ) . '</a>';
2029 echo ' | <a href="' . esc_url( wp_nonce_url( admin_url( '?action=wpsclogout' ), 'wpsc_logout' ) ) . '">' . esc_html__( 'Logout', 'wp-super-cache' ) . '</a>';
2030 echo '</div>';
2031 ?>
2032 <script type='text/javascript'>
2033 <!--
2034 jQuery(document).ready(function(){
2035 jQuery('#wpsc-dismiss').on("click",function() {
2036 jQuery.ajax({
2037 type: "post",url: "admin-ajax.php",data: { action: 'wpsc-index-dismiss', _ajax_nonce: '<?php echo wp_create_nonce( 'wpsc-index-dismiss' ); ?>' },
2038 beforeSend: function() {jQuery("#wpsc-index-warning").fadeOut('slow');},
2039 });
2040 })
2041 })
2042 //-->
2043 </script>
2044 <?php
2045 }
2046 }
2047 add_action( 'admin_notices', 'wp_cache_index_notice' );
2048
2049 function wpsc_config_file_notices() {
2050 global $wp_cache_config_file;
2051 if ( ! isset( $_GET['page'] ) || $_GET['page'] != 'wpsupercache' ) {
2052 return false;
2053 }
2054 $notice = get_transient( 'wpsc_config_error' );
2055 if ( ! $notice ) {
2056 return false;
2057 }
2058 switch( $notice ) {
2059 case 'error_move_tmp_config_file':
2060 $msg = sprintf( __( 'Error: Could not rename temporary file to configuration file. Please make sure %s is writeable by the webserver.' ), $wp_cache_config_file );
2061 break;
2062 case 'config_file_ro':
2063 $msg = sprintf( __( 'Error: Configuration file is read only. Please make sure %s is writeable by the webserver.' ), $wp_cache_config_file );
2064 break;
2065 case 'tmp_file_ro':
2066 $msg = sprintf( __( 'Error: The directory containing the configuration file %s is read only. Please make sure it is writeable by the webserver.' ), $wp_cache_config_file );
2067 break;
2068 case 'config_file_not_loaded':
2069 $msg = sprintf( __( 'Error: Configuration file %s could not be loaded. Please reload the page.' ), $wp_cache_config_file );
2070 break;
2071 case 'config_file_missing':
2072 $msg = sprintf( __( 'Error: Configuration file %s is missing. Please reload the page.' ), $wp_cache_config_file );
2073 break;
2074
2075 }
2076 echo '<div class="error"><p><strong>' . $msg . '</strong></p></div>';
2077 }
2078 add_action( 'admin_notices', 'wpsc_config_file_notices' );
2079 function wpsc_dismiss_indexhtml_warning() {
2080 check_ajax_referer( "wpsc-index-dismiss" );
2081 update_site_option( 'wp_super_cache_index_detected', 3 );
2082 die();
2083 }
2084 add_action( 'wp_ajax_wpsc-index-dismiss', 'wpsc_dismiss_indexhtml_warning' );
2085
2086 function wp_cache_logout_all() {
2087 global $current_user;
2088 if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'wpsclogout' && wp_verify_nonce( $_GET[ '_wpnonce' ], 'wpsc_logout' ) ) {
2089 $user_id = $current_user->ID;
2090 WP_Session_Tokens::destroy_all_for_all_users();
2091 wp_set_auth_cookie( $user_id, false, is_ssl() );
2092 update_site_option( 'wp_super_cache_index_detected', 2 );
2093 wp_redirect( admin_url() );
2094 }
2095 }
2096 if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'wpsclogout' )
2097 add_action( 'admin_init', 'wp_cache_logout_all' );
2098
2099 function wp_cache_add_index_protection() {
2100 global $cache_path, $blog_cache_dir;
2101
2102 if ( is_dir( $cache_path ) && false == is_file( "$cache_path/index.html" ) ) {
2103 $page = wp_remote_get( home_url( "/wp-content/cache/" ) );
2104 if ( false == is_wp_error( $page ) ) {
2105 if ( false == get_site_option( 'wp_super_cache_index_detected' )
2106 && $page[ 'response' ][ 'code' ] == 200
2107 && stripos( $page[ 'body' ], 'index of' ) ) {
2108 add_site_option( 'wp_super_cache_index_detected', 1 ); // only show this once
2109 }
2110 }
2111 if ( ! function_exists( 'insert_with_markers' ) ) {
2112 include_once( ABSPATH . 'wp-admin/includes/misc.php' );
2113 }
2114 insert_with_markers( $cache_path . '.htaccess', "INDEX", array( 'Options -Indexes' ) );
2115 }
2116
2117 $directories = array( $cache_path, $cache_path . '/supercache/', $cache_path . '/blogs/', $blog_cache_dir, $blog_cache_dir . "/meta" );
2118 foreach( $directories as $dir ) {
2119 if ( false == is_dir( $dir ) )
2120 @mkdir( $dir );
2121 if ( is_dir( $dir ) && false == is_file( "$dir/index.html" ) ) {
2122 $fp = @fopen( "$dir/index.html", 'w' );
2123 if ( $fp )
2124 fclose( $fp );
2125 }
2126 }
2127 }
2128
2129 function wp_cache_add_site_cache_index() {
2130 global $cache_path;
2131
2132 wp_cache_add_index_protection(); // root and supercache
2133
2134 if ( is_dir( $cache_path . "blogs" ) ) {
2135 $dir = new DirectoryIterator( $cache_path . "blogs" );
2136 foreach( $dir as $fileinfo ) {
2137 if ( $fileinfo->isDot() ) {
2138 continue;
2139 }
2140 if ( $fileinfo->isDir() ) {
2141 $directory = $cache_path . "blogs/" . $fileinfo->getFilename();
2142 if ( false == is_file( $directory . "/index.html" ) ) {
2143 $fp = @fopen( $directory . "/index.html", 'w' );
2144 if ( $fp )
2145 fclose( $fp );
2146 }
2147 if ( is_dir( $directory . "/meta" ) ) {
2148 if ( false == is_file( $directory . "/meta/index.html" ) ) {
2149 $fp = @fopen( $directory . "/meta/index.html", 'w' );
2150 if ( $fp )
2151 fclose( $fp );
2152 }
2153 }
2154 }
2155 }
2156 }
2157 }
2158
2159 function wp_cache_verify_cache_dir() {
2160 global $cache_path, $blog_cache_dir;
2161
2162 $dir = dirname($cache_path);
2163 if ( !file_exists($cache_path) ) {
2164 if ( !is_writeable_ACLSafe( $dir ) || !($dir = mkdir( $cache_path ) ) ) {
2165 echo "<strong>" . __( 'Error', 'wp-super-cache' ) . ":</strong> " . sprintf( __( 'Your cache directory (<strong>%1$s</strong>) did not exist and couldn&#8217;t be created by the web server. Check %1$s permissions.', 'wp-super-cache' ), $dir );
2166 return false;
2167 }
2168 }
2169 if ( !is_writeable_ACLSafe($cache_path)) {
2170 echo "<strong>" . __( 'Error', 'wp-super-cache' ) . ":</strong> " . sprintf( __( 'Your cache directory (<strong>%1$s</strong>) or <strong>%2$s</strong> need to be writable for this plugin to work. Double-check it.', 'wp-super-cache' ), $cache_path, $dir );
2171 return false;
2172 }
2173
2174 if ( '/' != substr($cache_path, -1)) {
2175 $cache_path .= '/';
2176 }
2177
2178 if( false == is_dir( $blog_cache_dir ) ) {
2179 @mkdir( $cache_path . "blogs" );
2180 if( $blog_cache_dir != $cache_path . "blogs/" )
2181 @mkdir( $blog_cache_dir );
2182 }
2183
2184 if( false == is_dir( $blog_cache_dir . 'meta' ) )
2185 @mkdir( $blog_cache_dir . 'meta' );
2186
2187 wp_cache_add_index_protection();
2188 return true;
2189 }
2190
2191 function wp_cache_verify_config_file() {
2192 global $wp_cache_config_file, $wp_cache_config_file_sample, $sem_id, $cache_path;
2193 global $WPSC_HTTP_HOST;
2194
2195 $new = false;
2196 $dir = dirname($wp_cache_config_file);
2197
2198 if ( file_exists($wp_cache_config_file) ) {
2199 $lines = implode( ' ', file( $wp_cache_config_file ) );
2200 if ( ! str_contains( $lines, 'WPCACHEHOME' ) ) {
2201 if( is_writeable_ACLSafe( $wp_cache_config_file ) ) {
2202 @unlink( $wp_cache_config_file );
2203 } else {
2204 echo "<strong>" . __( 'Error', 'wp-super-cache' ) . ":</strong> " . sprintf( __( 'Your WP-Cache config file (<strong>%s</strong>) is out of date and not writable by the Web server. Please delete it and refresh this page.', 'wp-super-cache' ), $wp_cache_config_file );
2205 return false;
2206 }
2207 }
2208 } elseif( !is_writeable_ACLSafe($dir)) {
2209 echo "<strong>" . __( 'Error', 'wp-super-cache' ) . ":</strong> " . sprintf( __( 'Configuration file missing and %1$s directory (<strong>%2$s</strong>) is not writable by the web server. Check its permissions.', 'wp-super-cache' ), WP_CONTENT_DIR, $dir );
2210 return false;
2211 }
2212
2213 if ( !file_exists($wp_cache_config_file) ) {
2214 if ( !file_exists($wp_cache_config_file_sample) ) {
2215 echo "<strong>" . __( 'Error', 'wp-super-cache' ) . ":</strong> " . sprintf( __( 'Sample WP-Cache config file (<strong>%s</strong>) does not exist. Verify your installation.', 'wp-super-cache' ), $wp_cache_config_file_sample );
2216 return false;
2217 }
2218 copy($wp_cache_config_file_sample, $wp_cache_config_file);
2219 $dir = str_replace( str_replace( '\\', '/', WP_CONTENT_DIR ), '', str_replace( '\\', '/', __DIR__ ) );
2220 if ( is_file( __DIR__ . '/wp-cache-config-sample.php' ) ) {
2221 wp_cache_replace_line('define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/\" );", $wp_cache_config_file);
2222 } elseif ( is_file( __DIR__ . '/wp-super-cache/wp-cache-config-sample.php' ) ) {
2223 wp_cache_replace_line('define\(\ \'WPCACHEHOME', "\tdefine( 'WPCACHEHOME', WP_CONTENT_DIR . \"{$dir}/wp-super-cache/\" );", $wp_cache_config_file);
2224 }
2225 $new = true;
2226 }
2227 if ( $sem_id == 5419 && $cache_path != '' && $WPSC_HTTP_HOST != '' ) {
2228 $sem_id = crc32( $WPSC_HTTP_HOST . $cache_path ) & 0x7fffffff;
2229 wp_cache_replace_line('sem_id', '$sem_id = ' . $sem_id . ';', $wp_cache_config_file);
2230 }
2231 if ( $new ) {
2232 require($wp_cache_config_file);
2233 wpsc_set_default_gc( true );
2234 }
2235 return true;
2236 }
2237
2238 function wp_cache_create_advanced_cache() {
2239 global $wpsc_advanced_cache_filename, $wpsc_advanced_cache_dist_filename;
2240 if ( file_exists( ABSPATH . 'wp-config.php') ) {
2241 $global_config_file = ABSPATH . 'wp-config.php';
2242 } elseif ( file_exists( dirname( ABSPATH ) . '/wp-config.php' ) ) {
2243 $global_config_file = dirname( ABSPATH ) . '/wp-config.php';
2244 } elseif ( defined( 'DEBIAN_FILE' ) && file_exists( DEBIAN_FILE ) ) {
2245 $global_config_file = DEBIAN_FILE;
2246 } else {
2247 die('Cannot locate wp-config.php');
2248 }
2249
2250 $line = 'define( \'WPCACHEHOME\', \'' . __DIR__ . '/\' );';
2251
2252 if ( ! apply_filters( 'wpsc_enable_wp_config_edit', true ) ) {
2253 echo '<div class="notice notice-error"><h4>' . __( 'Warning', 'wp-super-cache' ) . "! " . sprintf( __( 'Not allowed to edit %s per configuration.', 'wp-super-cache' ), $global_config_file ) . "</h4></div>";
2254 return false;
2255 }
2256
2257 if (
2258 ! strpos( file_get_contents( $global_config_file ), "WPCACHEHOME" ) ||
2259 (
2260 defined( 'WPCACHEHOME' ) &&
2261 (
2262 constant( 'WPCACHEHOME' ) == '' ||
2263 (
2264 constant( 'WPCACHEHOME' ) != '' &&
2265 ! file_exists( constant( 'WPCACHEHOME' ) . '/wp-cache.php' )
2266 )
2267 )
2268 )
2269 ) {
2270 if (
2271 ! is_writeable_ACLSafe( $global_config_file ) ||
2272 ! wp_cache_replace_line( 'define *\( *\'WPCACHEHOME\'', $line, $global_config_file )
2273 ) {
2274 echo '<div class="notice notice-error"><h4>' . __( 'Warning', 'wp-super-cache' ) . "! <em>" . sprintf( __( 'Could not update %s!</em> WPCACHEHOME must be set in config file.', 'wp-super-cache' ), $global_config_file ) . "</h4></div>";
2275 return false;
2276 }
2277 }
2278 $ret = true;
2279
2280 if ( file_exists( $wpsc_advanced_cache_filename ) ) {
2281 $file = file_get_contents( $wpsc_advanced_cache_filename );
2282 if (
2283 ! strpos( $file, "WP SUPER CACHE 0.8.9.1" ) &&
2284 ! strpos( $file, "WP SUPER CACHE 1.2" )
2285 ) {
2286 return false;
2287 }
2288 }
2289
2290 $file = file_get_contents( $wpsc_advanced_cache_dist_filename );
2291 $fp = @fopen( $wpsc_advanced_cache_filename, 'w' );
2292 if( $fp ) {
2293 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite
2294 fwrite( $fp, $file );
2295 fclose( $fp );
2296 do_action( 'wpsc_created_advanced_cache' );
2297 } else {
2298 $ret = false;
2299 }
2300 return $ret;
2301 }
2302
2303 /**
2304 * Identify the advanced cache plugin used
2305 *
2306 * @return string The name of the advanced cache plugin, BOOST, WPSC or OTHER.
2307 */
2308 function wpsc_identify_advanced_cache() {
2309 global $wpsc_advanced_cache_filename;
2310 if ( ! file_exists( $wpsc_advanced_cache_filename ) ) {
2311 return 'NONE';
2312 }
2313 $contents = file_get_contents( $wpsc_advanced_cache_filename ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
2314
2315 if ( false !== str_contains( $contents, 'Boost Cache Plugin' ) ) {
2316 return 'BOOST';
2317 }
2318
2319 if ( str_contains( $contents, 'WP SUPER CACHE 0.8.9.1' ) || str_contains( $contents, 'WP SUPER CACHE 1.2' ) ) {
2320 return 'WPSC';
2321 }
2322
2323 return 'OTHER';
2324 }
2325
2326 function wpsc_check_advanced_cache() {
2327 global $wpsc_advanced_cache_filename;
2328
2329 $ret = false;
2330 $other_advanced_cache = false;
2331 if ( file_exists( $wpsc_advanced_cache_filename ) ) {
2332 $cache_type = wpsc_identify_advanced_cache();
2333 switch ( $cache_type ) {
2334 case 'WPSC':
2335 return true;
2336 case 'BOOST':
2337 $other_advanced_cache = 'BOOST';
2338 break;
2339 default:
2340 $other_advanced_cache = true;
2341 break;
2342 }
2343 } else {
2344 $ret = wp_cache_create_advanced_cache();
2345 }
2346
2347 if ( false == $ret ) {
2348 if ( $other_advanced_cache === 'BOOST' ) {
2349 wpsc_deactivate_boost_cache_notice();
2350 } elseif ( $other_advanced_cache ) {
2351 echo '<div style="width: 50%" class="notice notice-error"><h2>' . __( 'Warning! You may not be allowed to use this plugin on your site.', 'wp-super-cache' ) . "</h2>";
2352 echo '<p>' .
2353 sprintf(
2354 __( 'The file %s was created by another plugin or by your system administrator. Please examine the file carefully by FTP or SSH and consult your hosting documentation. ', 'wp-super-cache' ),
2355 $wpsc_advanced_cache_filename
2356 ) .
2357 '</p>';
2358 echo '<p>' .
2359 __( 'If it was created by another caching plugin please uninstall that plugin first before activating WP Super Cache. If the file is not removed by that action you should delete the file manually.', 'wp-super-cache' ),
2360 '</p>';
2361 echo '<p><strong>' .
2362 __( 'If you need support for this problem contact your hosting provider.', 'wp-super-cache' ),
2363 '</strong></p>';
2364 echo '</div>';
2365 } elseif ( ! is_writeable_ACLSafe( $wpsc_advanced_cache_filename ) ) {
2366 echo '<div class="notice notice-error"><h2>' . __( 'Warning', 'wp-super-cache' ) . "! <em>" . sprintf( __( '%s/advanced-cache.php</em> cannot be updated.', 'wp-super-cache' ), WP_CONTENT_DIR ) . "</h2>";
2367 echo '<ol>';
2368 echo "<li>" .
2369 sprintf(
2370 __( 'Make %1$s writable using the chmod command through your ftp or server software. (<em>chmod 777 %1$s</em>) and refresh this page. This is only a temporary measure and you&#8217;ll have to make it read only afterwards again. (Change 777 to 755 in the previous command)', 'wp-super-cache' ),
2371 WP_CONTENT_DIR
2372 ) .
2373 "</li>";
2374 echo "<li>" . sprintf( __( 'Refresh this page to update <em>%s/advanced-cache.php</em>', 'wp-super-cache' ), WP_CONTENT_DIR ) . "</li></ol>";
2375 echo sprintf( __( 'If that doesn&#8217;t work, make sure the file <em>%s/advanced-cache.php</em> doesn&#8217;t exist:', 'wp-super-cache' ), WP_CONTENT_DIR ) . "<ol>";
2376 echo "</ol>";
2377 echo '</div>';
2378 }
2379 return false;
2380 }
2381 return true;
2382 }
2383
2384 function wp_cache_check_global_config() {
2385 global $wp_cache_check_wp_config;
2386
2387 if ( !isset( $wp_cache_check_wp_config ) )
2388 return true;
2389
2390
2391 if ( file_exists( ABSPATH . 'wp-config.php') ) {
2392 $global_config_file = ABSPATH . 'wp-config.php';
2393 } else {
2394 $global_config_file = dirname( ABSPATH ) . '/wp-config.php';
2395 }
2396
2397 if ( preg_match( '#^\s*(define\s*\(\s*[\'"]WP_CACHE[\'"]|const\s+WP_CACHE\s*=)#m', file_get_contents( $global_config_file ) ) === 1 ) { // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
2398 if ( defined( 'WP_CACHE' ) && ! constant( 'WP_CACHE' ) ) {
2399 ?>
2400 <div class="notice notice-error"><h4><?php esc_html_e( 'WP_CACHE constant set to false', 'wp-super-cache' ); ?></h4>
2401 <p><?php esc_html_e( 'The WP_CACHE constant is used by WordPress to load the code that serves cached pages. Unfortunately, it is set to false. Please edit your wp-config.php and add or edit the following line above the final require_once command:', 'wp-super-cache' ); ?></p>
2402 <p><code>define('WP_CACHE', true);</code></p></div>
2403 <?php
2404 return false;
2405 } else {
2406 return true;
2407 }
2408 }
2409
2410 $line = 'define(\'WP_CACHE\', true);';
2411 if (
2412 ! is_writeable_ACLSafe( $global_config_file ) ||
2413 ! wp_cache_replace_line( 'define *\( *\'WP_CACHE\'', $line, $global_config_file )
2414 ) {
2415 if ( defined( 'WP_CACHE' ) && constant( 'WP_CACHE' ) == false ) {
2416 echo '<div class="notice notice-error">' . __( "<h4>WP_CACHE constant set to false</h4><p>The WP_CACHE constant is used by WordPress to load the code that serves cached pages. Unfortunately, it is set to false. Please edit your wp-config.php and add or edit the following line above the final require_once command:<br /><br /><code>define('WP_CACHE', true);</code></p>", 'wp-super-cache' ) . "</div>";
2417 } else {
2418 echo '<div class="notice notice-error"><p>' . __( "<strong>Error: WP_CACHE is not enabled</strong> in your <code>wp-config.php</code> file and I couldn&#8217;t modify it.", 'wp-super-cache' ) . "</p>";
2419 echo "<p>" . sprintf( __( "Edit <code>%s</code> and add the following line:<br /> <code>define('WP_CACHE', true);</code><br />Otherwise, <strong>WP-Cache will not be executed</strong> by WordPress core. ", 'wp-super-cache' ), $global_config_file ) . "</p></div>";
2420 }
2421 return false;
2422 } else {
2423 echo "<div class='notice notice-warning'>" . __( '<h4>WP_CACHE constant added to wp-config.php</h4><p>If you continue to see this warning message please see point 5 of the <a href="https://wordpress.org/plugins/wp-super-cache/faq/">Troubleshooting Guide</a>. The WP_CACHE line must be moved up.', 'wp-super-cache' ) . "</p></div>";
2424 }
2425 return true;
2426 }
2427
2428 function wpsc_generate_sizes_array() {
2429 $sizes = array();
2430 $cache_types = apply_filters( 'wpsc_cache_types', array( 'supercache', 'wpcache' ) );
2431 $cache_states = apply_filters( 'wpsc_cache_state', array( 'expired', 'cached' ) );
2432 foreach( $cache_types as $type ) {
2433 reset( $cache_states );
2434 foreach( $cache_states as $state ) {
2435 $sizes[ $type ][ $state ] = 0;
2436 }
2437 $sizes[ $type ][ 'fsize' ] = 0;
2438 $sizes[ $type ][ 'cached_list' ] = array();
2439 $sizes[ $type ][ 'expired_list' ] = array();
2440 }
2441 return $sizes;
2442 }
2443
2444 function wp_cache_format_fsize( $fsize ) {
2445 if ( $fsize > 1024 ) {
2446 $fsize = number_format( $fsize / 1024, 2 ) . "MB";
2447 } elseif ( $fsize != 0 ) {
2448 $fsize = number_format( $fsize, 2 ) . "KB";
2449 } else {
2450 $fsize = "0KB";
2451 }
2452 return $fsize;
2453 }
2454
2455 function wp_cache_regenerate_cache_file_stats() {
2456 global $cache_compression, $supercachedir, $file_prefix, $wp_cache_preload_on, $cache_max_time;
2457
2458 if ( $supercachedir == '' )
2459 $supercachedir = get_supercache_dir();
2460
2461 $sizes = wpsc_generate_sizes_array();
2462 $now = time();
2463 if (is_dir( $supercachedir ) ) {
2464 if ( $dh = opendir( $supercachedir ) ) {
2465 while ( ( $entry = readdir( $dh ) ) !== false ) {
2466 if ( $entry != '.' && $entry != '..' ) {
2467 $sizes = wpsc_dirsize( trailingslashit( $supercachedir ) . $entry, $sizes );
2468 }
2469 }
2470 closedir( $dh );
2471 }
2472 }
2473 foreach( $sizes as $cache_type => $list ) {
2474 foreach( array( 'cached_list', 'expired_list' ) as $status ) {
2475 $cached_list = array();
2476 foreach( $list[ $status ] as $dir => $details ) {
2477 if ( $details[ 'files' ] == 2 && !isset( $details[ 'upper_age' ] ) ) {
2478 $details[ 'files' ] = 1;
2479 }
2480 $cached_list[ $dir ] = $details;
2481 }
2482 $sizes[ $cache_type ][ $status ] = $cached_list;
2483 }
2484 }
2485 if ( $cache_compression ) {
2486 $sizes[ 'supercache' ][ 'cached' ] = intval( $sizes[ 'supercache' ][ 'cached' ] / 2 );
2487 $sizes[ 'supercache' ][ 'expired' ] = intval( $sizes[ 'supercache' ][ 'expired' ] / 2 );
2488 }
2489 $cache_stats = array( 'generated' => time(), 'supercache' => $sizes[ 'supercache' ], 'wpcache' => $sizes[ 'wpcache' ] );
2490 update_option( 'supercache_stats', $cache_stats );
2491 return $cache_stats;
2492 }
2493
2494 function wp_cache_files() {
2495 global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $super_cache_enabled, $blog_cache_dir, $cache_compression;
2496 global $wp_cache_preload_on;
2497
2498 if ( '/' != substr($cache_path, -1)) {
2499 $cache_path .= '/';
2500 }
2501
2502 if ( $valid_nonce ) {
2503 if(isset($_REQUEST['wp_delete_cache'])) {
2504 wp_cache_clean_cache($file_prefix);
2505 $_GET[ 'action' ] = 'regenerate_cache_stats';
2506 }
2507 if ( isset( $_REQUEST[ 'wp_delete_all_cache' ] ) ) {
2508 wp_cache_clean_cache( $file_prefix, true );
2509 $_GET[ 'action' ] = 'regenerate_cache_stats';
2510 }
2511 if(isset($_REQUEST['wp_delete_expired'])) {
2512 wp_cache_clean_expired($file_prefix);
2513 $_GET[ 'action' ] = 'regenerate_cache_stats';
2514 }
2515 }
2516 echo "<a name='listfiles'></a>";
2517 echo '<div class="wpsc-card">';
2518 echo '<fieldset class="options" id="show-this-fieldset"><h4>' . __( 'Cache Contents', 'wp-super-cache' ) . '</h4>';
2519
2520 $cache_stats = get_option( 'supercache_stats' );
2521 if ( !is_array( $cache_stats ) || ( isset( $_GET[ 'listfiles' ] ) ) || ( $valid_nonce && array_key_exists('action', $_GET) && $_GET[ 'action' ] == 'regenerate_cache_stats' ) ) {
2522 $count = 0;
2523 $expired = 0;
2524 $now = time();
2525 $wp_cache_fsize = 0;
2526 if ( ( $handle = @opendir( $blog_cache_dir ) ) ) {
2527 if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletewpcache' ) {
2528 $deleteuri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', base64_decode( $_GET[ 'uri' ] ) ) );
2529 } else {
2530 $deleteuri = '';
2531 }
2532
2533 if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletesupercache' ) {
2534 $supercacheuri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', preg_replace("/(\?.*)?$/", '', base64_decode( $_GET[ 'uri' ] ) ) ) );
2535 $supercacheuri = trailingslashit( realpath( $cache_path . 'supercache/' . $supercacheuri ) );
2536 if ( wp_cache_confirm_delete( $supercacheuri ) ) {
2537 printf( __( "Deleting supercache file: <strong>%s</strong><br />", 'wp-super-cache' ), $supercacheuri );
2538 wpsc_delete_files( $supercacheuri );
2539 prune_super_cache( $supercacheuri . 'page', true );
2540 @rmdir( $supercacheuri );
2541 } else {
2542 wp_die( __( 'Warning! You are not allowed to delete that file', 'wp-super-cache' ) );
2543 }
2544 }
2545 while( false !== ( $file = readdir( $handle ) ) ) {
2546 if ( // phpcs:ignore Generic.WhiteSpace.ScopeIndent.IncorrectExact
2547 str_contains( $file, $file_prefix )
2548 && substr( $file, -4 ) == '.php' // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
2549 ) { // phpcs:ignore Generic.WhiteSpace.ScopeIndent.Incorrect
2550 if ( false == file_exists( $blog_cache_dir . 'meta/' . $file ) ) {
2551 @unlink( $blog_cache_dir . $file );
2552 continue; // meta does not exist
2553 }
2554 $mtime = filemtime( $blog_cache_dir . 'meta/' . $file );
2555 $fsize = @filesize( $blog_cache_dir . $file );
2556 if ( $fsize > 0 )
2557 $fsize = $fsize - 15; // die() command takes 15 bytes at the start of the file
2558
2559 $age = $now - $mtime;
2560 if ( $valid_nonce && isset( $_GET[ 'listfiles' ] ) ) {
2561 $meta = json_decode( wp_cache_get_legacy_cache( $blog_cache_dir . 'meta/' . $file ), true );
2562 if ( $deleteuri != '' && $meta[ 'uri' ] == $deleteuri ) {
2563 printf( __( "Deleting wp-cache file: <strong>%s</strong><br />", 'wp-super-cache' ), esc_html( $deleteuri ) );
2564 @unlink( $blog_cache_dir . 'meta/' . $file );
2565 @unlink( $blog_cache_dir . $file );
2566 continue;
2567 }
2568 $meta[ 'age' ] = $age;
2569 foreach( $meta as $key => $val )
2570 $meta[ $key ] = esc_html( $val );
2571 if ( $cache_max_time > 0 && $age > $cache_max_time ) {
2572 $expired_list[ $age ][] = $meta;
2573 } else {
2574 $cached_list[ $age ][] = $meta;
2575 }
2576 }
2577
2578 if ( $cache_max_time > 0 && $age > $cache_max_time ) {
2579 ++$expired;
2580 } else {
2581 ++$count;
2582 }
2583 $wp_cache_fsize += $fsize;
2584 }
2585 }
2586 closedir($handle);
2587 }
2588 if( $wp_cache_fsize != 0 ) {
2589 $wp_cache_fsize = $wp_cache_fsize/1024;
2590 } else {
2591 $wp_cache_fsize = 0;
2592 }
2593 if( $wp_cache_fsize > 1024 ) {
2594 $wp_cache_fsize = number_format( $wp_cache_fsize / 1024, 2 ) . "MB";
2595 } elseif( $wp_cache_fsize != 0 ) {
2596 $wp_cache_fsize = number_format( $wp_cache_fsize, 2 ) . "KB";
2597 } else {
2598 $wp_cache_fsize = '0KB';
2599 }
2600 $cache_stats = wp_cache_regenerate_cache_file_stats();
2601 } else {
2602 echo "<p>" . __( 'Cache stats are not automatically generated. You must click the link below to regenerate the stats on this page.', 'wp-super-cache' ) . "</p>";
2603 echo "<a href='" . wp_nonce_url( add_query_arg( array( 'page' => 'wpsupercache', 'tab' => 'contents', 'action' => 'regenerate_cache_stats' ) ), 'wp-cache' ) . "'>" . __( 'Regenerate cache stats', 'wp-super-cache' ) . "</a>";
2604 if ( is_array( $cache_stats ) ) {
2605 echo "<p>" . sprintf( __( 'Cache stats last generated: %s minutes ago.', 'wp-super-cache' ), number_format( ( time() - $cache_stats[ 'generated' ] ) / 60 ) ) . "</p>";
2606 }
2607 $cache_stats = get_option( 'supercache_stats' );
2608 }// regerate stats cache
2609
2610 if ( is_array( $cache_stats ) ) {
2611 $fsize = wp_cache_format_fsize( $cache_stats[ 'wpcache' ][ 'fsize' ] / 1024 );
2612 echo "<p><strong>" . __( 'WP-Cache', 'wp-super-cache' ) . " ({$fsize})</strong></p>";
2613 echo "<ul><li>" . sprintf( __( '%s Cached Pages', 'wp-super-cache' ), $cache_stats[ 'wpcache' ][ 'cached' ] ) . "</li>";
2614 echo "<li>" . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), $cache_stats[ 'wpcache' ][ 'expired' ] ) . "</li></ul>";
2615 if ( array_key_exists('fsize', (array)$cache_stats[ 'supercache' ]) )
2616 $fsize = $cache_stats[ 'supercache' ][ 'fsize' ] / 1024;
2617 else
2618 $fsize = 0;
2619 $fsize = wp_cache_format_fsize( $fsize );
2620 echo "<p><strong>" . __( 'WP-Super-Cache', 'wp-super-cache' ) . " ({$fsize})</strong></p>";
2621 echo "<ul><li>" . sprintf( __( '%s Cached Pages', 'wp-super-cache' ), $cache_stats[ 'supercache' ][ 'cached' ] ) . "</li>";
2622 if ( isset( $now ) && isset( $cache_stats ) )
2623 $age = intval( ( $now - $cache_stats['generated'] ) / 60 );
2624 else
2625 $age = 0;
2626 echo "<li>" . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), $cache_stats[ 'supercache' ][ 'expired' ] ) . "</li></ul>";
2627 if ( $valid_nonce && array_key_exists('listfiles', $_GET) && isset( $_GET[ 'listfiles' ] ) ) {
2628 echo "<div style='padding: 10px; border: 1px solid #333; height: 400px; width: 90%; overflow: auto'>";
2629 $cache_description = array( 'supercache' => __( 'WP-Super-Cached', 'wp-super-cache' ), 'wpcache' => __( 'WP-Cached', 'wp-super-cache' ) );
2630 foreach( $cache_stats as $type => $details ) {
2631 if ( is_array( $details ) == false )
2632 continue;
2633 foreach( array( 'cached_list' => 'Fresh', 'expired_list' => 'Stale' ) as $list => $description ) {
2634 if ( is_array( $details[ $list ] ) & !empty( $details[ $list ] ) ) {
2635 echo "<h5>" . sprintf( __( '%s %s Files', 'wp-super-cache' ), $description, $cache_description[ $type ] ) . "</h5>";
2636 echo "<table class='widefat'><tr><th>#</th><th>" . __( 'URI', 'wp-super-cache' ) . "</th><th>" . __( 'Files', 'wp-super-cache' ) . "</th><th>" . __( 'Age', 'wp-super-cache' ) . "</th><th>" . __( 'Delete', 'wp-super-cache' ) . "</th></tr>";
2637 $c = 1;
2638 $flip = 1;
2639
2640 ksort( $details[ $list ] );
2641 foreach( $details[ $list ] as $directory => $d ) {
2642 if ( isset( $d[ 'upper_age' ] ) ) {
2643 $age = "{$d[ 'lower_age' ]} - {$d[ 'upper_age' ]}";
2644 } else {
2645 $age = $d[ 'lower_age' ];
2646 }
2647 $bg = $flip ? 'style="background: #EAEAEA;"' : '';
2648 echo "<tr $bg><td>$c</td><td> <a href='http://{$directory}'>{$directory}</a></td><td>{$d[ 'files' ]}</td><td>{$age}</td><td><a href='" . wp_nonce_url( add_query_arg( array( 'page' => 'wpsupercache', 'action' => 'deletesupercache', 'uri' => base64_encode( $directory ) ) ), 'wp-cache' ) . "#listfiles'>X</a></td></tr>\n";
2649 $flip = !$flip;
2650 ++$c;
2651 }
2652 echo "</table>";
2653 }
2654 }
2655 }
2656 echo "</div>";
2657 echo "<p><a href='?page=wpsupercache&tab=contents#top'>" . __( 'Hide file list', 'wp-super-cache' ) . "</a></p>";
2658 } elseif ( $cache_stats[ 'supercache' ][ 'cached' ] > 500 || $cache_stats[ 'supercache' ][ 'expired' ] > 500 || $cache_stats[ 'wpcache' ][ 'cached' ] > 500 || $cache_stats[ 'wpcache' ][ 'expired' ] > 500 ) {
2659 echo "<p><em>" . __( 'Too many cached files, no listing possible.', 'wp-super-cache' ) . "</em></p>";
2660 } else {
2661 echo "<p><a href='" . wp_nonce_url( add_query_arg( array( 'page' => 'wpsupercache', 'listfiles' => '1' ) ), 'wp-cache' ) . "#listfiles'>" . __( 'List all cached files', 'wp-super-cache' ) . "</a></p>";
2662 }
2663 if ( $cache_max_time > 0 )
2664 echo "<p>" . sprintf( __( 'Expired files are files older than %s seconds. They are still used by the plugin and are deleted periodically.', 'wp-super-cache' ), $cache_max_time ) . "</p>";
2665 if ( $wp_cache_preload_on )
2666 echo "<p>" . __( 'Preload mode is enabled. Supercache files will never be expired.', 'wp-super-cache' ) . "</p>";
2667 } // cache_stats
2668 wp_cache_delete_buttons();
2669
2670 echo '</fieldset>';
2671 echo '</div>';
2672 }
2673
2674 function wp_cache_delete_buttons() {
2675
2676 $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
2677
2678 echo '<form name="wp_cache_content_expired" action="' . esc_url_raw( add_query_arg( 'tab', 'contents', $admin_url ) . '#listfiles' ) . '" method="post">';
2679 echo '<input type="hidden" name="wp_delete_expired" />';
2680 echo '<div class="submit" style="float:left"><input class="button-primary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Expired', 'wp-super-cache' ) . '" /></div>';
2681 wp_nonce_field('wp-cache');
2682 echo "</form>\n";
2683
2684 echo '<form name="wp_cache_content_delete" action="' . esc_url_raw( add_query_arg( 'tab', 'contents', $admin_url ) . '#listfiles' ) . '" method="post">';
2685 echo '<input type="hidden" name="wp_delete_cache" />';
2686 echo '<div class="submit" style="float:left;margin-left:10px"><input id="deletepost" class="button-secondary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Cache', 'wp-super-cache' ) . '" /></div>';
2687 wp_nonce_field('wp-cache');
2688 echo "</form>\n";
2689 if ( is_multisite() && wpsupercache_site_admin() ) {
2690 echo '<form name="wp_cache_content_delete" action="' . esc_url_raw( add_query_arg( 'tab', 'contents', $admin_url ) . '#listfiles' ) . '" method="post">';
2691 echo '<input type="hidden" name="wp_delete_all_cache" />';
2692 echo '<div class="submit" style="float:left;margin-left:10px"><input id="deleteallpost" class="button-secondary" type="submit" ' . SUBMITDISABLED . 'value="' . __( 'Delete Cache On All Blogs', 'wp-super-cache' ) . '" /></div>';
2693 wp_nonce_field('wp-cache');
2694 echo "</form>\n";
2695 }
2696 }
2697
2698 function delete_cache_dashboard() {
2699 if ( function_exists( '_deprecated_function' ) ) {
2700 _deprecated_function( __FUNCTION__, 'WP Super Cache 1.6.4' );
2701 }
2702
2703 if ( false == wpsupercache_site_admin() )
2704 return false;
2705
2706 if ( function_exists('current_user_can') && !current_user_can('manage_options') )
2707 return false;
2708
2709 echo "<li><a href='" . wp_nonce_url( 'options-general.php?page=wpsupercache&wp_delete_cache=1', 'wp-cache' ) . "' target='_blank' title='" . __( 'Delete Super Cache cached files (opens in new window)', 'wp-super-cache' ) . "'>" . __( 'Delete Cache', 'wp-super-cache' ) . "</a></li>";
2710 }
2711 //add_action( 'dashmenu', 'delete_cache_dashboard' );
2712
2713 function wpsc_dirsize($directory, $sizes) {
2714 global $cache_max_time, $cache_path, $valid_nonce, $wp_cache_preload_on, $file_prefix;
2715 $now = time();
2716
2717 if (is_dir($directory)) {
2718 if( $dh = opendir( $directory ) ) {
2719 while( ( $entry = readdir( $dh ) ) !== false ) {
2720 if ($entry != '.' && $entry != '..') {
2721 $sizes = wpsc_dirsize( trailingslashit( $directory ) . $entry, $sizes );
2722 }
2723 }
2724 closedir($dh);
2725 }
2726 } elseif ( is_file( $directory ) && strpos( $directory, 'meta-' . $file_prefix ) === false ) {
2727 if ( strpos( $directory, '/' . $file_prefix ) !== false ) {
2728 $cache_type = 'wpcache';
2729 } else {
2730 $cache_type = 'supercache';
2731 }
2732 $keep_fresh = false;
2733 if ( $cache_type === 'supercache' && $wp_cache_preload_on ) {
2734 $keep_fresh = true;
2735 }
2736 $filem = filemtime( $directory );
2737 if ( ! $keep_fresh && $cache_max_time > 0 && $filem + $cache_max_time <= $now ) {
2738 $cache_status = 'expired';
2739 } else {
2740 $cache_status = 'cached';
2741 }
2742 $sizes[ $cache_type ][ $cache_status ] += 1;
2743 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Presumably the caller should handle it if necessary.
2744 if ( $valid_nonce && isset( $_GET['listfiles'] ) ) {
2745 $dir = str_replace( $cache_path . 'supercache/', '', dirname( $directory ) );
2746 $age = $now - $filem;
2747 if ( ! isset( $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ] ) ) {
2748 $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['lower_age'] = $age;
2749 $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['files'] = 1;
2750 } else {
2751 $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['files'] += 1;
2752 if ( $age <= $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['lower_age'] ) {
2753
2754 if ( $age < $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['lower_age'] && ! isset( $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['upper_age'] ) ) {
2755 $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['upper_age'] = $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['lower_age'];
2756 }
2757
2758 $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['lower_age'] = $age;
2759
2760 } elseif ( ! isset( $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['upper_age'] ) || $age > $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['upper_age'] ) {
2761
2762 $sizes[ $cache_type ][ $cache_status . '_list' ][ $dir ]['upper_age'] = $age;
2763
2764 }
2765 }
2766 }
2767 if ( ! isset( $sizes['fsize'] ) ) {
2768 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
2769 $sizes[ $cache_type ]['fsize'] = @filesize( $directory );
2770 } else {
2771 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
2772 $sizes[ $cache_type ]['fsize'] += @filesize( $directory );
2773 }
2774 }
2775 return $sizes;
2776 }
2777
2778 function wp_cache_clean_cache( $file_prefix, $all = false ) {
2779 global $cache_path, $supercachedir, $blog_cache_dir;
2780
2781 do_action( 'wp_cache_cleared' );
2782
2783 if ( $all == true && wpsupercache_site_admin() && function_exists( 'prune_super_cache' ) ) {
2784 prune_super_cache( $cache_path, true );
2785 return true;
2786 }
2787 if ( $supercachedir == '' )
2788 $supercachedir = get_supercache_dir();
2789
2790 if (function_exists ('prune_super_cache')) {
2791 if( is_dir( $supercachedir ) ) {
2792 prune_super_cache( $supercachedir, true );
2793 } elseif( is_dir( $supercachedir . '.disabled' ) ) {
2794 prune_super_cache( $supercachedir . '.disabled', true );
2795 }
2796 $_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
2797 } else {
2798 wp_cache_debug( 'Warning! prune_super_cache() not found in wp-cache.php', 1 );
2799 }
2800
2801 wp_cache_clean_legacy_files( $blog_cache_dir, $file_prefix );
2802 wp_cache_clean_legacy_files( $cache_path, $file_prefix );
2803 }
2804
2805 function wpsc_delete_post_cache( $id ) {
2806 $post = get_post( $id );
2807 wpsc_delete_url_cache( get_author_posts_url( $post->post_author ) );
2808 $permalink = get_permalink( $id );
2809 if ( $permalink != '' ) {
2810 wpsc_delete_url_cache( $permalink );
2811 return true;
2812 } else {
2813 return false;
2814 }
2815 }
2816
2817 function wp_cache_clean_legacy_files( $dir, $file_prefix ) {
2818 global $wpdb;
2819
2820 $dir = trailingslashit( $dir );
2821 if ( @is_dir( $dir . 'meta' ) == false )
2822 return false;
2823
2824 if ( $handle = @opendir( $dir ) ) {
2825 $curr_blog_id = is_multisite() ? get_current_blog_id() : false;
2826
2827 while ( false !== ( $file = readdir( $handle ) ) ) {
2828 if ( is_file( $dir . $file ) == false || $file == 'index.html' ) {
2829 continue;
2830 }
2831
2832 if ( str_contains( $file, $file_prefix ) ) {
2833 if ( strpos( $file, '.html' ) ) {
2834 // delete old WPCache files immediately
2835 @unlink( $dir . $file);
2836 @unlink( $dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
2837 } else {
2838 $meta = json_decode( wp_cache_get_legacy_cache( $dir . 'meta/' . $file ), true );
2839 if ( $curr_blog_id && $curr_blog_id !== (int) $meta['blog_id'] ) {
2840 continue;
2841 }
2842 @unlink( $dir . $file);
2843 @unlink( $dir . 'meta/' . $file);
2844 }
2845 }
2846 }
2847 closedir($handle);
2848 }
2849 }
2850
2851 function wp_cache_clean_expired($file_prefix) {
2852 global $cache_max_time, $blog_cache_dir, $wp_cache_preload_on;
2853
2854 if ( $cache_max_time == 0 ) {
2855 return false;
2856 }
2857
2858 // If phase2 was compiled, use its function to avoid race-conditions
2859 if(function_exists('wp_cache_phase2_clean_expired')) {
2860 if ( $wp_cache_preload_on != 1 && function_exists ('prune_super_cache')) {
2861 $dir = get_supercache_dir();
2862 if( is_dir( $dir ) ) {
2863 prune_super_cache( $dir );
2864 } elseif( is_dir( $dir . '.disabled' ) ) {
2865 prune_super_cache( $dir . '.disabled' );
2866 }
2867 $_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
2868 }
2869 return wp_cache_phase2_clean_expired($file_prefix);
2870 }
2871
2872 $now = time();
2873 if ( $handle = @opendir( $blog_cache_dir ) ) {
2874 while ( false !== ( $file = readdir( $handle ) ) ) {
2875 if ( str_contains( $file, $file_prefix ) ) {
2876 if ( strpos( $file, '.html' ) ) {
2877 @unlink( $blog_cache_dir . $file);
2878 @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
2879 } elseif ( ( filemtime( $blog_cache_dir . $file ) + $cache_max_time ) <= $now ) {
2880 @unlink( $blog_cache_dir . $file );
2881 @unlink( $blog_cache_dir . 'meta/' . $file );
2882 }
2883 }
2884 }
2885 closedir($handle);
2886 }
2887 }
2888
2889 function wpsc_remove_marker( $filename, $marker ) {
2890 if (!file_exists( $filename ) || is_writeable_ACLSafe( $filename ) ) {
2891 if (!file_exists( $filename ) ) {
2892 return '';
2893 } else {
2894 $markerdata = explode( "\n", implode( '', file( $filename ) ) );
2895 }
2896
2897 $f = fopen( $filename, 'w' );
2898 if ( $markerdata ) {
2899 $state = true;
2900 foreach ( $markerdata as $n => $markerline ) {
2901 if (strpos($markerline, '# BEGIN ' . $marker) !== false)
2902 $state = false;
2903 if ( $state ) {
2904 if ( $n + 1 < count( $markerdata ) )
2905 fwrite( $f, "{$markerline}\n" );
2906 else
2907 fwrite( $f, "{$markerline}" );
2908 }
2909 if (strpos($markerline, '# END ' . $marker) !== false) {
2910 $state = true;
2911 }
2912 }
2913 }
2914 return true;
2915 } else {
2916 return false;
2917 }
2918 }
2919
2920 if( get_option( 'gzipcompression' ) )
2921 update_option( 'gzipcompression', 0 );
2922
2923 // Catch 404 requests. Themes that use query_posts() destroy $wp_query->is_404
2924 function wp_cache_catch_404() {
2925 global $wp_cache_404;
2926 if ( function_exists( '_deprecated_function' ) )
2927 _deprecated_function( __FUNCTION__, 'WP Super Cache 1.5.6' );
2928 $wp_cache_404 = false;
2929 if( is_404() )
2930 $wp_cache_404 = true;
2931 }
2932 //More info - https://github.com/Automattic/wp-super-cache/pull/373
2933 //add_action( 'template_redirect', 'wp_cache_catch_404' );
2934
2935 function wp_cache_favorite_action( $actions ) {
2936 if ( function_exists( '_deprecated_function' ) ) {
2937 _deprecated_function( __FUNCTION__, 'WP Super Cache 1.6.4' );
2938 }
2939
2940 if ( false == wpsupercache_site_admin() )
2941 return $actions;
2942
2943 if ( function_exists('current_user_can') && !current_user_can('manage_options') )
2944 return $actions;
2945
2946 $actions[ wp_nonce_url( 'options-general.php?page=wpsupercache&wp_delete_cache=1&tab=contents', 'wp-cache' ) ] = array( __( 'Delete Cache', 'wp-super-cache' ), 'manage_options' );
2947
2948 return $actions;
2949 }
2950 //add_filter( 'favorite_actions', 'wp_cache_favorite_action' );
2951
2952 function wp_cache_plugin_notice( $plugin ) {
2953 global $cache_enabled;
2954 if( $plugin == 'wp-super-cache/wp-cache.php' && !$cache_enabled && function_exists( 'admin_url' ) )
2955 echo '<td colspan="5" class="plugin-update">' . sprintf( __( 'WP Super Cache must be configured. Go to <a href="%s">the admin page</a> to enable and configure the plugin.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . '</td>';
2956 }
2957 add_action( 'after_plugin_row', 'wp_cache_plugin_notice' );
2958
2959 function wp_cache_plugin_actions( $links, $file ) {
2960 if ( $file === 'wp-super-cache/wp-cache.php' && function_exists( 'admin_url' ) && is_array( $links ) ) {
2961 $settings_link = '<a href="' . admin_url( 'options-general.php?page=wpsupercache' ) . '">' . __( 'Settings', 'wp-super-cache' ) . '</a>';
2962 array_unshift( $links, $settings_link ); // before other links
2963 }
2964 return $links;
2965 }
2966 add_filter( 'plugin_action_links', 'wp_cache_plugin_actions', 10, 2 );
2967
2968 function wp_cache_admin_notice() {
2969 global $cache_enabled, $wp_cache_phase1_loaded;
2970 if( substr( $_SERVER['PHP_SELF'], -11 ) == 'plugins.php' && !$cache_enabled && function_exists( 'admin_url' ) )
2971 echo '<div class="notice notice-info"><p><strong>' . sprintf( __('WP Super Cache is disabled. Please go to the <a href="%s">plugin admin page</a> to enable caching.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . '</strong></p></div>';
2972
2973 if ( defined( 'WP_CACHE' ) && WP_CACHE == true && ( defined( 'ADVANCEDCACHEPROBLEM' ) || ( $cache_enabled && false == isset( $wp_cache_phase1_loaded ) ) ) ) {
2974 if ( wp_cache_create_advanced_cache() ) {
2975 echo '<div class="notice notice-error"><p>' . sprintf( __( 'Warning! WP Super Cache caching <strong>was</strong> broken but has been <strong>fixed</strong>! The script advanced-cache.php could not load wp-cache-phase1.php.<br /><br />The file %1$s/advanced-cache.php has been recreated and WPCACHEHOME fixed in your wp-config.php. Reload to hide this message.', 'wp-super-cache' ), WP_CONTENT_DIR ) . '</p></div>';
2976 }
2977 }
2978 }
2979 add_action( 'admin_notices', 'wp_cache_admin_notice' );
2980
2981 function wp_cache_check_site() {
2982 global $wp_super_cache_front_page_check, $wp_super_cache_front_page_clear, $wp_super_cache_front_page_text, $wp_super_cache_front_page_notification, $wpdb;
2983
2984 if ( !isset( $wp_super_cache_front_page_check ) || ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 0 ) ) {
2985 return false;
2986 }
2987
2988 if ( function_exists( "wp_remote_get" ) == false ) {
2989 return false;
2990 }
2991 $front_page = wp_remote_get( site_url(), array('timeout' => 60, 'blocking' => true ) );
2992 if( is_array( $front_page ) ) {
2993 // Check for gzipped front page
2994 if ( $front_page[ 'headers' ][ 'content-type' ] == 'application/x-gzip' ) {
2995 if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) {
2996 wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Please clear cache!', 'wp-super-cache' ), home_url() ), sprintf( __( "Please visit %s to clear the cache as the front page of your site is now downloading!", 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) );
2997 } else {
2998 wp_cache_clear_cache( $wpdb->blogid );
2999 wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is gzipped! Cache Cleared!', 'wp-super-cache' ), home_url() ), sprintf( __( "The cache on your blog has been cleared because the front page of your site is now downloading. Please visit %s to verify the cache has been cleared.", 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) );
3000 }
3001 }
3002
3003 // Check for broken front page
3004 if (
3005 ! empty( $wp_super_cache_front_page_text )
3006 && ! str_contains( $front_page['body'], $wp_super_cache_front_page_text )
3007 ) {
3008 if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) {
3009 wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is not correct! Please clear cache!', 'wp-super-cache' ), home_url() ), sprintf( __( 'Please visit %1$s to clear the cache as the front page of your site is not correct and missing the text, "%2$s"!', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ), $wp_super_cache_front_page_text ) );
3010 } else {
3011 wp_cache_clear_cache( $wpdb->blogid );
3012 wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page is not correct! Cache Cleared!', 'wp-super-cache' ), home_url() ), sprintf( __( 'The cache on your blog has been cleared because the front page of your site is missing the text "%2$s". Please visit %1$s to verify the cache has been cleared.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ), $wp_super_cache_front_page_text ) );
3013 }
3014 }
3015 }
3016 if ( isset( $wp_super_cache_front_page_notification ) && $wp_super_cache_front_page_notification == 1 ) {
3017 wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Front page check!', 'wp-super-cache' ), home_url() ), sprintf( __( "WP Super Cache has checked the front page of your blog. Please visit %s if you would like to disable this.", 'wp-super-cache' ) . "\n\n", admin_url( 'options-general.php?page=wpsupercache' ) ) );
3018 }
3019
3020 if ( !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
3021 wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
3022 wp_cache_debug( 'scheduled wp_cache_check_site_hook for 360 seconds time.', 2 );
3023 }
3024 }
3025 add_action( 'wp_cache_check_site_hook', 'wp_cache_check_site' );
3026
3027 function update_cached_mobile_ua_list( $mobile_browsers, $mobile_prefixes = 0, $mobile_groups = 0 ) {
3028 global $wp_cache_config_file, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $wp_cache_mobile_groups;
3029 wp_cache_setting( 'wp_cache_mobile_browsers', $mobile_browsers );
3030 wp_cache_setting( 'wp_cache_mobile_prefixes', $mobile_prefixes );
3031 if ( is_array( $mobile_groups ) ) {
3032 $wp_cache_mobile_groups = $mobile_groups;
3033 wp_cache_replace_line('^ *\$wp_cache_mobile_groups', "\$wp_cache_mobile_groups = '" . implode( ', ', $mobile_groups ) . "';", $wp_cache_config_file);
3034 }
3035
3036 return true;
3037 }
3038
3039 function wpsc_update_htaccess() {
3040 extract( wpsc_get_htaccess_info() ); // $document_root, $apache_root, $home_path, $home_root, $home_root_lc, $inst_root, $wprules, $scrules, $condition_rules, $rules, $gziprules
3041 wpsc_remove_marker( $home_path.'.htaccess', 'WordPress' ); // remove original WP rules so SuperCache rules go on top
3042 if( insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', explode( "\n", $rules ) ) && insert_with_markers( $home_path.'.htaccess', 'WordPress', explode( "\n", $wprules ) ) ) {
3043 return true;
3044 } else {
3045 return false;
3046 }
3047 }
3048
3049 function wpsc_update_htaccess_form( $short_form = true ) {
3050 global $wpmu_version;
3051
3052 $admin_url = admin_url( 'options-general.php?page=wpsupercache' );
3053 extract( wpsc_get_htaccess_info() ); // $document_root, $apache_root, $home_path, $home_root, $home_root_lc, $inst_root, $wprules, $scrules, $condition_rules, $rules, $gziprules
3054 if( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) {
3055 echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><h5>" . __( 'Cannot update .htaccess', 'wp-super-cache' ) . "</h5><p>" . sprintf( __( 'The file <code>%s.htaccess</code> cannot be modified by the web server. Please correct this using the chmod command or your ftp client.', 'wp-super-cache' ), $home_path ) . "</p><p>" . __( 'Refresh this page when the file permissions have been modified.' ) . "</p><p>" . sprintf( __( 'Alternatively, you can edit your <code>%s.htaccess</code> file manually and add the following code (before any WordPress rules):', 'wp-super-cache' ), $home_path ) . "</p>";
3056 echo "<p><pre># BEGIN WPSuperCache\n" . esc_html( $rules ) . "# END WPSuperCache</pre></p></div>";
3057 } else {
3058 if ( $short_form == false ) {
3059 echo "<p>" . sprintf( __( 'To serve static html files your server must have the correct mod_rewrite rules added to a file called <code>%s.htaccess</code>', 'wp-super-cache' ), $home_path ) . " ";
3060 _e( "You can edit the file yourself. Add the following rules.", 'wp-super-cache' );
3061 echo __( " Make sure they appear before any existing WordPress rules. ", 'wp-super-cache' ) . "</p>";
3062 echo "<div style='overflow: auto; width: 800px; height: 400px; padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'>";
3063 echo "<pre># BEGIN WPSuperCache\n" . esc_html( $rules ) . "# END WPSuperCache</pre></p>";
3064 echo "</div>";
3065 echo "<h5>" . sprintf( __( 'Rules must be added to %s too:', 'wp-super-cache' ), WP_CONTENT_DIR . "/cache/.htaccess" ) . "</h5>";
3066 echo "<div style='overflow: auto; width: 800px; height: 400px; padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'>";
3067 echo "<pre># BEGIN supercache\n" . esc_html( $gziprules ) . "# END supercache</pre></p>";
3068 echo "</div>";
3069 }
3070 if ( !isset( $wpmu_version ) || $wpmu_version == '' ) {
3071 echo '<form name="updatehtaccess" action="' . esc_url_raw( add_query_arg( 'tab', 'settings', $admin_url ) . '#modrewrite' ) . '" method="post">';
3072 echo '<input type="hidden" name="updatehtaccess" value="1" />';
3073 echo '<div class="submit"><input class="button-primary" type="submit" ' . SUBMITDISABLED . 'id="updatehtaccess" value="' . __( 'Update Mod_Rewrite Rules', 'wp-super-cache' ) . '" /></div>';
3074 wp_nonce_field('wp-cache');
3075 echo "</form>\n";
3076 }
3077 }
3078 }
3079
3080 /*
3081 * Return LOGGED_IN_COOKIE if it doesn't begin with wordpress_logged_in
3082 * to avoid having people update their .htaccess file
3083 */
3084 function wpsc_get_logged_in_cookie() {
3085 $logged_in_cookie = 'wordpress_logged_in';
3086 if ( defined( 'LOGGED_IN_COOKIE' ) && substr( constant( 'LOGGED_IN_COOKIE' ), 0, 19 ) != 'wordpress_logged_in' )
3087 $logged_in_cookie = constant( 'LOGGED_IN_COOKIE' );
3088 return $logged_in_cookie;
3089 }
3090
3091 function wpsc_get_htaccess_info() {
3092 global $wp_cache_mobile_enabled, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_disable_utf8;
3093 global $htaccess_path;
3094
3095 if ( isset( $_SERVER[ "PHP_DOCUMENT_ROOT" ] ) ) {
3096 $document_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
3097 $apache_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
3098 } else {
3099 $document_root = $_SERVER[ "DOCUMENT_ROOT" ];
3100 $apache_root = '%{DOCUMENT_ROOT}';
3101 }
3102 $content_dir_root = $document_root;
3103 if ( strpos( $document_root, '/kunden/homepages/' ) === 0 ) {
3104 // https://wordpress.org/support/topic/plugin-wp-super-cache-how-to-get-mod_rewrite-working-on-1and1-shared-hosting?replies=1
3105 // On 1and1, PHP's directory structure starts with '/homepages'. The
3106 // Apache directory structure has an extra '/kunden' before it.
3107 // Also 1and1 does not support the %{DOCUMENT_ROOT} variable in
3108 // .htaccess files.
3109 // This prevents the $inst_root from being calculated correctly and
3110 // means that the $apache_root is wrong.
3111 //
3112 // e.g. This is an example of how Apache and PHP see the directory
3113 // structure on 1and1:
3114 // Apache: /kunden/homepages/xx/dxxxxxxxx/htdocs/site1/index.html
3115 // PHP: /homepages/xx/dxxxxxxxx/htdocs/site1/index.html
3116 // Here we fix up the paths to make mode_rewrite work on 1and1 shared hosting.
3117 $content_dir_root = substr( $content_dir_root, 7 );
3118 $apache_root = $document_root;
3119 }
3120 $home_path = get_home_path();
3121 $home_root = parse_url(get_bloginfo('url'));
3122 $home_root = isset( $home_root[ 'path' ] ) ? trailingslashit( $home_root[ 'path' ] ) : '/';
3123 if ( isset( $htaccess_path ) ) {
3124 $home_path = $htaccess_path;
3125 } elseif (
3126 $home_root == '/' &&
3127 $home_path != $_SERVER[ 'DOCUMENT_ROOT' ]
3128 ) {
3129 $home_path = $_SERVER[ 'DOCUMENT_ROOT' ];
3130 } elseif (
3131 $home_root != '/' &&
3132 $home_path != str_replace( '//', '/', $_SERVER[ 'DOCUMENT_ROOT' ] . $home_root ) &&
3133 is_dir( $_SERVER[ 'DOCUMENT_ROOT' ] . $home_root )
3134 ) {
3135 $home_path = str_replace( '//', '/', $_SERVER[ 'DOCUMENT_ROOT' ] . $home_root );
3136 }
3137
3138 $home_path = trailingslashit( $home_path );
3139 $home_root_lc = str_replace( '//', '/', strtolower( $home_root ) );
3140 $inst_root = str_replace( '//', '/', '/' . trailingslashit( str_replace( $content_dir_root, '', str_replace( '\\', '/', WP_CONTENT_DIR ) ) ) );
3141 $wprules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WordPress' ) );
3142 $wprules = str_replace( "RewriteEngine On\n", '', $wprules );
3143 $wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
3144 $scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
3145
3146 if( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
3147 $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*[^/]$";
3148 $condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*//.*$";
3149 }
3150 $condition_rules[] = "RewriteCond %{REQUEST_METHOD} !POST";
3151 $condition_rules[] = "RewriteCond %{QUERY_STRING} ^$";
3152 $condition_rules[] = "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|" . wpsc_get_logged_in_cookie() . wpsc_get_extra_cookies() . "|wp-postpass_).*$";
3153 $condition_rules[] = "RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\\\"]+ [NC]";
3154 $condition_rules[] = "RewriteCond %{HTTP:Profile} !^[a-z0-9\\\"]+ [NC]";
3155 if ( $wp_cache_mobile_enabled ) {
3156 if ( isset( $wp_cache_mobile_browsers ) && "" != $wp_cache_mobile_browsers )
3157 $condition_rules[] = "RewriteCond %{HTTP_USER_AGENT} !^.*(" . addcslashes( str_replace( ', ', '|', $wp_cache_mobile_browsers ), ' ' ) . ").* [NC]";
3158 if ( isset( $wp_cache_mobile_prefixes ) && "" != $wp_cache_mobile_prefixes )
3159 $condition_rules[] = "RewriteCond %{HTTP_USER_AGENT} !^(" . addcslashes( str_replace( ', ', '|', $wp_cache_mobile_prefixes ), ' ' ) . ").* [NC]";
3160 }
3161 $condition_rules = apply_filters( 'supercacherewriteconditions', $condition_rules );
3162
3163 $rules = "<IfModule mod_rewrite.c>\n";
3164 $rules .= "RewriteEngine On\n";
3165 $rules .= "RewriteBase $home_root\n"; // props Chris Messina
3166 $rules .= "#If you serve pages from behind a proxy you may want to change 'RewriteCond %{HTTPS} on' to something more sensible\n";
3167 if ( isset( $wp_cache_disable_utf8 ) == false || $wp_cache_disable_utf8 == 0 ) {
3168 $charset = get_option('blog_charset') == '' ? 'UTF-8' : get_option('blog_charset');
3169 $rules .= "AddDefaultCharset {$charset}\n";
3170 }
3171
3172 $rules .= "CONDITION_RULES";
3173 $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
3174 $rules .= "RewriteCond %{HTTPS} on\n";
3175 $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html.gz -f\n";
3176 $rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html.gz\" [L]\n\n";
3177
3178 $rules .= "CONDITION_RULES";
3179 $rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
3180 $rules .= "RewriteCond %{HTTPS} !on\n";
3181 $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html.gz -f\n";
3182 $rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html.gz\" [L]\n\n";
3183
3184 $rules .= "CONDITION_RULES";
3185 $rules .= "RewriteCond %{HTTPS} on\n";
3186 $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html -f\n";
3187 $rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html\" [L]\n\n";
3188
3189 $rules .= "CONDITION_RULES";
3190 $rules .= "RewriteCond %{HTTPS} !on\n";
3191 $rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html -f\n";
3192 $rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html\" [L]\n";
3193 $rules .= "</IfModule>\n";
3194 $rules = apply_filters( 'supercacherewriterules', $rules );
3195
3196 $rules = str_replace( "CONDITION_RULES", implode( "\n", $condition_rules ) . "\n", $rules );
3197
3198 $gziprules = "<IfModule mod_mime.c>\n <FilesMatch \"\\.html\\.gz\$\">\n ForceType text/html\n FileETag None\n </FilesMatch>\n AddEncoding gzip .gz\n AddType text/html .gz\n</IfModule>\n";
3199 $gziprules .= "<IfModule mod_deflate.c>\n SetEnvIfNoCase Request_URI \.gz$ no-gzip\n</IfModule>\n";
3200
3201 // Default headers.
3202 $headers = array(
3203 'Vary' => 'Accept-Encoding, Cookie',
3204 'Cache-Control' => 'max-age=3, must-revalidate',
3205 );
3206
3207 // Allow users to override the Vary header with WPSC_VARY_HEADER.
3208 if ( defined( 'WPSC_VARY_HEADER' ) && ! empty( WPSC_VARY_HEADER ) ) {
3209 $headers['Vary'] = WPSC_VARY_HEADER;
3210 }
3211
3212 // Allow users to override Cache-control header with WPSC_CACHE_CONTROL_HEADER
3213 if ( defined( 'WPSC_CACHE_CONTROL_HEADER' ) && ! empty( WPSC_CACHE_CONTROL_HEADER ) ) {
3214 $headers['Cache-Control'] = WPSC_CACHE_CONTROL_HEADER;
3215 }
3216
3217 // Allow overriding headers with a filter.
3218 $headers = apply_filters( 'wpsc_htaccess_mod_headers', $headers );
3219
3220 // Combine headers into a block of text.
3221 $headers_text = implode(
3222 "\n",
3223 array_map(
3224 function ( $key, $value ) {
3225 return " Header set $key '" . addcslashes( $value, "'" ) . "'";
3226 },
3227 array_keys( $headers ),
3228 array_values( $headers )
3229 )
3230 );
3231
3232 // Pack headers into gziprules (for historic reasons) - TODO refactor the values
3233 // returned to better reflect the blocks being written.
3234 if ( $headers_text != '' ) {
3235 $gziprules .= "<IfModule mod_headers.c>\n$headers_text\n</IfModule>\n";
3236 }
3237
3238 // Deafult mod_expires rules.
3239 $expires_rules = array(
3240 'ExpiresActive On',
3241 'ExpiresByType text/html A3',
3242 );
3243
3244 // Allow overriding mod_expires rules with a filter.
3245 $expires_rules = apply_filters( 'wpsc_htaccess_mod_expires', $expires_rules );
3246
3247 $gziprules .= "<IfModule mod_expires.c>\n";
3248 $gziprules .= implode(
3249 "\n",
3250 array_map(
3251 function ( $line ) {
3252 return " $line";
3253 },
3254 $expires_rules
3255 )
3256 );
3257 $gziprules .= "\n</IfModule>\n";
3258
3259 $gziprules .= "Options -Indexes\n";
3260
3261 return array(
3262 'document_root' => $document_root,
3263 'apache_root' => $apache_root,
3264 'home_path' => $home_path,
3265 'home_root' => $home_root,
3266 'home_root_lc' => $home_root_lc,
3267 'inst_root' => $inst_root,
3268 'wprules' => $wprules,
3269 'scrules' => $scrules,
3270 'condition_rules' => $condition_rules,
3271 'rules' => $rules,
3272 'gziprules' => $gziprules,
3273 );
3274 }
3275
3276 function clear_post_supercache( $post_id ) {
3277 $dir = get_current_url_supercache_dir( $post_id );
3278 if ( false == @is_dir( $dir ) )
3279 return false;
3280
3281 if ( get_supercache_dir() == $dir ) {
3282 wp_cache_debug( "clear_post_supercache: not deleting post_id $post_id as it points at homepage: $dir" );
3283 return false;
3284 }
3285
3286 wp_cache_debug( "clear_post_supercache: post_id: $post_id. deleting files in $dir" );
3287 if ( get_post_type( $post_id ) != 'page') { // don't delete child pages if they exist
3288 prune_super_cache( $dir, true );
3289 } else {
3290 wpsc_delete_files( $dir );
3291 }
3292 }
3293
3294 /**
3295 * Serves an AJAX endpoint to return the current state of the preload process.
3296 */
3297 function wpsc_ajax_get_preload_status() {
3298 $preload_status = wpsc_get_preload_status( true );
3299 wp_send_json_success( $preload_status );
3300 }
3301 add_action( 'wp_ajax_wpsc_get_preload_status', 'wpsc_ajax_get_preload_status' );
3302
3303 /**
3304 * Returns the location of the preload status file.
3305 */
3306 function wpsc_get_preload_status_file_path() {
3307 global $cache_path;
3308 return $cache_path . 'preload_permalink.txt';
3309 }
3310
3311 /**
3312 * Get the timestamp of the next preload.
3313 */
3314 function wpsc_get_next_preload_time() {
3315 $next = wp_next_scheduled( 'wp_cache_preload_hook' );
3316 if ( ! $next ) {
3317 $next = wp_next_scheduled( 'wp_cache_full_preload_hook' );
3318 }
3319
3320 return $next;
3321 }
3322
3323 /**
3324 * Read the preload status. Caches the result in a static variable.
3325 */
3326 function wpsc_get_preload_status( $include_next = false ) {
3327 $status = array(
3328 'running' => false,
3329 'history' => array(),
3330 'next' => false,
3331 'previous' => null,
3332 );
3333
3334 $filename = wpsc_get_preload_status_file_path();
3335 if ( file_exists( $filename ) ) {
3336 $data = wp_json_file_decode( $filename, array( 'associative' => true ) );
3337 if ( is_array( $data ) ) {
3338 $status = $data;
3339 }
3340 }
3341
3342 if ( $include_next ) {
3343 $status['next'] = wpsc_get_next_preload_time();
3344 }
3345
3346 return $status;
3347 }
3348
3349 /**
3350 * Update the preload status file during a preload.
3351 */
3352 function wpsc_update_active_preload( $group = null, $progress = null, $url = null ) {
3353 $preload_status = wpsc_get_preload_status();
3354
3355 $preload_status['running'] = true;
3356
3357 // Add the new entry to the history.
3358 array_unshift(
3359 $preload_status['history'],
3360 array(
3361 'group' => $group,
3362 'progress' => $progress,
3363 'url' => $url,
3364 )
3365 );
3366
3367 // Limit to 5 in the history.
3368 $preload_status['history'] = array_slice( $preload_status['history'], 0, 5 );
3369
3370 $filename = wpsc_get_preload_status_file_path();
3371 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents
3372 if ( false === file_put_contents( $filename, wp_json_encode( $preload_status ) ) ) {
3373 wp_cache_debug( "wpsc_update_active_preload: failed to write to $filename" );
3374 }
3375 }
3376
3377 /**
3378 * Update the preload status to indicate it is idle. If a finish time is specified, store it.
3379 */
3380 function wpsc_update_idle_preload( $finish_time = null ) {
3381 $preload_status = wpsc_get_preload_status();
3382
3383 $preload_status['running'] = false;
3384 $preload_status['history'] = array();
3385
3386 if ( ! empty( $finish_time ) ) {
3387 $preload_status['previous'] = $finish_time;
3388 }
3389
3390 $filename = wpsc_get_preload_status_file_path();
3391 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents
3392 if ( false === file_put_contents( $filename, wp_json_encode( $preload_status ) ) ) {
3393 wp_cache_debug( "wpsc_update_idle_preload: failed to write to $filename" );
3394 }
3395 }
3396
3397 function wp_cron_preload_cache() {
3398 global $wpdb, $wp_cache_preload_interval, $wp_cache_preload_posts, $wp_cache_preload_email_me, $wp_cache_preload_email_volume, $cache_path, $wp_cache_preload_taxonomies;
3399
3400 // check if stop_preload.txt exists and preload should be stopped.
3401 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
3402 if ( @file_exists( $cache_path . 'stop_preload.txt' ) ) {
3403 wp_cache_debug( 'wp_cron_preload_cache: preload cancelled. Aborting preload.' );
3404 wpsc_reset_preload_settings();
3405 return true;
3406 }
3407
3408 /*
3409 * The mutex file is used to prevent multiple preload processes from running at the same time.
3410 * If the mutex file is found, the preload process will wait 3-8 seconds and then check again.
3411 * If the mutex file is still found, the preload process will abort.
3412 * If the mutex file is not found, the preload process will create the mutex file and continue.
3413 * The mutex file is deleted at the end of the preload process.
3414 * The mutex file is deleted if it is more than 10 minutes old.
3415 * The mutex file should only be deleted by the preload process that created it.
3416 * If the mutex file is deleted by another process, another preload process may start.
3417 */
3418 $mutex = $cache_path . "preload_mutex.tmp";
3419 if ( @file_exists( $mutex ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
3420 sleep( 3 + wp_rand( 1, 5 ) );
3421 // check again just in case another preload process is still running.
3422 if ( @file_exists( $mutex ) && @filemtime( $mutex ) > ( time() - 600 ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
3423 wp_cache_debug( 'wp_cron_preload_cache: preload mutex found and less than 600 seconds old. Aborting preload.', 1 );
3424 return true;
3425 } else {
3426 wp_cache_debug( 'wp_cron_preload_cache: old preload mutex found and deleted. Preload continues.', 1 );
3427 @unlink( $mutex );
3428 }
3429 }
3430 $fp = @fopen( $mutex, 'w' );
3431 @fclose( $fp );
3432
3433 $counter = get_option( 'preload_cache_counter' );
3434 $c = $counter[ 'c' ];
3435
3436 if ( $wp_cache_preload_email_volume == 'none' && $wp_cache_preload_email_me == 1 ) {
3437 $wp_cache_preload_email_me = 0;
3438 wp_cache_setting( 'wp_cache_preload_email_me', 0 );
3439 }
3440
3441 $just_started_preloading = false;
3442
3443 /*
3444 * Preload taxonomies first.
3445 *
3446 */
3447 if ( isset( $wp_cache_preload_taxonomies ) && $wp_cache_preload_taxonomies ) {
3448 wp_cache_debug( 'wp_cron_preload_cache: doing taxonomy preload.', 5 );
3449 $taxonomies = apply_filters(
3450 'wp_cache_preload_taxonomies',
3451 array(
3452 'post_tag' => 'tag',
3453 'category' => 'category',
3454 )
3455 );
3456
3457 $preload_more_taxonomies = false;
3458
3459 foreach ( $taxonomies as $taxonomy => $path ) {
3460 $taxonomy_filename = $cache_path . 'taxonomy_' . $taxonomy . '.txt';
3461
3462 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
3463 if ( false === @file_exists( $taxonomy_filename ) ) {
3464
3465 if ( ! $just_started_preloading && $wp_cache_preload_email_me ) {
3466 // translators: 1: site url
3467 wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Started', 'wp-super-cache' ), home_url(), '' ), ' ' );
3468 }
3469
3470 $just_started_preloading = true;
3471 $out = '';
3472 $records = get_terms( $taxonomy );
3473 foreach ( $records as $term ) {
3474 $out .= get_term_link( $term ) . "\n";
3475 }
3476 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen
3477 $fp = fopen( $taxonomy_filename, 'w' );
3478 if ( $fp ) {
3479 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite
3480 fwrite( $fp, $out );
3481 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose
3482 fclose( $fp );
3483 }
3484 $details = explode( "\n", $out );
3485 } else {
3486 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
3487 $details = explode( "\n", file_get_contents( $taxonomy_filename ) );
3488 }
3489 if ( count( $details ) > 0 && $details[0] !== '' ) {
3490 $rows = array_splice( $details, 0, WPSC_PRELOAD_POST_COUNT );
3491 if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume === 'many' ) {
3492 // translators: 1: Site URL, 2: Taxonomy name, 3: Number of posts done, 4: Number of posts to preload
3493 wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Refreshing %2$s taxonomy from %3$d to %4$d', 'wp-super-cache' ), home_url(), $taxonomy, $c, ( $c + WPSC_PRELOAD_POST_COUNT ) ), 'Refreshing: ' . print_r( $rows, 1 ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
3494 }
3495
3496 foreach ( (array) $rows as $url ) {
3497 set_time_limit( 60 );
3498 if ( $url === '' ) {
3499 continue;
3500 }
3501
3502 $url_info = wp_parse_url( $url );
3503 $dir = get_supercache_dir() . $url_info['path'];
3504 wp_cache_debug( "wp_cron_preload_cache: delete $dir" );
3505 wpsc_delete_files( $dir );
3506 prune_super_cache( trailingslashit( $dir ) . 'feed/', true );
3507 prune_super_cache( trailingslashit( $dir ) . 'page/', true );
3508
3509 wpsc_update_active_preload( 'taxonomies', $taxonomy, $url );
3510
3511 wp_remote_get(
3512 $url,
3513 array(
3514 'timeout' => 60,
3515 'blocking' => true,
3516 )
3517 );
3518 wp_cache_debug( "wp_cron_preload_cache: fetched $url" );
3519 sleep( WPSC_PRELOAD_POST_INTERVAL );
3520
3521 if ( ! wpsc_is_preload_active() ) {
3522 wp_cache_debug( 'wp_cron_preload_cache: cancelling preload process.' );
3523 wpsc_reset_preload_settings();
3524
3525 if ( $wp_cache_preload_email_me ) {
3526 // translators: Home URL of website
3527 wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Stopped', 'wp-super-cache' ), home_url(), '' ), ' ' );
3528 }
3529 wpsc_update_idle_preload( time() );
3530 return true;
3531 }
3532 }
3533 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen
3534 $fp = fopen( $taxonomy_filename, 'w' );
3535 if ( $fp ) {
3536 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite
3537 fwrite( $fp, implode( "\n", $details ) );
3538 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose
3539 fclose( $fp );
3540 }
3541 }
3542
3543 if (
3544 $preload_more_taxonomies === false &&
3545 count( $details ) > 0 &&
3546 $details[0] !== ''
3547 ) {
3548 $preload_more_taxonomies = true;
3549 }
3550 }
3551
3552 if ( $preload_more_taxonomies === true ) {
3553 wpsc_schedule_next_preload();
3554 sleep( WPSC_PRELOAD_LOOP_INTERVAL );
3555 return true;
3556 }
3557 } elseif ( $c === 0 && $wp_cache_preload_email_me ) {
3558 // translators: Home URL of website
3559 wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Started', 'wp-super-cache' ), home_url(), '' ), ' ' );
3560 }
3561
3562 /*
3563 *
3564 * Preload posts now.
3565 *
3566 * The preload_cache_counter has two values:
3567 * c = the number of posts we've preloaded after this loop.
3568 * t = the time we started preloading in the current loop.
3569 *
3570 * $c is set to the value of preload_cache_counter['c'] at the start of the function
3571 * before it is incremented by WPSC_PRELOAD_POST_COUNT here.
3572 * The time is used to check if preloading has stalled in check_up_on_preloading().
3573 */
3574
3575 update_option(
3576 'preload_cache_counter',
3577 array(
3578 'c' => ( $c + WPSC_PRELOAD_POST_COUNT ),
3579 't' => time(),
3580 )
3581 );
3582
3583 if ( $wp_cache_preload_posts == 'all' || $c < $wp_cache_preload_posts ) {
3584 $types = wpsc_get_post_types();
3585 $posts = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE ( post_type IN ( $types ) ) AND post_status = 'publish' ORDER BY ID DESC LIMIT %d," . WPSC_PRELOAD_POST_COUNT, $c ) ); // phpcs:ignore
3586 wp_cache_debug( 'wp_cron_preload_cache: got ' . WPSC_PRELOAD_POST_COUNT . ' posts from position ' . $c );
3587 } else {
3588 wp_cache_debug( "wp_cron_preload_cache: no more posts to get. Limit ($wp_cache_preload_posts) reached.", 5 );
3589 $posts = false;
3590 }
3591 if ( !isset( $wp_cache_preload_email_volume ) )
3592 $wp_cache_preload_email_volume = 'medium';
3593
3594 if ( $posts ) {
3595 if ( get_option( 'show_on_front' ) == 'page' ) {
3596 $page_on_front = get_option( 'page_on_front' );
3597 $page_for_posts = get_option( 'page_for_posts' );
3598 } else {
3599 $page_on_front = $page_for_posts = 0;
3600 }
3601 if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume === 'many' ) {
3602 /* translators: 1: home url, 2: start post id, 3: end post id */
3603 wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Refreshing posts from %2$d to %3$d', 'wp-super-cache' ), home_url(), $c, ( $c + WPSC_PRELOAD_POST_COUNT ) ), ' ' );
3604 }
3605 $msg = '';
3606 $count = $c + 1;
3607
3608 foreach( $posts as $post_id ) {
3609 set_time_limit( 60 );
3610 if ( $page_on_front != 0 && ( $post_id == $page_on_front || $post_id == $page_for_posts ) )
3611 continue;
3612 $url = get_permalink( $post_id );
3613
3614 if ( ! is_string( $url ) ) {
3615 wp_cache_debug( "wp_cron_preload_cache: skipped $post_id. Expected a URL, received: " . gettype( $url ) );
3616 continue;
3617 }
3618
3619 if ( wp_cache_is_rejected( $url ) ) {
3620 wp_cache_debug( "wp_cron_preload_cache: skipped $url per rejected strings setting" );
3621 continue;
3622 }
3623 clear_post_supercache( $post_id );
3624
3625 wpsc_update_active_preload( 'posts', $count, $url );
3626
3627 if ( ! wpsc_is_preload_active() ) {
3628 wp_cache_debug( 'wp_cron_preload_cache: cancelling preload process.' );
3629 wpsc_reset_preload_settings();
3630
3631 if ( $wp_cache_preload_email_me ) {
3632 // translators: Home URL of website
3633 wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Stopped', 'wp-super-cache' ), home_url(), '' ), ' ' );
3634 }
3635
3636 wpsc_update_idle_preload( time() );
3637 return true;
3638 }
3639
3640 $msg .= "$url\n";
3641 wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
3642 wp_cache_debug( "wp_cron_preload_cache: fetched $url", 5 );
3643 ++$count;
3644 sleep( WPSC_PRELOAD_POST_INTERVAL );
3645 }
3646
3647 if ( $wp_cache_preload_email_me && ( $wp_cache_preload_email_volume === 'medium' || $wp_cache_preload_email_volume === 'many' ) ) {
3648 // translators: 1: home url, 2: number of posts refreshed
3649 wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] %2$d posts refreshed', 'wp-super-cache' ), home_url(), ( $c + WPSC_PRELOAD_POST_COUNT ) ), __( 'Refreshed the following posts:', 'wp-super-cache' ) . "\n$msg" );
3650 }
3651
3652 wpsc_schedule_next_preload();
3653 wpsc_delete_files( get_supercache_dir() );
3654 sleep( WPSC_PRELOAD_LOOP_INTERVAL );
3655 } else {
3656 $msg = '';
3657 wpsc_reset_preload_counter();
3658 if ( (int)$wp_cache_preload_interval && defined( 'DOING_CRON' ) ) {
3659 if ( $wp_cache_preload_email_me )
3660 $msg = sprintf( __( 'Scheduling next preload refresh in %d minutes.', 'wp-super-cache' ), (int)$wp_cache_preload_interval );
3661 wp_cache_debug( "wp_cron_preload_cache: no more posts. scheduling next preload in $wp_cache_preload_interval minutes.", 5 );
3662 wp_schedule_single_event( time() + ( (int)$wp_cache_preload_interval * 60 ), 'wp_cache_full_preload_hook' );
3663 }
3664 global $file_prefix, $cache_max_time;
3665 if ( $wp_cache_preload_interval > 0 ) {
3666 $cache_max_time = (int)$wp_cache_preload_interval * 60; // fool the GC into expiring really old files
3667 } else {
3668 $cache_max_time = 86400; // fool the GC into expiring really old files
3669 }
3670 if ( $wp_cache_preload_email_me )
3671 wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Cache Preload Completed', 'wp-super-cache' ), home_url() ), __( "Cleaning up old supercache files.", 'wp-super-cache' ) . "\n" . $msg );
3672 if ( $cache_max_time > 0 ) { // GC is NOT disabled
3673 wp_cache_debug( "wp_cron_preload_cache: clean expired cache files older than $cache_max_time seconds.", 5 );
3674 wp_cache_phase2_clean_expired( $file_prefix, true ); // force cleanup of old files.
3675 }
3676
3677 wpsc_reset_preload_settings();
3678 wpsc_update_idle_preload( time() );
3679 }
3680 @unlink( $mutex );
3681 }
3682 add_action( 'wp_cache_preload_hook', 'wp_cron_preload_cache' );
3683 add_action( 'wp_cache_full_preload_hook', 'wp_cron_preload_cache' );
3684
3685 /*
3686 * Schedule the next preload event without resetting the preload counter.
3687 * This happens when the next loop of an active preload is scheduled.
3688 */
3689 function wpsc_schedule_next_preload() {
3690 global $cache_path;
3691
3692 /*
3693 * Edge case: If preload is not active, don't schedule the next preload.
3694 * This can happen if the preload is cancelled by the user right after a loop finishes.
3695 */
3696 if ( ! wpsc_is_preload_active() ) {
3697 wpsc_reset_preload_settings();
3698 wp_cache_debug( 'wpsc_schedule_next_preload: preload is not active. not scheduling next preload.' );
3699 return;
3700 }
3701
3702 if ( defined( 'DOING_CRON' ) ) {
3703 wp_cache_debug( 'wp_cron_preload_cache: scheduling the next preload in 3 seconds.' );
3704 wp_schedule_single_event( time() + 3, 'wp_cache_preload_hook' );
3705 }
3706
3707 // we always want to delete the mutex file, even if we're not using cron
3708 $mutex = $cache_path . 'preload_mutex.tmp';
3709 wp_delete_file( $mutex );
3710 }
3711
3712 function option_preload_cache_counter( $value ) {
3713 if ( false == is_array( $value ) ) {
3714 return array(
3715 'c' => 0,
3716 't' => time(),
3717 );
3718 } else {
3719 return $value;
3720 }
3721 }
3722 add_filter( 'option_preload_cache_counter', 'option_preload_cache_counter' );
3723
3724 function check_up_on_preloading() {
3725 $value = get_option( 'preload_cache_counter' );
3726 if ( is_array( $value ) && $value['c'] > 0 && ( time() - $value['t'] ) > 3600 && false === wp_next_scheduled( 'wp_cache_preload_hook' ) ) {
3727 wp_schedule_single_event( time() + 5, 'wp_cache_preload_hook' );
3728 }
3729 }
3730 add_action( 'init', 'check_up_on_preloading' ); // sometimes preloading stops working. Kickstart it.
3731
3732 function wp_cache_disable_plugin( $delete_config_file = true ) {
3733 global $wp_rewrite;
3734 if ( file_exists( ABSPATH . 'wp-config.php') ) {
3735 $global_config_file = ABSPATH . 'wp-config.php';
3736 } else {
3737 $global_config_file = dirname(ABSPATH) . '/wp-config.php';
3738 }
3739
3740 if ( apply_filters( 'wpsc_enable_wp_config_edit', true ) ) {
3741 $line = 'define(\'WP_CACHE\', true);';
3742 if (
3743 strpos( file_get_contents( $global_config_file ), $line ) &&
3744 (
3745 ! is_writeable_ACLSafe( $global_config_file ) ||
3746 ! wp_cache_replace_line( 'define*\(*\'WP_CACHE\'', '', $global_config_file )
3747 )
3748 ) {
3749 wp_die( "Could not remove WP_CACHE define from $global_config_file. Please edit that file and remove the line containing the text 'WP_CACHE'. Then refresh this page." );
3750 }
3751 $line = 'define( \'WPCACHEHOME\',';
3752 if (
3753 strpos( file_get_contents( $global_config_file ), $line ) &&
3754 (
3755 ! is_writeable_ACLSafe( $global_config_file ) ||
3756 ! wp_cache_replace_line( 'define *\( *\'WPCACHEHOME\'', '', $global_config_file )
3757 )
3758 ) {
3759 wp_die( "Could not remove WPCACHEHOME define from $global_config_file. Please edit that file and remove the line containing the text 'WPCACHEHOME'. Then refresh this page." );
3760 }
3761 } elseif ( function_exists( 'wp_cache_debug' ) ) {
3762 wp_cache_debug( 'wp_cache_disable_plugin: not allowed to edit wp-config.php per configuration.' );
3763 }
3764
3765 uninstall_supercache( WP_CONTENT_DIR . '/cache' );
3766 $file_not_deleted = array();
3767 wpsc_remove_advanced_cache();
3768 if ( @file_exists( WP_CONTENT_DIR . "/advanced-cache.php" ) ) {
3769 $file_not_deleted[] = WP_CONTENT_DIR . '/advanced-cache.php';
3770 }
3771 if ( $delete_config_file && @file_exists( WPCACHECONFIGPATH . "/wp-cache-config.php" ) ) {
3772 if ( false == unlink( WPCACHECONFIGPATH . "/wp-cache-config.php" ) )
3773 $file_not_deleted[] = WPCACHECONFIGPATH . '/wp-cache-config.php';
3774 }
3775 if ( ! empty( $file_not_deleted ) ) {
3776 $msg = __( "Dear User,\n\nWP Super Cache was removed from your blog or deactivated but some files could\nnot be deleted.\n\n", 'wp-super-cache' );
3777 foreach( (array)$file_not_deleted as $path ) {
3778 $msg .= "{$path}\n";
3779 }
3780 $msg .= "\n";
3781 $msg .= sprintf( __( "You should delete these files manually.\nYou may need to change the permissions of the files or parent directory.\nYou can read more about this in the Codex at\n%s\n\nThank you.", 'wp-super-cache' ), 'https://codex.wordpress.org/Changing_File_Permissions#About_Chmod' );
3782
3783 if ( apply_filters( 'wpsc_send_uninstall_errors', 1 ) ) {
3784 wp_mail( get_option( 'admin_email' ), __( 'WP Super Cache: could not delete files', 'wp-super-cache' ), $msg );
3785 }
3786 }
3787 extract( wpsc_get_htaccess_info() ); // $document_root, $apache_root, $home_path, $home_root, $home_root_lc, $inst_root, $wprules, $scrules, $condition_rules, $rules, $gziprules
3788 if ( $scrules != '' && insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', array() ) ) {
3789 $wp_rewrite->flush_rules();
3790 } elseif( $scrules != '' ) {
3791 wp_mail( get_option( 'admin_email' ), __( 'Supercache Uninstall Problems', 'wp-super-cache' ), sprintf( __( "Dear User,\n\nWP Super Cache was removed from your blog but the mod_rewrite rules\nin your .htaccess were not.\n\nPlease edit the following file and remove the code\nbetween 'BEGIN WPSuperCache' and 'END WPSuperCache'. Please backup the file first!\n\n%s\n\nRegards,\nWP Super Cache Plugin\nhttps://wordpress.org/plugins/wp-super-cache/", 'wp-super-cache' ), ABSPATH . '/.htaccess' ) );
3792 }
3793 }
3794
3795 function uninstall_supercache( $folderPath ) { // from http://www.php.net/manual/en/function.rmdir.php
3796 if ( trailingslashit( constant( 'ABSPATH' ) ) == trailingslashit( $folderPath ) )
3797 return false;
3798 if ( @is_dir ( $folderPath ) ) {
3799 $dh = @opendir($folderPath);
3800 while( false !== ( $value = @readdir( $dh ) ) ) {
3801 if ( $value != "." && $value != ".." ) {
3802 $value = $folderPath . "/" . $value;
3803 if ( @is_dir ( $value ) ) {
3804 uninstall_supercache( $value );
3805 } else {
3806 @unlink( $value );
3807 }
3808 }
3809 }
3810 return @rmdir( $folderPath );
3811 } else {
3812 return false;
3813 }
3814 }
3815
3816 function supercache_admin_bar_render() {
3817 global $wp_admin_bar;
3818
3819 if ( function_exists( '_deprecated_function' ) ) {
3820 _deprecated_function( __FUNCTION__, 'WP Super Cache 1.6.4' );
3821 }
3822
3823 wpsc_admin_bar_render( $wp_admin_bar );
3824 }
3825
3826 /*
3827 * returns true if preload is active
3828 */
3829 function wpsc_is_preload_active() {
3830 global $cache_path;
3831
3832 // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
3833 if ( @file_exists( $cache_path . 'stop_preload.txt' ) ) {
3834 return false;
3835 }
3836
3837 if ( file_exists( $cache_path . 'preload_mutex.tmp' ) ) {
3838 return true;
3839 }
3840
3841 // check taxonomy preload loop
3842 $taxonomies = apply_filters(
3843 'wp_cache_preload_taxonomies',
3844 array(
3845 'post_tag' => 'tag',
3846 'category' => 'category',
3847 )
3848 );
3849
3850 foreach ( $taxonomies as $taxonomy => $path ) {
3851 $taxonomy_filename = $cache_path . 'taxonomy_' . $taxonomy . '.txt';
3852 if ( file_exists( $taxonomy_filename ) ) {
3853 return true;
3854 }
3855 }
3856
3857 // check post preload loop
3858 $preload_cache_counter = get_option( 'preload_cache_counter' );
3859 if (
3860 is_array( $preload_cache_counter )
3861 && isset( $preload_cache_counter['c'] )
3862 && $preload_cache_counter['c'] > 0
3863 ) {
3864 return true;
3865 }
3866
3867 return false;
3868 }
3869
3870 /*
3871 * This function will reset the preload cache counter
3872 */
3873 function wpsc_reset_preload_counter() {
3874 update_option(
3875 'preload_cache_counter',
3876 array(
3877 'c' => 0,
3878 't' => time(),
3879 )
3880 );
3881 }
3882
3883 /*
3884 * This function will reset all preload settings
3885 */
3886 function wpsc_reset_preload_settings() {
3887 global $cache_path;
3888
3889 $mutex = $cache_path . 'preload_mutex.tmp';
3890 wp_delete_file( $mutex );
3891 wp_delete_file( $cache_path . 'stop_preload.txt' );
3892 wpsc_reset_preload_counter();
3893
3894 $taxonomies = apply_filters(
3895 'wp_cache_preload_taxonomies',
3896 array(
3897 'post_tag' => 'tag',
3898 'category' => 'category',
3899 )
3900 );
3901
3902 foreach ( $taxonomies as $taxonomy => $path ) {
3903 $taxonomy_filename = $cache_path . 'taxonomy_' . $taxonomy . '.txt';
3904 wp_delete_file( $taxonomy_filename );
3905 }
3906 }
3907
3908 function wpsc_cancel_preload() {
3909 $next_preload = wp_next_scheduled( 'wp_cache_preload_hook' );
3910 $next_full_preload = wp_next_scheduled( 'wp_cache_full_preload_hook' );
3911
3912 if ( $next_preload || $next_full_preload ) {
3913 wp_cache_debug( 'wpsc_cancel_preload: reset preload settings' );
3914 wpsc_reset_preload_settings();
3915 }
3916
3917 if ( $next_preload ) {
3918 wp_cache_debug( 'wpsc_cancel_preload: unscheduling wp_cache_preload_hook' );
3919 wp_unschedule_event( $next_preload, 'wp_cache_preload_hook' );
3920 }
3921 if ( $next_full_preload ) {
3922 wp_cache_debug( 'wpsc_cancel_preload: unscheduling wp_cache_full_preload_hook' );
3923 wp_unschedule_event( $next_full_preload, 'wp_cache_full_preload_hook' );
3924 }
3925 wp_cache_debug( 'wpsc_cancel_preload: creating stop_preload.txt' );
3926
3927 /*
3928 * Reset the preload settings, but also create the stop_preload.txt file to
3929 * prevent the preload from starting again.
3930 * By creating the stop_preload.txt file, we can be sure the preload will cancel.
3931 */
3932 wpsc_reset_preload_settings();
3933 wpsc_create_stop_preload_flag();
3934 wpsc_update_idle_preload( time() );
3935 }
3936
3937 /*
3938 * The preload process checks for a file called stop_preload.txt and will stop if found.
3939 * This function creates that file.
3940 */
3941 function wpsc_create_stop_preload_flag() {
3942 global $cache_path;
3943 // phpcs:ignore -- WordPress.WP.AlternativeFunctions.file_system_read_fopen WordPress.PHP.NoSilencedErrors.Discouraged
3944 $fp = @fopen( $cache_path . 'stop_preload.txt', 'w' );
3945 // phpcs:ignore -- WordPress.WP.AlternativeFunctions.file_system_operations_fclose WordPress.PHP.NoSilencedErrors.Discouraged
3946 @fclose( $fp );
3947 }
3948
3949 function wpsc_enable_preload() {
3950
3951 wpsc_reset_preload_settings();
3952 wp_schedule_single_event( time() + 10, 'wp_cache_full_preload_hook' );
3953 }
3954
3955 function wpsc_get_post_types() {
3956
3957 $preload_type_args = apply_filters( 'wpsc_preload_post_types_args', array(
3958 'public' => true,
3959 'publicly_queryable' => true
3960 ) );
3961
3962 $post_types = (array) apply_filters( 'wpsc_preload_post_types', get_post_types( $preload_type_args, 'names', 'or' ));
3963
3964 return "'" . implode( "', '", array_map( 'esc_sql', $post_types ) ) . "'";
3965 }
3966 function wpsc_post_count() {
3967 global $wpdb;
3968 static $count;
3969
3970 if ( isset( $count ) ) {
3971 return $count;
3972 }
3973
3974 $post_type_list = wpsc_get_post_types();
3975 $count = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type IN ( $post_type_list ) AND post_status = 'publish'" );
3976
3977 return $count;
3978 }
3979
3980 /**
3981 * Get the minimum interval in minutes between preload refreshes.
3982 * Filter the default value of 10 minutes using the `wpsc_minimum_preload_interval` filter.
3983 *
3984 * @return int
3985 */
3986 function wpsc_get_minimum_preload_interval() {
3987 return apply_filters( 'wpsc_minimum_preload_interval', 10 );
3988 }
3989
3990 function wpsc_preload_settings() {
3991 global $wp_cache_preload_interval, $wp_cache_preload_on, $wp_cache_preload_taxonomies, $wp_cache_preload_email_me, $wp_cache_preload_email_volume, $wp_cache_preload_posts, $wpdb;
3992
3993 if ( isset( $_POST[ 'action' ] ) == false || $_POST[ 'action' ] != 'preload' )
3994 return;
3995
3996 if ( isset( $_POST[ 'preload_off' ] ) ) {
3997 wpsc_cancel_preload();
3998 return;
3999 } elseif ( isset( $_POST[ 'preload_now' ] ) ) {
4000 wpsc_enable_preload();
4001 wpsc_update_idle_preload();
4002 ?>
4003 <div class="notice notice-warning">
4004 <h4><?php esc_html_e( 'Preload has been activated', 'wp-super-cache' ); ?></h4>
4005 </div>
4006 <?php
4007 return;
4008 }
4009
4010 $min_refresh_interval = wpsc_get_minimum_preload_interval();
4011
4012 // Set to true if the preload interval is changed, and a reschedule is required.
4013 $force_preload_reschedule = false;
4014
4015 if ( isset( $_POST[ 'wp_cache_preload_interval' ] ) && ( $_POST[ 'wp_cache_preload_interval' ] == 0 || $_POST[ 'wp_cache_preload_interval' ] >= $min_refresh_interval ) ) {
4016 $_POST[ 'wp_cache_preload_interval' ] = (int)$_POST[ 'wp_cache_preload_interval' ];
4017 if ( $wp_cache_preload_interval != $_POST[ 'wp_cache_preload_interval' ] ) {
4018 $force_preload_reschedule = true;
4019 }
4020
4021 // phpcs:ignore WordPress.Security.NonceVerification.Missing
4022 $wp_cache_preload_interval = (int) $_POST['wp_cache_preload_interval'];
4023 wp_cache_setting( 'wp_cache_preload_interval', $wp_cache_preload_interval );
4024 }
4025
4026 if ( $_POST[ 'wp_cache_preload_posts' ] == 'all' ) {
4027 $wp_cache_preload_posts = 'all';
4028 } else {
4029 $wp_cache_preload_posts = (int)$_POST[ 'wp_cache_preload_posts' ];
4030 }
4031 wp_cache_setting( 'wp_cache_preload_posts', $wp_cache_preload_posts );
4032
4033 if ( isset( $_POST[ 'wp_cache_preload_email_volume' ] ) && in_array( $_POST[ 'wp_cache_preload_email_volume' ], array( 'none', 'less', 'medium', 'many' ) ) ) {
4034 $wp_cache_preload_email_volume = $_POST[ 'wp_cache_preload_email_volume' ];
4035 } else {
4036 $wp_cache_preload_email_volume = 'none';
4037 }
4038 wp_cache_setting( 'wp_cache_preload_email_volume', $wp_cache_preload_email_volume );
4039
4040 if ( $wp_cache_preload_email_volume == 'none' )
4041 wp_cache_setting( 'wp_cache_preload_email_me', 0 );
4042 else
4043 wp_cache_setting( 'wp_cache_preload_email_me', 1 );
4044
4045 if ( isset( $_POST[ 'wp_cache_preload_taxonomies' ] ) ) {
4046 $wp_cache_preload_taxonomies = 1;
4047 } else {
4048 $wp_cache_preload_taxonomies = 0;
4049 }
4050 wp_cache_setting( 'wp_cache_preload_taxonomies', $wp_cache_preload_taxonomies );
4051
4052 if ( isset( $_POST[ 'wp_cache_preload_on' ] ) ) {
4053 $wp_cache_preload_on = 1;
4054 } else {
4055 $wp_cache_preload_on = 0;
4056 }
4057 wp_cache_setting( 'wp_cache_preload_on', $wp_cache_preload_on );
4058
4059 // Ensure that preload settings are applied to scheduled cron.
4060 $next_preload = wp_next_scheduled( 'wp_cache_full_preload_hook' );
4061 $should_schedule = ( $wp_cache_preload_on === 1 && $wp_cache_preload_interval > 0 );
4062
4063 // If forcing a reschedule, or preload is disabled, clear the next scheduled event.
4064 if ( $next_preload && ( ! $should_schedule || $force_preload_reschedule ) ) {
4065 wp_cache_debug( 'Clearing old preload event' );
4066 wpsc_reset_preload_counter();
4067 wpsc_create_stop_preload_flag();
4068 wp_unschedule_event( $next_preload, 'wp_cache_full_preload_hook' );
4069
4070 $next_preload = 0;
4071 }
4072
4073 // Ensure a preload is scheduled if it should be.
4074 if ( ! $next_preload && $should_schedule ) {
4075 wp_cache_debug( 'Scheduling new preload event' );
4076 wp_schedule_single_event( time() + ( $wp_cache_preload_interval * 60 ), 'wp_cache_full_preload_hook' );
4077 }
4078 }
4079
4080 function wpsc_is_preloading() {
4081 if ( wp_next_scheduled( 'wp_cache_preload_hook' ) || wp_next_scheduled( 'wp_cache_full_preload_hook' ) ) {
4082 return true;
4083 } else {
4084 return false;
4085 }
4086 }
4087
4088 function wpsc_set_default_gc( $force = false ) {
4089 global $cache_path, $wp_cache_shutdown_gc, $cache_schedule_type;
4090
4091 if ( isset( $wp_cache_shutdown_gc ) && $wp_cache_shutdown_gc == 1 ) {
4092 return false;
4093 }
4094
4095 if ( $force ) {
4096 unset( $cache_schedule_type );
4097 $timestamp = wp_next_scheduled( 'wp_cache_gc' );
4098 if ( $timestamp ) {
4099 wp_unschedule_event( $timestamp, 'wp_cache_gc' );
4100 }
4101 }
4102
4103 // set up garbage collection with some default settings
4104 if ( false == isset( $cache_schedule_type ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) {
4105 $cache_schedule_type = 'interval';
4106 $cache_time_interval = 600;
4107 $cache_max_time = 1800;
4108 $cache_schedule_interval = 'hourly';
4109 $cache_gc_email_me = 0;
4110 wp_cache_setting( 'cache_schedule_type', $cache_schedule_type );
4111 wp_cache_setting( 'cache_time_interval', $cache_time_interval );
4112 wp_cache_setting( 'cache_max_time', $cache_max_time );
4113 wp_cache_setting( 'cache_schedule_interval', $cache_schedule_interval );
4114 wp_cache_setting( 'cache_gc_email_me', $cache_gc_email_me );
4115
4116 wp_schedule_single_event( time() + 600, 'wp_cache_gc' );
4117 }
4118
4119 return true;
4120 }
4121
4122 function add_mod_rewrite_rules() {
4123 return update_mod_rewrite_rules();
4124 }
4125
4126 function remove_mod_rewrite_rules() {
4127 return update_mod_rewrite_rules( false );
4128 }
4129
4130 function update_mod_rewrite_rules( $add_rules = true ) {
4131 global $cache_path, $update_mod_rewrite_rules_error;
4132
4133 $update_mod_rewrite_rules_error = false;
4134
4135 if ( defined( "DO_NOT_UPDATE_HTACCESS" ) ) {
4136 $update_mod_rewrite_rules_error = ".htaccess update disabled by admin: DO_NOT_UPDATE_HTACCESS defined";
4137 return false;
4138 }
4139
4140 if ( ! function_exists( 'get_home_path' ) ) {
4141 include_once( ABSPATH . 'wp-admin/includes/file.php' ); // get_home_path()
4142 include_once( ABSPATH . 'wp-admin/includes/misc.php' ); // extract_from_markers()
4143 }
4144 $home_path = trailingslashit( get_home_path() );
4145 $home_root = parse_url( get_bloginfo( 'url' ) );
4146 $home_root = isset( $home_root[ 'path' ] ) ? trailingslashit( $home_root[ 'path' ] ) : '/';
4147 if (
4148 $home_root == '/' &&
4149 $home_path != $_SERVER[ 'DOCUMENT_ROOT' ]
4150 ) {
4151 $home_path = $_SERVER[ 'DOCUMENT_ROOT' ];
4152 } elseif (
4153 $home_root != '/' &&
4154 $home_path != str_replace( '//', '/', $_SERVER[ 'DOCUMENT_ROOT' ] . $home_root ) &&
4155 is_dir( $_SERVER[ 'DOCUMENT_ROOT' ] . $home_root )
4156 ) {
4157 $home_path = str_replace( '//', '/', $_SERVER[ 'DOCUMENT_ROOT' ] . $home_root );
4158 }
4159 $home_path = trailingslashit( $home_path );
4160
4161 if ( ! file_exists( $home_path . ".htaccess" ) ) {
4162 $update_mod_rewrite_rules_error = ".htaccess not found: {$home_path}.htaccess";
4163 return false;
4164 }
4165
4166 $generated_rules = wpsc_get_htaccess_info();
4167 $existing_rules = implode( "\n", extract_from_markers( $home_path . '.htaccess', 'WPSuperCache' ) );
4168
4169 $rules = $add_rules ? $generated_rules[ 'rules' ] : '';
4170
4171 if ( $existing_rules == $rules ) {
4172 $update_mod_rewrite_rules_error = "rules have not changed";
4173 return true;
4174 }
4175
4176 if ( $generated_rules[ 'wprules' ] == '' ) {
4177 $update_mod_rewrite_rules_error = "WordPress rules empty";
4178 return false;
4179 }
4180
4181 if ( empty( $rules ) ) {
4182 return insert_with_markers( $home_path . '.htaccess', 'WPSuperCache', array() );
4183 }
4184
4185 $url = trailingslashit( get_bloginfo( 'url' ) );
4186 $original_page = wp_remote_get( $url, array( 'timeout' => 60, 'blocking' => true ) );
4187 if ( is_wp_error( $original_page ) ) {
4188 $update_mod_rewrite_rules_error = "Problem loading page";
4189 return false;
4190 }
4191
4192 $backup_filename = $cache_path . 'htaccess.' . mt_rand() . ".php";
4193 $backup_file_contents = file_get_contents( $home_path . '.htaccess' );
4194 file_put_contents( $backup_filename, "<" . "?php die(); ?" . ">" . $backup_file_contents );
4195 $existing_gzip_rules = implode( "\n", extract_from_markers( $cache_path . '.htaccess', 'supercache' ) );
4196 if ( $existing_gzip_rules != $generated_rules[ 'gziprules' ] ) {
4197 insert_with_markers( $cache_path . '.htaccess', 'supercache', explode( "\n", $generated_rules[ 'gziprules' ] ) );
4198 }
4199 $wprules = extract_from_markers( $home_path . '.htaccess', 'WordPress' );
4200 wpsc_remove_marker( $home_path . '.htaccess', 'WordPress' ); // remove original WP rules so SuperCache rules go on top
4201 if ( insert_with_markers( $home_path . '.htaccess', 'WPSuperCache', explode( "\n", $rules ) ) && insert_with_markers( $home_path . '.htaccess', 'WordPress', $wprules ) ) {
4202 $new_page = wp_remote_get( $url, array( 'timeout' => 60, 'blocking' => true ) );
4203 $restore_backup = false;
4204 if ( is_wp_error( $new_page ) ) {
4205 $restore_backup = true;
4206 $update_mod_rewrite_rules_error = "Error testing page with new .htaccess rules: " . $new_page->get_error_message() . ".";
4207 wp_cache_debug( 'update_mod_rewrite_rules: failed to update rules. error fetching second page: ' . $new_page->get_error_message() );
4208 } elseif ( $new_page[ 'body' ] != $original_page[ 'body' ] ) {
4209 $restore_backup = true;
4210 $update_mod_rewrite_rules_error = "Page test failed as pages did not match with new .htaccess rules.";
4211 wp_cache_debug( 'update_mod_rewrite_rules: failed to update rules. page test failed as pages did not match. Files dumped in ' . $cache_path . ' for inspection.' );
4212 wp_cache_debug( 'update_mod_rewrite_rules: original page: 1-' . md5( $original_page[ 'body' ] ) . '.txt' );
4213 wp_cache_debug( 'update_mod_rewrite_rules: new page: 1-' . md5( $new_page[ 'body' ] ) . '.txt' );
4214 file_put_contents( $cache_path . '1-' . md5( $original_page[ 'body' ] ) . '.txt', $original_page[ 'body' ] );
4215 file_put_contents( $cache_path . '2-' . md5( $new_page[ 'body' ] ) . '.txt', $new_page[ 'body' ] );
4216 }
4217
4218 if ( $restore_backup ) {
4219 global $wp_cache_debug;
4220 file_put_contents( $home_path . '.htaccess', $backup_file_contents );
4221 unlink( $backup_filename );
4222 if ( $wp_cache_debug ) {
4223 $update_mod_rewrite_rules_error .= "<br />See debug log for further details";
4224 } else {
4225 $update_mod_rewrite_rules_error .= "<br />Enable debug log on Debugging page for further details and try again";
4226 }
4227
4228 return false;
4229 }
4230 } else {
4231 file_put_contents( $home_path . '.htaccess', $backup_file_contents );
4232 unlink( $backup_filename );
4233 $update_mod_rewrite_rules_error = "problem inserting rules in .htaccess and original .htaccess restored";
4234 return false;
4235 }
4236
4237 return true;
4238 }
4239
4240 // Delete feeds when the site is updated so that feed files are always fresh
4241 function wpsc_feed_update( $type, $permalink ) {
4242 $wpsc_feed_list = get_option( 'wpsc_feed_list' );
4243
4244 update_option( 'wpsc_feed_list', array() );
4245 if ( is_array( $wpsc_feed_list ) && ! empty( $wpsc_feed_list ) ) {
4246 foreach( $wpsc_feed_list as $file ) {
4247 wp_cache_debug( "wpsc_feed_update: deleting feed: $file" );
4248 prune_super_cache( $file, true );
4249 prune_super_cache( dirname( $file ) . '/meta-' . basename( $file ), true );
4250 }
4251 }
4252 }
4253 add_action( 'gc_cache', 'wpsc_feed_update', 10, 2 );
4254
4255 function wpsc_get_plugin_list() {
4256 $list = do_cacheaction( 'wpsc_filter_list' );
4257 foreach( $list as $t => $details ) {
4258 $key = "cache_" . $details[ 'key' ];
4259 if ( isset( $GLOBALS[ $key ] ) && $GLOBALS[ $key ] == 1 ) {
4260 $list[ $t ][ 'enabled' ] = true;
4261 } else {
4262 $list[ $t ][ 'enabled' ] = false;
4263 }
4264
4265 $list[ $t ][ 'desc' ] = strip_tags( $list[ $t ][ 'desc' ] );
4266 $list[ $t ][ 'title' ] = strip_tags( $list[ $t ][ 'title' ] );
4267 }
4268 return $list;
4269 }
4270
4271 function wpsc_update_plugin_list( $update ) {
4272 $list = do_cacheaction( 'wpsc_filter_list' );
4273 foreach( $update as $key => $enabled ) {
4274 $plugin_toggle = "cache_{$key}";
4275 if ( isset( $GLOBALS[ $plugin_toggle ] ) || isset( $list[ $key ] ) ) {
4276 wp_cache_setting( $plugin_toggle, (int)$enabled );
4277 }
4278 }
4279 }
4280
4281 function wpsc_add_plugin( $file ) {
4282 global $wpsc_plugins;
4283 if ( substr( $file, 0, strlen( ABSPATH ) ) == ABSPATH ) {
4284 $file = substr( $file, strlen( ABSPATH ) ); // remove ABSPATH
4285 }
4286 if (
4287 ! isset( $wpsc_plugins ) ||
4288 ! is_array( $wpsc_plugins ) ||
4289 ! in_array( $file, $wpsc_plugins )
4290 ) {
4291 $wpsc_plugins[] = $file;
4292 wp_cache_setting( 'wpsc_plugins', $wpsc_plugins );
4293 }
4294 return $file;
4295 }
4296 add_action( 'wpsc_add_plugin', 'wpsc_add_plugin' );
4297
4298 function wpsc_delete_plugin( $file ) {
4299 global $wpsc_plugins;
4300 if ( substr( $file, 0, strlen( ABSPATH ) ) == ABSPATH ) {
4301 $file = substr( $file, strlen( ABSPATH ) ); // remove ABSPATH
4302 }
4303 if (
4304 isset( $wpsc_plugins ) &&
4305 is_array( $wpsc_plugins ) &&
4306 in_array( $file, $wpsc_plugins )
4307 ) {
4308 unset( $wpsc_plugins[ array_search( $file, $wpsc_plugins ) ] );
4309 wp_cache_setting( 'wpsc_plugins', $wpsc_plugins );
4310 }
4311 return $file;
4312 }
4313 add_action( 'wpsc_delete_plugin', 'wpsc_delete_plugin' );
4314
4315 function wpsc_get_plugins() {
4316 global $wpsc_plugins;
4317 return $wpsc_plugins;
4318 }
4319
4320 function wpsc_add_cookie( $name ) {
4321 global $wpsc_cookies;
4322 if (
4323 ! isset( $wpsc_cookies ) ||
4324 ! is_array( $wpsc_cookies ) ||
4325 ! in_array( $name, $wpsc_cookies )
4326 ) {
4327 $wpsc_cookies[] = $name;
4328 wp_cache_setting( 'wpsc_cookies', $wpsc_cookies );
4329 }
4330 return $name;
4331 }
4332 add_action( 'wpsc_add_cookie', 'wpsc_add_cookie' );
4333
4334 function wpsc_delete_cookie( $name ) {
4335 global $wpsc_cookies;
4336 if (
4337 isset( $wpsc_cookies ) &&
4338 is_array( $wpsc_cookies ) &&
4339 in_array( $name, $wpsc_cookies )
4340 ) {
4341 unset( $wpsc_cookies[ array_search( $name, $wpsc_cookies ) ] );
4342 wp_cache_setting( 'wpsc_cookies', $wpsc_cookies );
4343 }
4344 return $name;
4345 }
4346 add_action( 'wpsc_delete_cookie', 'wpsc_delete_cookie' );
4347
4348 function wpsc_get_cookies() {
4349 global $wpsc_cookies;
4350 return $wpsc_cookies;
4351 }
4352
4353 function wpsc_get_extra_cookies() {
4354 global $wpsc_cookies;
4355 if (
4356 is_array( $wpsc_cookies ) &&
4357 ! empty( $wpsc_cookies )
4358 ) {
4359 return '|' . implode( '|', $wpsc_cookies );
4360 } else {
4361 return '';
4362 }
4363 }
4364
4365 function wpsc_update_check() {
4366 global $wpsc_version;
4367
4368 if (
4369 ! isset( $wpsc_version ) ||
4370 $wpsc_version != 169
4371 ) {
4372 wp_cache_setting( 'wpsc_version', 169 );
4373 global $wp_cache_debug_log, $cache_path;
4374 $log_file = $cache_path . str_replace('/', '', str_replace('..', '', $wp_cache_debug_log));
4375 if ( ! file_exists( $log_file ) ) {
4376 return false;
4377 }
4378 @unlink( $log_file );
4379 wp_cache_debug( 'wpsc_update_check: Deleted old log file on plugin update.' );
4380 }
4381 }
4382 add_action( 'admin_init', 'wpsc_update_check' );
4383
4384 /**
4385 * Renders a partial/template.
4386 *
4387 * The global $current_user is made available for any rendered template.
4388 *
4389 * @param string $partial - Filename under ./partials directory, with or without .php (appended if absent).
4390 * @param array $page_vars - Variables made available for the template.
4391 */
4392 function wpsc_render_partial( $partial, array $page_vars = array() ) {
4393 if ( ! str_ends_with( $partial, '.php' ) ) {
4394 $partial .= '.php';
4395 }
4396
4397 if ( strpos( $partial, 'partials/' ) !== 0 ) {
4398 $partial = 'partials/' . $partial;
4399 }
4400
4401 $path = __DIR__ . '/' . $partial;
4402 if ( ! file_exists( $path ) ) {
4403 return;
4404 }
4405
4406 foreach ( $page_vars as $key => $val ) {
4407 $$key = $val;
4408 }
4409 global $current_user;
4410 include $path;
4411 }
4412
4413 /**
4414 * Render common header
4415 */
4416 function wpsc_render_header() {
4417 ?>
4418 <div class="header">
4419 <img class="wpsc-icon" src="<?php echo esc_url( plugin_dir_url( __FILE__ ) . '/assets/super-cache-icon.png' ); ?>" />
4420 <span class="wpsc-name"><?php echo esc_html( 'WP Super Cache' ); ?></span>
4421 </div>
4422 <?php
4423 }
4424
4425 /**
4426 * Render common footer
4427 */
4428 function wpsc_render_footer() {
4429 ?>
4430 <div class="footer">
4431 <div class="wp-super-cache-version">
4432 <img class="wpsc-icon" src="<?php echo esc_url( plugin_dir_url( __FILE__ ) . '/assets/super-cache-icon.png' ); ?>" />
4433 <span class="wpsc-name"><?php echo esc_html( 'WP Super Cache' ); ?></span>
4434 </div>
4435 <div class="automattic-airline">
4436 <img class="wpsc-icon" src="<?php echo esc_url( plugin_dir_url( __FILE__ ) . '/assets/automattic-airline.svg' ); ?>" />
4437 </div>
4438 </div>
4439 <?php
4440 }
4441