" . sprintf( __( "Directly cached files are files created directly off %s where your blog lives. This feature is only useful if you are expecting a major Digg or Slashdot level of traffic to one post or page.", 'wp-super-cache' ), ABSPATH ) . "
";
if( $readonly != 'READONLY' ) {
echo "" . sprintf( __( 'For example: to cache %1$sabout/ , you would enter %1$sabout/ or /about/. The cached file will be generated the next time an anonymous user visits that page.', 'wp-super-cache' ), trailingslashit( get_option( 'siteurl' ) ) ) . "
";
echo "" . __( 'Make the textbox blank to remove it from the list of direct pages and delete the cached file.', 'wp-super-cache' ) . "
";
}
wp_nonce_field('wp-cache');
if( $readonly != 'READONLY' )
echo "' . __( 'Warning', 'wp-super-cache' ) . "! " . sprintf( __( 'Could not update %s! WPCACHEHOME must be set in config file.', 'wp-super-cache' ), $global_config_file ) . " ";
return false;
}
$ret = true;
$file = file_get_contents( $wp_cache_file );
$fp = @fopen( $wp_cache_link, 'w' );
if( $fp ) {
fputs( $fp, $file );
fclose( $fp );
} else {
$ret = false;
}
return $ret;
}
function wp_cache_check_link() {
global $wp_cache_link, $wp_cache_file;
$ret = true;
if( file_exists($wp_cache_link) ) {
$file = file_get_contents( $wp_cache_link );
if( strpos( $file, "WP SUPER CACHE 0.8.9.1" ) || strpos( $file, "WP SUPER CACHE 1.2" ) ) {
return true;
} else {
if( !@unlink($wp_cache_link) ) {
$ret = false;
} else {
$ret = wp_cache_create_advanced_cache();
}
}
} else {
$ret = wp_cache_create_advanced_cache();
}
if( false == $ret ) {
echo '
' . __( 'Warning', 'wp-super-cache' ) . "! " . sprintf( __( '%s/advanced-cache.php does not exist or cannot be updated.', 'wp-super-cache' ), WP_CONTENT_DIR ) . " ";
echo "
" . __( '1. If it already exists, please delete the file first.', 'wp-super-cache' ) . " ";
echo "" . sprintf( __( '2. Make %1$s writable using the chmod command through your ftp or server software. (chmod 777 %1$s ) and refresh this page. This is only a temporary measure and you’ll have to make it read only afterwards again. (Change 777 to 755 in the previous command)', 'wp-super-cache' ), WP_CONTENT_DIR ) . " ";
echo "" . sprintf( __( '3. Refresh this page to update %s/advanced-cache.php ', 'wp-super-cache' ), WP_CONTENT_DIR ) . " ";
echo sprintf( __( 'If that doesn’t work, make sure the file
%s/advanced-cache.php doesn’t exist:', 'wp-super-cache' ), WP_CONTENT_DIR ) . "
";
printf( __( '1. Open %1$s$wp_cache_file in a text editor. 2. Change the text CACHEHOME to %2$s 3. Save the file and copy it to %3$s and refresh this page. ', 'wp-super-cache' ), $wp_cache_file, WPCACHEHOME, $wp_cache_link );
echo " ";
return false;
}
return true;
}
function wp_cache_check_global_config() {
global $wp_cache_check_wp_config;
if ( !isset( $wp_cache_check_wp_config ) )
return true;
if ( file_exists( ABSPATH . 'wp-config.php') ) {
$global = ABSPATH . 'wp-config.php';
} else {
$global = dirname(ABSPATH) . '/wp-config.php';
}
$line = 'define(\'WP_CACHE\', true);';
if (!is_writeable_ACLSafe($global) || !wp_cache_replace_line('define *\( *\'WP_CACHE\'', $line, $global) ) {
if ( defined( 'WP_CACHE' ) && constant( 'WP_CACHE' ) == false ) {
echo '
' . __( "
WP_CACHE constant set to false 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:define('WP_CACHE', true);
", 'wp-super-cache' ) . "
";
} else {
echo "
" . __( "Error: WP_CACHE is not enabled in your wp-config.php file and I couldn’t modify it.", 'wp-super-cache' ) . "
";;
echo "
" . sprintf( __( "Edit %s and add the following line: define('WP_CACHE', true); Otherwise, WP-Cache will not be executed by WordPress core. ", 'wp-super-cache' ), $global ) . "
";
}
return false;
} else {
echo "
" . __( '
WP_CACHE constant added to wp-config.php If you continue to see this warning message please see point 5 of the Troubleshooting Guide . The WP_CACHE line must be moved up.', 'wp-super-cache' ) . "
";
}
return true;
}
function wp_cache_files() {
global $cache_path, $file_prefix, $cache_max_time, $valid_nonce, $supercachedir, $cache_enabled, $super_cache_enabled, $blog_cache_dir, $cache_compression;
global $wp_cache_object_cache, $wp_cache_preload_on;
if ( '/' != substr($cache_path, -1)) {
$cache_path .= '/';
}
if ( $valid_nonce ) {
if(isset($_REQUEST['wp_delete_cache'])) {
wp_cache_clean_cache($file_prefix);
$_GET[ 'action' ] = 'regenerate_cache_stats';
}
if ( isset( $_REQUEST[ 'wp_delete_all_cache' ] ) ) {
wp_cache_clean_cache( $file_prefix, true );
$_GET[ 'action' ] = 'regenerate_cache_stats';
}
if(isset($_REQUEST['wp_delete_expired'])) {
wp_cache_clean_expired($file_prefix);
$_GET[ 'action' ] = 'regenerate_cache_stats';
}
}
echo "
";
echo '
' . __( 'Cache Contents', 'wp-super-cache' ) . ' ';
if ( $wp_cache_object_cache ) {
echo "" . __( "Object cache in use. No cache listing available.", 'wp-super-cache' ) . "
";
wp_cache_delete_buttons();
echo "";
return false;
}
$cache_stats = get_option( 'supercache_stats' );
if ( !is_array( $cache_stats ) || ( isset( $_GET[ 'listfiles' ] ) ) || ( $valid_nonce && array_key_exists('action', $_GET) && $_GET[ 'action' ] == 'regenerate_cache_stats' ) ) {
$list_files = false; // it doesn't list supercached files, and removing single pages is buggy
$count = 0;
$expired = 0;
$now = time();
if ( ( $handle = @opendir( $blog_cache_dir ) ) ) {
$wp_cache_fsize = 0;
if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletewpcache' ) {
$deleteuri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', base64_decode( $_GET[ 'uri' ] ) ) );
} else {
$deleteuri = '';
}
if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deletesupercache' ) {
$supercacheuri = wpsc_deep_replace( array( '..', '\\', 'index.php' ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', preg_replace("/(\?.*)?$/", '', base64_decode( $_GET[ 'uri' ] ) ) ) );
$supercacheuri = trailingslashit( realpath( $cache_path . 'supercache/' . $supercacheuri ) );
if ( wp_cache_confirm_delete( $supercacheuri ) ) {
printf( __( "Deleting supercache file:
%s ", 'wp-super-cache' ), $supercacheuri );
@unlink( $supercacheuri . 'index.html' );
@unlink( $supercacheuri . 'index.html.gz' );
prune_super_cache( $supercacheuri . 'page', true );
@rmdir( $supercacheuri );
}
}
while( false !== ( $file = readdir( $handle ) ) ) {
if ( strpos( $file, $file_prefix ) !== false && substr( $file, -4 ) == '.php' ) {
if ( false == file_exists( $blog_cache_dir . 'meta/' . $file ) ) {
@unlink( $blog_cache_dir . $file );
continue; // meta does not exist
}
$mtime = filemtime( $blog_cache_dir . 'meta/' . $file );
$fsize = @filesize( $blog_cache_dir . $file );
if ( $fsize > 0 )
$fsize = $fsize - 15; // die() command takes 15 bytes at the start of the file
$age = $now - $mtime;
if ( $valid_nonce && isset( $_GET[ 'listfiles' ] ) ) {
$meta = json_decode( wp_cache_get_legacy_cache( $blog_cache_dir . 'meta/' . $file ), true );
if ( $deleteuri != '' && $meta[ 'uri' ] == $deleteuri ) {
printf( __( "Deleting wp-cache file:
%s ", 'wp-super-cache' ), esc_html( $deleteuri ) );
@unlink( $blog_cache_dir . 'meta/' . $file );
@unlink( $blog_cache_dir . $file );
continue;
}
$meta[ 'age' ] = $age;
foreach( $meta as $key => $val )
$meta[ $key ] = esc_html( $val );
if ( $cache_max_time > 0 && $age > $cache_max_time ) {
$expired_list[ $age ][] = $meta;
} else {
$cached_list[ $age ][] = $meta;
}
}
if ( $cache_max_time > 0 && $age > $cache_max_time ) {
$expired++;
} else {
$count++;
}
$wp_cache_fsize += $fsize;
$fsize = intval($fsize/1024);
}
}
closedir($handle);
}
if( $wp_cache_fsize != 0 ) {
$wp_cache_fsize = $wp_cache_fsize/1024;
} else {
$wp_cache_fsize = 0;
}
if( $wp_cache_fsize > 1024 ) {
$wp_cache_fsize = number_format( $wp_cache_fsize / 1024, 2 ) . "MB";
} elseif( $wp_cache_fsize != 0 ) {
$wp_cache_fsize = number_format( $wp_cache_fsize, 2 ) . "KB";
} else {
$wp_cache_fsize = '0KB';
}
// Supercache files
$now = time();
$sizes = array( 'expired' => 0, 'expired_list' => array(), 'cached' => 0, 'cached_list' => array(), 'ts' => 0 );
if (is_dir($supercachedir)) {
if( $dh = opendir( $supercachedir ) ) {
while( ( $entry = readdir( $dh ) ) !== false ) {
if ($entry != '.' && $entry != '..') {
$sizes = wpsc_dirsize( trailingslashit( $supercachedir ) . $entry, $sizes );
}
}
closedir($dh);
}
} else {
$filem = @filemtime( $supercachedir );
if ( false == $wp_cache_preload_on && is_file( $supercachedir ) && $cache_max_time > 0 && $filem + $cache_max_time <= $now ) {
$sizes[ 'expired' ] ++;
if ( $valid_nonce && isset( $_GET[ 'listfiles' ] ) )
$sizes[ 'expired_list' ][ str_replace( $cache_path . 'supercache/' , '', $supercachedir ) ] = $now - $filem;
} else {
if ( $valid_nonce && isset( $_GET[ 'listfiles' ] ) && $filem )
$sizes[ 'cached_list' ][ str_replace( $cache_path . 'supercache/' , '', $supercachedir ) ] = $now - $filem;
}
}
$sizes[ 'ts' ] = time();
$cache_stats = array( 'generated' => time(), 'supercache' => $sizes, 'wpcache' => array( 'cached' => $count, 'expired' => $expired, 'fsize' => $wp_cache_fsize ) );
update_option( 'supercache_stats', $cache_stats );
} else {
echo "
" . __( 'Cache stats are not automatically generated. You must click the link below to regenerate the stats on this page.', 'wp-super-cache' ) . "
";
echo "
'wpsupercache', 'tab' => 'contents', 'action' => 'regenerate_cache_stats' ) ), 'wp-cache' ) . "'>" . __( 'Regenerate cache stats', 'wp-super-cache' ) . " ";
if ( is_array( $cache_stats ) ) {
echo "
" . sprintf( __( 'Cache stats last generated: %s minutes ago.', 'wp-super-cache' ), number_format( ( time() - $cache_stats[ 'generated' ] ) / 60 ) ) . "
";
}
$cache_stats = get_option( 'supercache_stats' );
}// regerate stats cache
if ( is_array( $cache_stats ) ) {
echo "
" . __( 'WP-Cache', 'wp-super-cache' ) . " ({$cache_stats[ 'wpcache' ][ 'fsize' ]})
";
echo "
" . sprintf( __( '%s Cached Pages', 'wp-super-cache' ), $cache_stats[ 'wpcache' ][ 'cached' ] ) . " ";
echo "" . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), $cache_stats[ 'wpcache' ][ 'expired' ] ) . " ";
$divisor = $cache_compression == 1 ? 2 : 1;
if ( array_key_exists('fsize', (array)$cache_stats[ 'supercache' ]) )
$fsize = $cache_stats[ 'supercache' ][ 'fsize' ] / 1024;
else
$fsize = 0;
if( $fsize > 1024 ) {
$fsize = number_format( $fsize / 1024, 2 ) . "MB";
} elseif( $fsize != 0 ) {
$fsize = number_format( $fsize, 2 ) . "KB";
} else {
$fsize = "0KB";
}
echo "
" . __( 'WP-Super-Cache', 'wp-super-cache' ) . " ({$fsize})
";
echo "
" . sprintf( __( '%s Cached Pages', 'wp-super-cache' ), intval( $cache_stats[ 'supercache' ][ 'cached' ] / $divisor ) ) . " ";
if (isset($now) && isset($sizes))
$age = intval(($now - $sizes['ts'])/60);
else
$age = 0;
echo "" . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), intval( $cache_stats[ 'supercache' ][ 'expired' ] / $divisor ) ) . " ";
if ( $valid_nonce && array_key_exists('listfiles', $_GET) && $_GET[ 'listfiles' ] ) {
echo "
";
if ( isset( $cached_list ) && is_array( $cached_list ) && !empty( $cached_list ) ) {
echo "
" . __( 'Fresh WP-Cached Files', 'wp-super-cache' ) . " ";
echo "
";
}
if ( isset( $expired_list ) && is_array( $expired_list ) && !empty( $expired_list ) ) {
echo "
" . __( 'Stale WP-Cached Files', 'wp-super-cache' ) . " ";
echo "
";
}
if ( is_array( $sizes[ 'cached_list' ] ) & !empty( $sizes[ 'cached_list' ] ) ) {
echo "
" . __( 'Fresh Super Cached Files', 'wp-super-cache' ) . " ";
echo "
";
}
if ( is_array( $sizes[ 'expired_list' ] ) && !empty( $sizes[ 'expired_list' ] ) ) {
echo "
" . __( 'Stale Super Cached Files', 'wp-super-cache' ) . " ";
echo "
";
}
echo "
";
echo "
" . __( 'Hide file list', 'wp-super-cache' ) . "
";
} elseif ( $cache_stats[ 'supercache' ][ 'cached' ] > 500 || $cache_stats[ 'supercache' ][ 'expired' ] > 500 || ( $cache_stats[ 'wpcache' ][ 'cached' ] / $divisor ) > 500 || ( $cache_stats[ 'wpcache' ][ 'expired' ] / $divisor) > 500 ) {
echo "
" . __( 'Too many cached files, no listing possible.', 'wp-super-cache' ) . "
";
} else {
echo "
'wpsupercache', 'listfiles' => '1' ) ), 'wp-cache' ) . "#listfiles'>" . __( 'List all cached files', 'wp-super-cache' ) . "
";
}
if ( $cache_max_time > 0 )
echo "
" . 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 ) . "
";
} // cache_stats
wp_cache_delete_buttons();
echo '';
}
function wp_cache_delete_buttons() {
echo '
\n";
echo '
\n";
if ( ( defined( 'VHOST' ) || defined( 'SUBDOMAIN_INSTALL' ) || defined( 'SUNRISE' ) || ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) ) && wpsupercache_site_admin() ) {
echo '
\n";
}
}
function delete_cache_dashboard() {
if ( false == wpsupercache_site_admin() )
return false;
if ( function_exists('current_user_can') && !current_user_can('manage_options') )
return false;
echo "
" . __( 'Delete Cache', 'wp-super-cache' ) . " ";
}
add_action( 'dashmenu', 'delete_cache_dashboard' );
function wpsc_dirsize($directory, $sizes) {
global $cache_max_time, $cache_path, $valid_nonce, $wp_cache_preload_on;
$now = time();
if (is_dir($directory)) {
if( $dh = opendir( $directory ) ) {
while( ( $entry = readdir( $dh ) ) !== false ) {
if ($entry != '.' && $entry != '..') {
$sizes = wpsc_dirsize( trailingslashit( $directory ) . $entry, $sizes );
}
}
closedir($dh);
}
} else {
if(is_file($directory) ) {
$filem = filemtime( $directory );
if ( $wp_cache_preload_on == false && $cache_max_time > 0 && $filem + $cache_max_time <= $now ) {
$sizes[ 'expired' ]+=1;
if ( $valid_nonce && $_GET[ 'listfiles' ] )
$sizes[ 'expired_list' ][ $now - $filem ][ str_replace( $cache_path . 'supercache/' , '', str_replace( 'index.html', '', str_replace( 'index.html.gz', '', $directory ) ) ) ] = 1;
} else {
$sizes[ 'cached' ]+=1;
if ( $valid_nonce && array_key_exists('listfiles', $_GET) && $_GET[ 'listfiles' ] )
$sizes[ 'cached_list' ][ $now - $filem ][ str_replace( $cache_path . 'supercache/' , '', str_replace( 'index.html', '', str_replace( 'index.html.gz', '', $directory ) ) ) ] = 1;
}
if ( ! isset( $sizes[ 'fsize' ] ) )
$sizes[ 'fsize' ] = @filesize( $directory );
else
$sizes[ 'fsize' ] += @filesize( $directory );
}
}
return $sizes;
}
function wp_cache_clean_cache( $file_prefix, $all = false ) {
global $wpdb, $cache_path, $supercachedir, $blog_cache_dir, $wp_cache_object_cache;
if ( $wp_cache_object_cache && function_exists( "reset_oc_version" ) )
reset_oc_version();
if ( $all == true && wpsupercache_site_admin() && function_exists( 'prune_super_cache' ) ) {
prune_super_cache( $cache_path, true );
return true;
}
if (function_exists ('prune_super_cache')) {
if( is_dir( $supercachedir ) ) {
prune_super_cache( $supercachedir, true );
} elseif( is_dir( $supercachedir . '.disabled' ) ) {
prune_super_cache( $supercachedir . '.disabled', true );
}
$_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
} else {
wp_cache_debug( 'Warning! prune_super_cache() not found in wp-cache.php', 1 );
}
wp_cache_clean_legacy_files( $blog_cache_dir, $file_prefix );
wp_cache_clean_legacy_files( $cache_path, $file_prefix );
}
function wp_cache_clean_legacy_files( $dir, $file_prefix ) {
global $wpdb;
$dir = trailingslashit( $dir );
if ( @is_dir( $dir . 'meta' ) == false )
return false;
if ( $handle = @opendir( $dir ) ) {
while ( false !== ( $file = readdir( $handle ) ) ) {
if ( is_file( $dir . $file ) == false || $file == 'index.html' ) {
continue;
}
if ( strpos( $file, $file_prefix ) !== false ) {
if ( strpos( $file, '.html' ) ) {
// delete old legacy files immediately
@unlink( $dir . $file);
@unlink( $dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
} else {
$meta = json_decode( wp_cache_get_legacy_cache( $dir . 'meta/' . $file ), true );
if ( ( defined( 'VHOST' ) || defined( 'SUBDOMAIN_INSTALL' ) || defined( 'SUNRISE' ) || ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) ) && $meta[ 'blog_id' ] != $wpdb->blogid )
continue;
@unlink( $dir . $file);
@unlink( $dir . 'meta/' . $file);
}
}
}
closedir($handle);
}
}
function wp_cache_clean_expired($file_prefix) {
global $cache_path, $cache_max_time, $blog_cache_dir, $wp_cache_preload_on;
if ( $cache_max_time == 0 ) {
return false;
}
// If phase2 was compiled, use its function to avoid race-conditions
if(function_exists('wp_cache_phase2_clean_expired')) {
if ( $wp_cache_preload_on != 1 && function_exists ('prune_super_cache')) {
$dir = get_supercache_dir();
if( is_dir( $dir ) ) {
prune_super_cache( $dir );
} elseif( is_dir( $dir . '.disabled' ) ) {
prune_super_cache( $dir . '.disabled' );
}
$_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
}
return wp_cache_phase2_clean_expired($file_prefix);
}
$now = time();
if ( $handle = @opendir( $blog_cache_dir ) ) {
while ( false !== ( $file = readdir( $handle ) ) ) {
if ( strpos( $file, $file_prefix ) !== false ) {
if ( strpos( $file, '.html' ) ) {
@unlink( $blog_cache_dir . $file);
@unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) );
} elseif ( ( filemtime( $blog_cache_dir . $file ) + $cache_max_time ) <= $now ) {
@unlink( $blog_cache_dir . $file );
@unlink( $blog_cache_dir . 'meta/' . $file );
}
}
}
closedir($handle);
}
}
function wpsc_remove_marker( $filename, $marker ) {
if (!file_exists( $filename ) || is_writeable_ACLSafe( $filename ) ) {
if (!file_exists( $filename ) ) {
return '';
} else {
$markerdata = explode( "\n", implode( '', file( $filename ) ) );
}
$f = fopen( $filename, 'w' );
$foundit = false;
if ( $markerdata ) {
$state = true;
foreach ( $markerdata as $n => $markerline ) {
if (strpos($markerline, '# BEGIN ' . $marker) !== false)
$state = false;
if ( $state ) {
if ( $n + 1 < count( $markerdata ) )
fwrite( $f, "{$markerline}\n" );
else
fwrite( $f, "{$markerline}" );
}
if (strpos($markerline, '# END ' . $marker) !== false) {
$state = true;
}
}
}
return true;
} else {
return false;
}
}
function wp_super_cache_footer() {
?>
WP Super Cache' ); ?>
is_404
function wp_cache_catch_404() {
global $wp_cache_404;
$wp_cache_404 = false;
if( is_404() )
$wp_cache_404 = true;
}
add_action( 'template_redirect', 'wp_cache_catch_404' );
function wp_cache_favorite_action( $actions ) {
if ( false == wpsupercache_site_admin() )
return $actions;
if ( function_exists('current_user_can') && !current_user_can('manage_options') )
return $actions;
$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' );
return $actions;
}
add_filter( 'favorite_actions', 'wp_cache_favorite_action' );
function wp_cache_plugin_notice( $plugin ) {
global $cache_enabled;
if( $plugin == 'wp-super-cache/wp-cache.php' && !$cache_enabled && function_exists( "admin_url" ) )
echo '
' . sprintf( __( 'WP Super Cache must be configured. Go to the admin page to enable and configure the plugin.' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . ' ';
}
add_action( 'after_plugin_row', 'wp_cache_plugin_notice' );
function wp_cache_plugin_actions( $links, $file ) {
if( $file == 'wp-super-cache/wp-cache.php' && function_exists( "admin_url" ) ) {
$settings_link = '
' . __('Settings') . ' ';
array_unshift( $links, $settings_link ); // before other links
}
return $links;
}
add_filter( 'plugin_action_links', 'wp_cache_plugin_actions', 10, 2 );
function wp_cache_admin_notice() {
global $cache_enabled, $wp_cache_phase1_loaded;
if( substr( $_SERVER["PHP_SELF"], -11 ) == 'plugins.php' && !$cache_enabled && function_exists( "admin_url" ) )
echo '
' . sprintf( __('WP Super Cache is disabled. Please go to the plugin admin page to enable caching.', 'wp-super-cache' ), admin_url( 'options-general.php?page=wpsupercache' ) ) . '
';
if ( defined( 'WP_CACHE' ) && WP_CACHE == true && ( defined( 'ADVANCEDCACHEPROBLEM' ) || ( $cache_enabled && false == isset( $wp_cache_phase1_loaded ) ) ) ) {
echo '
' . sprintf( __( 'Warning! WP Super Cache caching was broken but has been fixed ! The script advanced-cache.php could not load wp-cache-phase1.php. 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 ) . '
';
wp_cache_create_advanced_cache();
}
}
add_action( 'admin_notices', 'wp_cache_admin_notice' );
function wp_cache_check_site() {
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;
if ( !isset( $wp_super_cache_front_page_check ) || ( isset( $wp_super_cache_front_page_check ) && $wp_super_cache_front_page_check == 0 ) ) {
return false;
}
if ( function_exists( "wp_remote_get" ) == false ) {
return false;
}
$front_page = wp_remote_get( site_url(), array('timeout' => 60, 'blocking' => true ) );
if( is_array( $front_page ) ) {
// Check for gzipped front page
if ( $front_page[ 'headers' ][ 'content-type' ] == 'application/x-gzip' ) {
if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) {
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' ) ) );
} else {
wp_cache_clear_cache( $wpdb->blogid );
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' ) ) );
}
}
// Check for broken front page
if ( isset( $wp_super_cache_front_page_text ) && $wp_super_cache_front_page_text != '' && false === strpos( $front_page[ 'body' ], $wp_super_cache_front_page_text ) ) {
if ( !isset( $wp_super_cache_front_page_clear ) || ( isset( $wp_super_cache_front_page_clear ) && $wp_super_cache_front_page_clear == 0 ) ) {
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 ) );
} else {
wp_cache_clear_cache( $wpdb->blogid );
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 ) );
}
}
}
if ( isset( $wp_super_cache_front_page_notification ) && $wp_super_cache_front_page_notification == 1 ) {
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' ) ) );
}
if ( !wp_next_scheduled( 'wp_cache_check_site_hook' ) ) {
wp_schedule_single_event( time() + 360 , 'wp_cache_check_site_hook' );
wp_cache_debug( 'scheduled wp_cache_check_site_hook for 360 seconds time.', 2 );
}
}
add_action( 'wp_cache_check_site_hook', 'wp_cache_check_site' );
function update_cached_mobile_ua_list( $mobile_browsers, $mobile_prefixes = 0, $mobile_groups = 0 ) {
global $wp_cache_config_file, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $wp_cache_mobile_groups;
if ( is_array( $mobile_browsers ) ) {
$wp_cache_mobile_browsers = $mobile_browsers;
wp_cache_replace_line('^ *\$wp_cache_mobile_browsers', "\$wp_cache_mobile_browsers = '" . implode( ', ', $mobile_browsers ) . "';", $wp_cache_config_file);
}
if ( is_array( $mobile_prefixes ) ) {
$wp_cache_mobile_prefixes = $mobile_prefixes;
wp_cache_replace_line('^ *\$wp_cache_mobile_prefixes', "\$wp_cache_mobile_prefixes = '" . implode( ', ', $mobile_prefixes ) . "';", $wp_cache_config_file);
}
if ( is_array( $mobile_groups ) ) {
$wp_cache_mobile_groups = $mobile_groups;
wp_cache_replace_line('^ *\$wp_cache_mobile_groups', "\$wp_cache_mobile_groups = '" . implode( ', ', $mobile_groups ) . "';", $wp_cache_config_file);
}
return true;
}
function wpsc_update_htaccess() {
extract( wpsc_get_htaccess_info() );
wpsc_remove_marker( $home_path.'.htaccess', 'WordPress' ); // remove original WP rules so SuperCache rules go on top
if( insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', explode( "\n", $rules ) ) && insert_with_markers( $home_path.'.htaccess', 'WordPress', explode( "\n", $wprules ) ) ) {
return true;
} else {
return false;
}
}
function wpsc_update_htaccess_form( $short_form = true ) {
global $wpmu_version;
extract( wpsc_get_htaccess_info() );
if( !is_writeable_ACLSafe( $home_path . ".htaccess" ) ) {
echo "
" . __( 'Cannot update .htaccess', 'wp-super-cache' ) . " " . sprintf( __( 'The file %s.htaccess cannot be modified by the web server. Please correct this using the chmod command or your ftp client.', 'wp-super-cache' ), $home_path ) . "
" . __( 'Refresh this page when the file permissions have been modified.' ) . "
" . sprintf( __( 'Alternatively, you can edit your %s.htaccess file manually and add the following code (before any WordPress rules):', 'wp-super-cache' ), $home_path ) . "
";
echo "
# BEGIN WPSuperCache\n" . esc_html( $rules ) . "# END WPSuperCache ";
} else {
if ( $short_form == false ) {
echo "
" . sprintf( __( 'To serve static html files your server must have the correct mod_rewrite rules added to a file called %s.htaccess', 'wp-super-cache' ), $home_path ) . " ";
_e( "You can edit the file yourself. Add the following rules.", 'wp-super-cache' );
echo __( " Make sure they appear before any existing WordPress rules. ", 'wp-super-cache' ) . "
";
echo "
# BEGIN WPSuperCache\n" . esc_html( $rules ) . "# END WPSuperCache ";
echo "
" . sprintf( __( 'Rules must be added to %s too:', 'wp-super-cache' ), WP_CONTENT_DIR . "/cache/.htaccess" ) . "
";
echo "
# BEGIN supercache\n" . esc_html( $gziprules ) . "# END supercache ";
}
if ( !isset( $wpmu_version ) || $wpmu_version == '' ) {
echo '
\n";
}
}
}
/*
* Return LOGGED_IN_COOKIE if it doesn't begin with wordpress_logged_in
* to avoid having people update their .htaccess file
*/
function wpsc_get_logged_in_cookie() {
$logged_in_cookie = 'wordpress_logged_in';
if ( defined( 'LOGGED_IN_COOKIE' ) && substr( constant( 'LOGGED_IN_COOKIE' ), 0, 19 ) != 'wordpress_logged_in' )
$logged_in_cookie = constant( 'LOGGED_IN_COOKIE' );
return $logged_in_cookie;
}
function wpsc_get_htaccess_info() {
global $wp_cache_mobile_enabled, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_disable_utf8;
if ( isset( $_SERVER[ "PHP_DOCUMENT_ROOT" ] ) ) {
$document_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
$apache_root = $_SERVER[ "PHP_DOCUMENT_ROOT" ];
} else {
$document_root = $_SERVER[ "DOCUMENT_ROOT" ];
$apache_root = '%{DOCUMENT_ROOT}';
}
$content_dir_root = $document_root;
if ( strpos( $document_root, '/kunden/homepages/' ) === 0 ) {
// http://wordpress.org/support/topic/plugin-wp-super-cache-how-to-get-mod_rewrite-working-on-1and1-shared-hosting?replies=1
// On 1and1, PHP's directory structure starts with '/homepages'. The
// Apache directory structure has an extra '/kunden' before it.
// Also 1and1 does not support the %{DOCUMENT_ROOT} variable in
// .htaccess files.
// This prevents the $inst_root from being calculated correctly and
// means that the $apache_root is wrong.
//
// e.g. This is an example of how Apache and PHP see the directory
// structure on 1and1:
// Apache: /kunden/homepages/xx/dxxxxxxxx/htdocs/site1/index.html
// PHP: /homepages/xx/dxxxxxxxx/htdocs/site1/index.html
// Here we fix up the paths to make mode_rewrite work on 1and1 shared hosting.
$content_dir_root = substr( $content_dir_root, 7 );
$apache_root = $document_root;
}
$home_path = get_home_path();
$home_root = parse_url(get_bloginfo('url'));
$home_root = isset( $home_root['path'] ) ? trailingslashit( $home_root['path'] ) : '/';
$home_root_lc = str_replace( '//', '/', strtolower( $home_root ) );
$inst_root = str_replace( '//', '/', '/' . trailingslashit( str_replace( $content_dir_root, '', str_replace( '\\', '/', WP_CONTENT_DIR ) ) ) );
$wprules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WordPress' ) );
$wprules = str_replace( "RewriteEngine On\n", '', $wprules );
$wprules = str_replace( "RewriteBase $home_root\n", '', $wprules );
$scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
if( substr( get_option( 'permalink_structure' ), -1 ) == '/' ) {
$condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*[^/]$";
$condition_rules[] = "RewriteCond %{REQUEST_URI} !^.*//.*$";
}
$condition_rules[] = "RewriteCond %{REQUEST_METHOD} !POST";
$condition_rules[] = "RewriteCond %{QUERY_STRING} !.*=.*";
$condition_rules[] = "RewriteCond %{HTTP:Cookie} !^.*(comment_author_|" . wpsc_get_logged_in_cookie() . "|wp-postpass_).*$";
$condition_rules[] = "RewriteCond %{HTTP:X-Wap-Profile} !^[a-z0-9\\\"]+ [NC]";
$condition_rules[] = "RewriteCond %{HTTP:Profile} !^[a-z0-9\\\"]+ [NC]";
if ( $wp_cache_mobile_enabled ) {
if ( false == empty( $wp_cache_mobile_browsers ) )
$condition_rules[] = "RewriteCond %{HTTP_USER_AGENT} !^.*(" . addcslashes( implode( '|', $wp_cache_mobile_browsers ), ' ' ) . ").* [NC]";
if ( false == empty( $wp_cache_mobile_prefixes ) )
$condition_rules[] = "RewriteCond %{HTTP_user_agent} !^(" . addcslashes( implode( '|', $wp_cache_mobile_prefixes ), ' ' ) . ").* [NC]";
}
$condition_rules = apply_filters( 'supercacherewriteconditions', $condition_rules );
$rules = "
\n";
$rules .= "RewriteEngine On\n";
$rules .= "RewriteBase $home_root\n"; // props Chris Messina
$rules .= "#If you serve pages from behind a proxy you may want to change 'RewriteCond %{HTTPS} on' to something more sensible\n";
if ( isset( $wp_cache_disable_utf8 ) == false || $wp_cache_disable_utf8 == 0 ) {
$charset = get_option('blog_charset') == '' ? 'UTF-8' : get_option('blog_charset');
$rules .= "AddDefaultCharset {$charset}\n";
}
$rules .= "CONDITION_RULES";
$rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
$rules .= "RewriteCond %{HTTPS} on\n";
$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html.gz -f\n";
$rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html.gz\" [L]\n\n";
$rules .= "CONDITION_RULES";
$rules .= "RewriteCond %{HTTP:Accept-Encoding} gzip\n";
$rules .= "RewriteCond %{HTTPS} !on\n";
$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html.gz -f\n";
$rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html.gz\" [L]\n\n";
$rules .= "CONDITION_RULES";
$rules .= "RewriteCond %{HTTPS} on\n";
$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html -f\n";
$rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index-https.html\" [L]\n\n";
$rules .= "CONDITION_RULES";
$rules .= "RewriteCond %{HTTPS} !on\n";
$rules .= "RewriteCond {$apache_root}{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html -f\n";
$rules .= "RewriteRule ^(.*) \"{$inst_root}cache/supercache/%{SERVER_NAME}{$home_root_lc}$1/index.html\" [L]\n";
$rules .= " \n";
$rules = apply_filters( 'supercacherewriterules', $rules );
$rules = str_replace( "CONDITION_RULES", implode( "\n", $condition_rules ) . "\n", $rules );
$gziprules = "
\n \n ForceType text/html\n FileETag None\n \n AddEncoding gzip .gz\n AddType text/html .gz\n \n";
$gziprules .= "
\n SetEnvIfNoCase Request_URI \.gz$ no-gzip\n \n";
$gziprules .= "
\n Header set Vary \"Accept-Encoding, Cookie\"\n Header set Cache-Control 'max-age=3, must-revalidate'\n \n";
$gziprules .= "
\n ExpiresActive On\n ExpiresByType text/html A3\n \n";
$gziprules .= "Options -Indexes\n";
return array( "document_root" => $document_root, "apache_root" => $apache_root, "home_path" => $home_path, "home_root" => $home_root, "home_root_lc" => $home_root_lc, "inst_root" => $inst_root, "wprules" => $wprules, "scrules" => $scrules, "condition_rules" => $condition_rules, "rules" => $rules, "gziprules" => $gziprules );
}
function clear_post_supercache( $post_id ) {
$dir = get_current_url_supercache_dir( $post_id );
if ( false == @is_dir( $dir ) )
return false;
if ( !function_exists( 'prune_super_cache' ) )
include_once( 'wp-cache-phase2.php' );
wp_cache_debug( "clear_post_supercache: deleting $dir/index*.html files", 2 );
$files_to_check = get_all_supercache_filenames( $dir );
foreach( $files_to_check as $cache_file ) {
prune_super_cache( $dir . $cache_file, true );
}
}
function wp_cron_preload_cache() {
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;
if ( get_option( 'preload_cache_stop' ) ) {
delete_option( 'preload_cache_stop' );
wp_cache_debug( "wp_cron_preload_cache: preload cancelled", 1 );
return true;
}
$mutex = $cache_path . "preload_mutex.tmp";
sleep( 3 + mt_rand( 1, 5 ) );
if ( @file_exists( $mutex ) ) {
if ( @filemtime( $mutex ) > ( time() - 600 ) ) {
wp_cache_debug( "wp_cron_preload_cache: preload mutex found and less than 600 seconds old. Aborting preload.", 1 );
return true;
} else {
wp_cache_debug( "wp_cron_preload_cache: old preload mutex found and deleted. Preload continues.", 1 );
@unlink( $mutex );
}
}
$fp = @fopen( $mutex, 'w' );
@fclose( $fp );
$counter = get_option( 'preload_cache_counter' );
if ( is_array( $counter ) == false ) {
wp_cache_debug( "wp_cron_preload_cache: setting up preload for the first time!", 5 );
$counter = array( 'c' => 0, 't' => time() );
update_option( 'preload_cache_counter', $counter );
}
$c = $counter[ 'c' ];
update_option( 'preload_cache_counter', array( 'c' => ( $c + 100 ), 't' => time() ) );
if ( $wp_cache_preload_email_me && $c == 0 )
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Started', 'wp-super-cache' ), home_url(), '' ), ' ' );
if ( $wp_cache_preload_posts == 'all' || $c < $wp_cache_preload_posts ) {
wp_cache_debug( "wp_cron_preload_cache: doing taxonomy preload.", 5 );
$permalink_counter_msg = $cache_path . "preload_permalink.txt";
if ( isset( $wp_cache_preload_taxonomies ) && $wp_cache_preload_taxonomies ) {
$taxonomies = apply_filters( 'wp_cache_preload_taxonomies', array( 'post_tag' => 'tag', 'category' => 'category' ) );
foreach( $taxonomies as $taxonomy => $path ) {
$taxonomy_filename = $cache_path . "taxonomy_" . $taxonomy . ".txt";
if ( $c == 0 )
@unlink( $taxonomy_filename );
if ( false == @file_exists( $taxonomy_filename ) ) {
$out = '';
$records = get_terms( $taxonomy );
foreach( $records as $term ) {
$out .= get_term_link( $term ). "\n";
}
$fp = fopen( $taxonomy_filename, 'w' );
if ( $fp ) {
fwrite( $fp, $out );
fclose( $fp );
}
$details = explode( "\n", $out );
} else {
$details = explode( "\n", file_get_contents( $taxonomy_filename ) );
}
if ( count( $details ) != 1 && $details[ 0 ] != '' ) {
$rows = array_splice( $details, 0, 50 );
if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume == 'many' )
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+100) ), 'Refreshing: ' . print_r( $rows, 1 ) );
foreach( (array)$rows as $url ) {
set_time_limit( 60 );
if ( $url == '' )
continue;
$url_info = parse_url( $url );
$dir = get_supercache_dir() . $url_info[ 'path' ];
wp_cache_debug( "wp_cron_preload_cache: delete $dir", 5 );
prune_super_cache( $dir );
$fp = @fopen( $permalink_counter_msg, 'w' );
if ( $fp ) {
@fwrite( $fp, "$taxonomy: $url" );
@fclose( $fp );
}
wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
wp_cache_debug( "wp_cron_preload_cache: fetched $url", 5 );
sleep( 1 );
}
$fp = fopen( $taxonomy_filename, 'w' );
if ( $fp ) {
fwrite( $fp, implode( "\n", $details ) );
fclose( $fp );
}
}
}
}
}
if ( $wp_cache_preload_posts == 'all' || $c < $wp_cache_preload_posts ) {
$types = get_post_types( array( 'public' => true, 'publicly_queryable' => true ), 'names', 'or' );
$types = array_map( 'esc_sql', $types );
$types = "'" . implode( "','", $types ) . "'";
$posts = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE ( post_type IN ( $types ) ) AND post_status = 'publish' ORDER BY ID ASC LIMIT $c, 100" );
wp_cache_debug( "wp_cron_preload_cache: got 100 posts from position $c.", 5 );
} else {
wp_cache_debug( "wp_cron_preload_cache: no more posts to get. Limit ($wp_cache_preload_posts) reached.", 5 );
$posts = false;
}
if ( !isset( $wp_cache_preload_email_volume ) )
$wp_cache_preload_email_volume = 'medium';
if ( $posts ) {
if ( get_option( 'show_on_front' ) == 'page' ) {
$page_on_front = get_option( 'page_on_front' );
$page_for_posts = get_option( 'page_for_posts' );
} else {
$page_on_front = $page_for_posts = 0;
}
if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume == 'many' )
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Refreshing posts from %2$d to %3$d', 'wp-super-cache' ), home_url(), $c, ($c+100) ), ' ' );
$msg = '';
$count = $c + 1;
$permalink_counter_msg = $cache_path . "preload_permalink.txt";
foreach( $posts as $post_id ) {
set_time_limit( 60 );
if ( $page_on_front != 0 && ( $post_id == $page_on_front || $post_id == $page_for_posts ) )
continue;
clear_post_supercache( $post_id );
$url = get_permalink( $post_id );
$fp = @fopen( $permalink_counter_msg, 'w' );
if ( $fp ) {
@fwrite( $fp, $count . " " . $url );
@fclose( $fp );
}
if ( @file_exists( $cache_path . "stop_preload.txt" ) ) {
wp_cache_debug( "wp_cron_preload_cache: cancelling preload. stop_preload.txt found.", 5 );
@unlink( $mutex );
@unlink( $cache_path . "stop_preload.txt" );
update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
if ( $wp_cache_preload_email_me )
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] Cache Preload Stopped', 'wp-super-cache' ), home_url(), '' ), ' ' );
return true;
}
$msg .= "$url\n";
wp_remote_get( $url, array('timeout' => 60, 'blocking' => true ) );
wp_cache_debug( "wp_cron_preload_cache: fetched $url", 5 );
sleep( 1 );
$count++;
}
if ( $wp_cache_preload_email_me && $wp_cache_preload_email_volume != 'less' )
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%1$s] %2$d posts refreshed', 'wp-super-cache' ), home_url(), ($c+100) ), __( "Refreshed the following posts:", 'wp-super-cache' ) . "\n$msg" );
if ( defined( 'DOING_CRON' ) ) {
wp_cache_debug( "wp_cron_preload_cache: scheduling the next preload in 30 seconds.", 5 );
wp_schedule_single_event( time() + 30, 'wp_cache_preload_hook' );
}
} else {
$msg = '';
update_option( 'preload_cache_counter', array( 'c' => 0, 't' => time() ) );
if ( (int)$wp_cache_preload_interval && defined( 'DOING_CRON' ) ) {
if ( $wp_cache_preload_email_me )
$msg = sprintf( __( 'Scheduling next preload refresh in %d minutes.', 'wp-super-cache' ), (int)$wp_cache_preload_interval );
wp_cache_debug( "wp_cron_preload_cache: no more posts. scheduling next preload in $wp_cache_preload_interval minutes.", 5 );
wp_schedule_single_event( time() + ( (int)$wp_cache_preload_interval * 60 ), 'wp_cache_full_preload_hook' );
}
global $file_prefix, $cache_max_time;
if ( $wp_cache_preload_interval > 0 ) {
$cache_max_time = (int)$wp_cache_preload_interval * 60; // fool the GC into expiring really old files
} else {
$cache_max_time = 86400; // fool the GC into expiring really old files
}
if ( $wp_cache_preload_email_me )
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 );
wp_cache_debug( "wp_cron_preload_cache: clean expired cache files older than $cache_max_time seconds.", 5 );
wp_cache_phase2_clean_expired( $file_prefix, true ); // force cleanup of old files.
}
@unlink( $mutex );
}
add_action( 'wp_cache_preload_hook', 'wp_cron_preload_cache' );
add_action( 'wp_cache_full_preload_hook', 'wp_cron_preload_cache' );
function next_preload_message( $hook, $text, $limit = 0 ) {
global $currently_preloading, $wp_cache_preload_interval;
if ( $next_preload = wp_next_scheduled( $hook ) ) {
$next_time = $next_preload - time();
if ( $limit != 0 && $next_time > $limit )
return false;
$h = $m = $s = 0;
if ( $next_time > 0 ) {
$m = (int)($next_time / 60);
$s = $next_time % 60;
$h = (int)($m / 60); $m = $m % 60;
}
if ( $next_time > 0 && $next_time < ( 60 * $wp_cache_preload_interval ) )
echo '
' . sprintf( $text, $h, $m, $s ) . '
';
if ( ( $next_preload - time() ) <= 60 )
$currently_preloading = true;
}
}
function option_preload_cache_counter( $value ) {
if ( false == is_array( $value ) ) {
$ret = array( 'c' => $value, 't' => time(), 'first' => 1 );
return $ret;
}
return $value;
}
add_filter( 'option_preload_cache_counter', 'option_preload_cache_counter' );
function check_up_on_preloading() {
$value = get_option( 'preload_cache_counter' );
if ( $value[ 'c' ] > 0 && ( time() - $value[ 't' ] ) > 3600 && false == wp_next_scheduled( 'wp_cache_preload_hook' ) ) {
if ( is_admin() )
wp_mail( get_option( 'admin_email' ), sprintf( __( '[%s] Preload may have stalled.', 'wp-super-cache' ), get_bloginfo( 'url' ) ), sprintf( __( "Preload has been restarted.\n%s", 'wp-super-cache' ), admin_url( "options-general.php?page=wpsupercache" ) ) );
wp_schedule_single_event( time() + 30, 'wp_cache_preload_hook' );
}
}
add_action( 'init', 'check_up_on_preloading' ); // sometimes preloading stops working. Kickstart it.
function wp_cache_disable_plugin( $delete_config_file = true ) {
global $wp_cache_config_file, $wp_rewrite;
if ( file_exists( ABSPATH . 'wp-config.php') ) {
$global_config_file = ABSPATH . 'wp-config.php';
} else {
$global_config_file = dirname(ABSPATH) . '/wp-config.php';
}
$line = 'define(\'WP_CACHE\', true);';
if ( strpos( file_get_contents( $global_config_file ), $line ) && ( !is_writeable_ACLSafe( $global_config_file ) || !wp_cache_replace_line( 'define *\( *\'WP_CACHE\'', '//' . $line, $global_config_file ) ) )
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." );
uninstall_supercache( WP_CONTENT_DIR . '/cache' );
$file_not_deleted = false;
if ( @file_exists( WP_CONTENT_DIR . "/advanced-cache.php" ) ) {
if ( false == @unlink( WP_CONTENT_DIR . "/advanced-cache.php" ) )
$file_not_deleted[] = 'advanced-cache.php';
}
if ( $delete_config_file && @file_exists( WP_CONTENT_DIR . "/wp-cache-config.php" ) ) {
if ( false == unlink( WP_CONTENT_DIR . "/wp-cache-config.php" ) )
$file_not_deleted[] = 'wp-cache-config.php';
}
if ( $file_not_deleted ) {
$msg = "
One or more files could not be deleted. These files and directories must be made writeable:
\n
" . WP_CONTENT_DIR . " \n";
$code = "\n";
foreach( (array)$file_not_deleted as $filename ) {
$msg .= "" . WP_CONTENT_DIR . "/{$filename} ";
$code .= "chmod 666 " . WP_CONTENT_DIR . "/{$filename} \n";
}
$code .= " \n";
$msg .= "\n
First try fixing the directory permissions with this command and refresh this page:chmod 777 " . WP_CONTENT_DIR . " If you still see this error, you have to fix the permissions on the files themselves and refresh this page again:
{$code}\n
Don't forgot to fix things later:chmod 755 " . WP_CONTENT_DIR . "
If you don't know what chmod is use this Google search to find out all about it.
Please refresh this page when the permissions have been modified.
";
wp_die( $msg );
}
extract( wpsc_get_htaccess_info() );
if ( $scrules != '' && insert_with_markers( $home_path.'.htaccess', 'WPSuperCache', array() ) ) {
$wp_rewrite->flush_rules();
} elseif( $scrules != '' ) {
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\nhttp://wordpress.org/plugins/wp-super-cache/", 'wp-super-cache' ), ABSPATH . '/.htaccess' ) );
}
}
function uninstall_supercache( $folderPath ) { // from http://www.php.net/manual/en/function.rmdir.php
if ( trailingslashit( constant( 'ABSPATH' ) ) == trailingslashit( $folderPath ) )
return false;
if ( @is_dir ( $folderPath ) ) {
$dh = @opendir($folderPath);
while( false !== ( $value = @readdir( $dh ) ) ) {
if ( $value != "." && $value != ".." ) {
$value = $folderPath . "/" . $value;
if ( @is_dir ( $value ) ) {
uninstall_supercache( $value );
} else {
@unlink( $value );
}
}
}
return @rmdir( $folderPath );
} else {
return false;
}
}
function supercache_admin_bar_render() {
global $wp_admin_bar, $wp_cache_not_logged_in;
if ( !is_user_logged_in() || !$wp_cache_not_logged_in )
return false;
if ( function_exists('current_user_can') && false == current_user_can('delete_others_posts') )
return false;
$wp_admin_bar->add_menu( array(
'parent' => '',
'id' => 'delete-cache',
'title' => __( 'Delete Cache', 'wp-super-cache' ),
'meta' => array( 'title' => __( 'Delete cache of the current page', 'wp-super-cache' ) ),
'href' => wp_nonce_url( admin_url( 'index.php?action=delcachepage&path=' . urlencode( preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', $_SERVER[ 'REQUEST_URI' ] ) ) ), 'delete-cache' )
) );
}
add_action( 'wp_before_admin_bar_render', 'supercache_admin_bar_render' );
?>
wp-cache-phase1.php 0000666 00000063061 15213303524 0010133 0 ustar 00 $header) {
// godaddy fix, via http://blog.gneu.org/2008/05/wp-supercache-on-godaddy/ and http://www.littleredrails.com/blog/2007/09/08/using-wp-cache-on-godaddy-500-error/
if( strpos( $header, 'Last-Modified:' ) === false )
header($header);
}
header( 'WP-Super-Cache: Served legacy cache file' );
if ( $wp_cache_object_cache ) {
if ( $cache ) {
if ( $ungzip ) {
// attempt to uncompress the cached file just in case it's gzipped
$uncompressed = gzuncompress( $cache );
if ( $uncompressed ) {
wp_cache_debug( "Uncompressed gzipped cache file from object cache", 1 );
$cache = $uncompressed;
unset( $uncompressed );
}
}
if ( isset( $meta[ 'dynamic' ] ) && $meta[ 'dynamic' ] ) {
wp_cache_debug( "Serving wp-cache dynamic file from object cache", 5 );
echo do_cacheaction( 'wpsc_cachedata', $cache );
} else {
wp_cache_debug( "Serving wp-cache static file from object cache", 5 );
echo $cache;
}
wp_cache_debug( "exit request", 5 );
die();
}
} else {
if ( isset( $meta[ 'dynamic' ] ) ) {
wp_cache_debug( "Serving wp-cache dynamic file", 5 );
if ( $ungzip ) {
// attempt to uncompress the cached file just in case it's gzipped
$cache = wp_cache_get_legacy_cache( $cache_file );
$uncompressed = @gzuncompress( $cache );
if ( $uncompressed ) {
wp_cache_debug( "Uncompressed gzipped cache file from wp-cache", 1 );
unset( $cache );
echo do_cacheaction( 'wpsc_cachedata', $uncompressed );
} else {
echo do_cacheaction( 'wpsc_cachedata', $cache );
}
} else {
echo do_cacheaction( 'wpsc_cachedata', wp_cache_get_legacy_cache( $cache_file ) );
}
} else {
wp_cache_debug( "Serving wp-cache static file", 5 );
if ( $ungzip ) {
$cache = wp_cache_get_legacy_cache( $cache_file );
$uncompressed = gzuncompress( $cache );
if ( $uncompressed ) {
wp_cache_debug( "Uncompressed gzipped cache file from wp-cache", 1 );
echo $uncompressed;
} else {
echo $cache;
}
} else {
echo( wp_cache_get_legacy_cache( $cache_file ) );
}
}
wp_cache_debug( "exit request", 5 );
die();
}
}
function wp_cache_get_legacy_cache( $cache_file ) {
return substr( @file_get_contents( $cache_file ), 15 );
}
if(defined('DOING_CRON')) {
extract( wp_super_cache_init() );
return true;
}
if ( !isset( $wp_super_cache_late_init ) || ( isset( $wp_super_cache_late_init ) && false == $wp_super_cache_late_init ) ) {
wp_cache_serve_cache_file();
}
function wp_cache_postload() {
global $cache_enabled, $wp_super_cache_late_init;
if ( !$cache_enabled )
return true;
if ( isset( $wp_super_cache_late_init ) && true == $wp_super_cache_late_init ) {
wp_cache_debug( "Supercache Late Init: add wp_cache_serve_cache_file to init", 3 );
add_action( 'init', 'wp_cache_late_loader', 9999 );
} else {
wp_super_cache_init();
wp_cache_phase2();
}
}
function wp_cache_late_loader() {
wp_cache_debug( "Supercache Late Loader running on init", 3 );
wp_cache_serve_cache_file();
wp_cache_phase2();
}
function wp_cache_get_cookies_values() {
static $string = '';
if ( $string != '' ) {
wp_cache_debug( "wp_cache_get_cookies_values: cached: $string" );
return $string;
}
$regex = "/^wp-postpass|^comment_author_";
if ( defined( 'LOGGED_IN_COOKIE' ) )
$regex .= "|^" . preg_quote( constant( 'LOGGED_IN_COOKIE' ) );
else
$regex .= "|^wordpress_logged_in_";
$regex .= "/";
while ($key = key($_COOKIE)) {
if ( preg_match( $regex, $key ) ) {
wp_cache_debug( "wp_cache_get_cookies_values: $regex Cookie detected: $key", 5 );
$string .= $_COOKIE[ $key ] . ",";
}
next($_COOKIE);
}
reset($_COOKIE);
// If you use this hook, make sure you update your .htaccess rules with the same conditions
$string = do_cacheaction( 'wp_cache_get_cookies_values', $string );
if ( $string != '' )
$string = md5( $string );
wp_cache_debug( "wp_cache_get_cookies_values: return: $string", 5 );
return $string;
}
function add_cacheaction( $action, $func ) {
global $wp_supercache_actions;
$wp_supercache_actions[ $action ][] = $func;
}
function do_cacheaction( $action, $value = '' ) {
global $wp_supercache_actions;
if ( !isset( $wp_supercache_actions ) || !is_array( $wp_supercache_actions ) )
return $value;
if( array_key_exists($action, $wp_supercache_actions) && is_array( $wp_supercache_actions[ $action ] ) ) {
$actions = $wp_supercache_actions[ $action ];
foreach( $actions as $func ) {
if ( is_array( $func ) ) {
$value = $func[0]->{$func[1]}( $value );
} else {
$value = $func( $value );
}
}
}
return $value;
}
function wp_cache_mobile_group( $user_agent ) {
global $wp_cache_mobile_groups;
foreach( (array)$wp_cache_mobile_groups as $name => $group ) {
foreach( (array)$group as $browser ) {
$browser = trim( strtolower( $browser ) );
if ( $browser != '' && strstr( $user_agent, $browser ) ) {
return $browser;
}
}
}
return "mobile";
}
// From http://wordpress.org/plugins/wordpress-mobile-edition/ by Alex King
function wp_cache_check_mobile( $cache_key ) {
global $wp_cache_mobile_enabled, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes;
if ( !isset( $wp_cache_mobile_enabled ) || false == $wp_cache_mobile_enabled )
return $cache_key;
wp_cache_debug( "wp_cache_check_mobile: $cache_key" );
// allow plugins to short circuit mobile check. Cookie, extra UA checks?
switch( do_cacheaction( 'wp_cache_check_mobile', $cache_key ) ) {
case "normal":
wp_cache_debug( "wp_cache_check_mobile: desktop user agent detected by wp_cache_check_mobile action" );
return $cache_key;
break;
case "mobile":
wp_cache_debug( "wp_cache_check_mobile: mobile user agent detected by wp_cache_check_mobile action" );
return $cache_key . "-mobile";
break;
}
if ( !isset( $_SERVER[ "HTTP_USER_AGENT" ] ) ) {
return $cache_key;
}
if ( do_cacheaction( 'disable_mobile_check', false ) ) {
wp_cache_debug( "wp_cache_check_mobile: disable_mobile_check disabled mobile check" );
return $cache_key;
}
$browsers = explode( ',', $wp_cache_mobile_browsers );
$user_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
foreach ($browsers as $browser) {
if ( strstr( $user_agent, trim( strtolower( $browser ) ) ) ) {
wp_cache_debug( "mobile browser detected: " . $_SERVER[ "HTTP_USER_AGENT" ], 5 );
return $cache_key . '-' . wp_cache_mobile_group( $user_agent );
}
}
if (isset($_SERVER['HTTP_X_WAP_PROFILE']) )
return $cache_key . '-' . $_SERVER['HTTP_X_WAP_PROFILE'];
if (isset($_SERVER['HTTP_PROFILE']) )
return $cache_key . '-' . $_SERVER['HTTP_PROFILE'];
if ( isset( $wp_cache_mobile_prefixes ) ) {
$browsers = explode( ',', $wp_cache_mobile_prefixes );
foreach ($browsers as $browser_prefix) {
if ( substr($user_agent, 0, 4) == $browser_prefix ) {
wp_cache_debug( "mobile browser (prefix) detected: " . $_SERVER[ "HTTP_USER_AGENT" ], 5 );
return $cache_key . '-' . $browser_prefix;
}
}
}
$accept = isset( $_SERVER[ 'HTTP_ACCEPT' ] ) ? strtolower( $_SERVER[ 'HTTP_ACCEPT' ] ) : '';
if (strpos($accept, 'wap') !== false) {
return $cache_key . '-' . 'wap';
}
if (isset($_SERVER['ALL_HTTP']) && strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false) {
return $cache_key . '-' . 'operamini';
}
return $cache_key;
}
/**
* Add a log message to the file, if debugging is turned on
*
* @param $message string The message that should be added to the log
* @param $level int
*/
function wp_cache_debug( $message, $level = 1 ) {
global $wp_cache_debug_log, $cache_path, $wp_cache_debug_ip, $wp_super_cache_debug;
// If either of the debug or log globals aren't set, then we can stop
if ( !isset($wp_super_cache_debug)
|| !isset($wp_cache_debug_log) )
return false;
// If either the debug or log globals are false or empty, we can stop
if ( $wp_super_cache_debug == false
|| $wp_cache_debug_log == '' )
return false;
// If the debug_ip has been set, but it doesn't match the ip of the requester
// then we can stop.
if ( isset($wp_cache_debug_ip)
&& $wp_cache_debug_ip != ''
&& $wp_cache_debug_ip != $_SERVER[ 'REMOTE_ADDR' ] )
return false;
// Log message: Date URI Message
$log_message = date('H:i:s') . " " . getmypid() . " {$_SERVER['REQUEST_URI']} {$message}\n\r";
// path to the log file in the cache folder
$log_file = $cache_path . str_replace('/', '', str_replace('..', '', $wp_cache_debug_log));
error_log( $log_message, 3, $log_file );
}
function wp_cache_user_agent_is_rejected() {
global $cache_rejected_user_agent;
if (!function_exists('apache_request_headers')) return false;
$headers = apache_request_headers();
if (!isset($headers["User-Agent"])) return false;
if ( false == is_array( $cache_rejected_user_agent ) )
return false;
foreach ($cache_rejected_user_agent as $expr) {
if (strlen($expr) > 0 && stristr($headers["User-Agent"], $expr))
return true;
}
return false;
}
function get_supercache_dir( $blog_id = 0 ) {
global $cache_path;
if ( $blog_id == 0 ) {
$home = get_option( 'home' );
} else {
$home = get_blog_option( $blog_id, 'home' );
}
return trailingslashit( apply_filters( 'wp_super_cache_supercachedir', $cache_path . 'supercache/' . trailingslashit( strtolower( preg_replace( '/:.*$/', '', str_replace( 'http://', '', str_replace( 'https://', '', $home ) ) ) ) ) ) );
}
function get_current_url_supercache_dir( $post_id = 0 ) {
global $cached_direct_pages, $cache_path, $wp_cache_request_uri, $WPSC_HTTP_HOST, $wp_cache_home_path;
static $saved_supercache_dir = array();
if ( isset( $saved_supercache_dir[ $post_id ] ) ) {
return $saved_supercache_dir[ $post_id ];
}
$DONOTREMEMBER = 0;
if ( $post_id != 0 ) {
$site_url = site_url();
$permalink = get_permalink( $post_id );
if ( false === strpos( $permalink, $site_url ) ) {
/*
* Sometimes site_url doesn't return the siteurl. See http://wordpress.org/support/topic/wp-super-cache-not-refreshing-post-after-comments-made
*/
$DONOTREMEMBER = 1;
wp_cache_debug( "get_current_url_supercache_dir: warning! site_url ($site_url) not found in permalink ($permalink).", 1 );
if ( false === strpos( $permalink, $WPSC_HTTP_HOST ) ) {
wp_cache_debug( "get_current_url_supercache_dir: WARNING! SERVER_NAME ({$WPSC_HTTP_HOST}) not found in permalink ($permalink). ", 1 );
$p = parse_url( $permalink );
if ( is_array( $p ) ) {
$uri = $p[ 'path' ];
wp_cache_debug( "get_current_url_supercache_dir: WARNING! Using $uri as permalink. Used parse_url.", 1 );
} else {
wp_cache_debug( "get_current_url_supercache_dir: WARNING! Permalink ($permalink) could not be understood by parse_url. Using front page.", 1 );
$uri = '';
}
} else {
wp_cache_debug( "get_current_url_supercache_dir: Removing SERVER_NAME ({$WPSC_HTTP_HOST}) from permalink ($permalink). Is the url right?", 1 );
$uri = str_replace( $WPSC_HTTP_HOST, '', $permalink );
$uri = str_replace( 'http://', '', $uri );
$uri = str_replace( 'https://', '', $uri );
}
} else {
$uri = str_replace( $site_url, '', $permalink );
if ( strpos( $uri, $wp_cache_home_path ) !== 0 )
$uri = rtrim( $wp_cache_home_path, '/' ) . $uri;
}
} else {
$uri = strtolower( $wp_cache_request_uri );
}
$uri = wpsc_deep_replace( array( '..', '\\', 'index.php', ), preg_replace( '/[ <>\'\"\r\n\t\(\)]/', '', preg_replace( "/(\?.*)?$/", '', $uri ) ) );
$dir = preg_replace( '/:.*$/', '', $WPSC_HTTP_HOST ) . $uri; // To avoid XSS attacks
if ( function_exists( "apply_filters" ) ) {
$dir = apply_filters( 'supercache_dir', $dir );
} else {
$dir = do_cacheaction( 'supercache_dir', $dir );
}
$dir = $cache_path . 'supercache/' . $dir . '/';
if( is_array( $cached_direct_pages ) && in_array( $_SERVER[ 'REQUEST_URI' ], $cached_direct_pages ) ) {
$dir = ABSPATH . $uri . '/';
}
$dir = str_replace( '..', '', str_replace( '//', '/', $dir ) );
wp_cache_debug( "supercache dir: $dir", 5 );
if ( $DONOTREMEMBER == 0 )
$saved_supercache_dir[ $post_id ] = $dir;
return $dir;
}
function get_all_supercache_filenames( $dir = '' ) {
global $wp_cache_mobile_enabled, $cache_path;
$dir = realpath( $dir );
if ( substr( $dir, 0, strlen( $cache_path ) ) != $cache_path )
return array();
$filenames = array( 'index.html', 'index-https.html', 'index.html.php' );
if ( $dir != '' && isset( $wp_cache_mobile_enabled ) && $wp_cache_mobile_enabled ) {
// open directory and look for index-*.html files
if ( is_dir( $dir ) && $dh = @opendir( $dir ) ) {
while ( ( $file = readdir( $dh ) ) !== false ) {
if ( substr( $file, 0, 6 ) == 'index-' && strpos( $file, '.html' ) )
$filenames[] = $file;
}
closedir( $dh );
}
}
if ( function_exists( "apply_filters" ) ) {
$filenames = apply_filters( 'all_supercache_filenames', $filenames );
} else {
$filenames = do_cacheaction( 'all_supercache_filenames', $filenames );
}
foreach( $filenames as $file ) {
$out[] = $file;
$out[] = $file . '.gz';
}
return $out;
}
function supercache_filename() {
//Add support for https and http caching
$is_https = ( ( isset( $_SERVER[ 'HTTPS' ] ) && 'on' == strtolower( $_SERVER[ 'HTTPS' ] ) ) || ( isset( $_SERVER[ 'HTTP_X_FORWARDED_PROTO' ] ) && 'https' == strtolower( $_SERVER[ 'HTTP_X_FORWARDED_PROTO' ] ) ) ); //Also supports https requests coming from an nginx reverse proxy
$extra_str = $is_https ? '-https' : '';
if ( function_exists( "apply_filters" ) ) {
$extra_str = apply_filters( 'supercache_filename_str', $extra_str );
} else {
$extra_str = do_cacheaction( 'supercache_filename_str', $extra_str );
}
$filename = 'index' . $extra_str . '.html';
return $filename;
}
function get_oc_version() {
$wp_cache_oc_key = wp_cache_get( "wp_cache_oc_key" );
if ( ! $wp_cache_oc_key ) {
$wp_cache_oc_key[ 'key' ] = reset_oc_version();
} elseif ( $wp_cache_oc_key[ 'ts' ] < time() - 600 )
wp_cache_set( "wp_cache_oc_key", array( 'ts' => time(), 'key' => $wp_cache_oc_key[ 'key' ] ) );
return $wp_cache_oc_key[ 'key' ];
}
function reset_oc_version( $version = 1 ) {
if ( $version == 1 )
$version = mt_rand();
wp_cache_set( "wp_cache_oc_key", array( 'ts' => time(), 'key' => $version ) );
return $version;
}
function get_oc_key( $url = false ) {
global $wp_cache_gzip_encoding, $WPSC_HTTP_HOST;
if ( $url ) {
$key = intval( $_SERVER[ 'SERVER_PORT' ] ) . strtolower( preg_replace( '/:.*$/', '', $WPSC_HTTP_HOST ) ) . $url;
} else {
$key = get_current_url_supercache_dir();
}
return $key . $wp_cache_gzip_encoding . get_oc_version();
}
function wp_supercache_cache_for_admins() {
if ( isset( $_GET[ 'preview' ] ) || function_exists( "is_admin" ) && is_admin() )
return true;
if ( false == do_cacheaction( 'wp_supercache_remove_cookies', true ) )
return true;
$cookie_keys = array( 'wordpress_logged_in', 'comment_author_' );
if ( defined( 'LOGGED_IN_COOKIE' ) )
$cookie_keys[] = constant( 'LOGGED_IN_COOKIE' );
reset( $_COOKIE );
foreach( $_COOKIE as $cookie => $val ) {
reset( $cookie_keys );
foreach( $cookie_keys as $key ) {
if ( strpos( $cookie, $key ) !== FALSE ) {
wp_cache_debug( 'Removing auth from $_COOKIE to allow caching for logged in user (' . $cookie . ')', 5 );
unset( $_COOKIE[ $cookie ] );
}
}
}
}
/* returns true/false depending on location of $dir. */
function wp_cache_confirm_delete( $dir ) {
global $cache_path, $blog_cache_dir;
// don't allow cache_path, blog cache dir, blog meta dir, supercache.
$dir = realpath( $dir );
if (
$dir == $cache_path ||
$dir == $blog_cache_dir ||
$dir == $blog_cache_dir . "meta/" ||
$dir == $cache_path . "supercache"
) {
return false;
} else {
return true;
}
}
// copy of _deep_replace() to be used before WordPress loads
function wpsc_deep_replace( $search, $subject ) {
$subject = (string) $subject;
$count = 1;
while ( $count ) {
$subject = str_replace( $search, '', $subject, $count );
}
return $subject;
}
?>
readme.txt 0000666 00000135200 15213303524 0006545 0 ustar 00 === WP Super Cache ===
Contributors: donncha, automattic, kraftbj
Tags: performance,caching,wp-cache,wp-super-cache,cache
Tested up to: 4.7.3
Stable tag: 1.4.9
Requires at least: 3.0
A very fast caching engine for WordPress that produces static html files.
== Description ==
This plugin generates static html files from your dynamic WordPress blog. After a html file is generated your webserver will serve that file instead of processing the comparatively heavier and more expensive WordPress PHP scripts.
The static html files will be served to the vast majority of your users, but because a user's details are displayed in the comment form after they leave a comment those requests are handled by the legacy caching engine. Static files are served to:
1. Users who are not logged in.
2. Users who have not left a comment on your blog.
3. Or users who have not viewed a password protected post.
99% of your visitors will be served static html files. Those users who don't see the static files will still benefit because they will see different cached files that aren't quite as efficient but still better than uncached. This plugin will help your server cope with a front page appearance on digg.com or other social networking site.
If for some reason "supercaching" doesn't work on your server then don't worry. Caching will still be performed, but every request will require loading the PHP engine. In normal circumstances this isn't bad at all. Visitors to your site will notice no slowdown or difference. Supercache really comes into it's own if your server is underpowered, or you're experiencing heavy traffic.
Super Cached html files will be served more quickly than PHP generated cached files but in every day use, the difference isn't noticeable.
The plugin serves cached files in 3 ways (ranked by speed):
1. Mod_Rewrite. The fastest method is by using Apache mod_rewrite (or whatever similar module your web server supports) to serve "supercached" static html files. This completely bypasses PHP and is extremely quick. If your server is hit by a deluge of traffic it is more likely to cope as the requests are "lighter". This does require the Apache mod_rewrite module (which is probably installed if you have custom permalinks) and a modification of your .htaccess file. Visits by anonymous or unknown users will be served this way.
2. PHP. Supercached static files can now be served by PHP. The plugin will serve a "supercached" file if it exists and it's almost as fast as the mod_rewrite method. It's easier to configure as the .htaccess file doesn't need to be changed. You still need a custom permalink. You can keep portions of your page dynamic in this caching mode. Your server may not cope as well with a really large amount of traffic. (You're gaming Digg aren't you? You'll need mod_rewrite, the rest of us are ok with PHP!)
3. Legacy caching. This is mainly used to cache pages for known users. These are logged in users, visitors who leave comments or those who should be shown custom per-user data. It's the most flexible caching method but also the slowest. As each page is different it's often better not to cache pages for these users at all and avoid legacy caching. Legacy caching will also cache visits by unknown users if this caching mode is selected. You can have dynamic parts to your page in this mode too.
If you're new to caching use PHP caching. It's easy to set up and very fast. Avoid legacy caching if you can.
= Recommended Settings =
Advanced users will probably want to use mod_rewrite caching, but PHP caching is almost as good and recommended for everyone else. Enable the following:
1. PHP caching.
2. Compress pages.
3. Don't cache pages for known users.
4. Cache rebuild.
5. CDN support.
6. Extra homepage checks.
Garbage collection is the act of cleaning up cache files that are out of date and stale. There's no correct value for the expiry time but a good starting point is 1800 seconds if you're not using legacy mode. If you are using that mode start with an expiry time of 600 seconds.
If you are not using legacy mode caching consider deleting the contents of the "Rejected User Agents" text box and allow search engines to create supercache static files.
Likewise, preload as many posts as you can and enable "Preload Mode". Garbage collection will still occur but it won't affect the preloaded files. If you don't care about sidebar widgets updating often set the preload interval to 2880 minutes (2 days) so all your posts aren't recached very often. When the preload occurs the cache files for the post being refreshed is deleted and then regenerated. Afterwards a garbage collection of all old files is performed to clean out stale cache files.
With preloading on cached files will still be deleted when posts are made or edited or comments made.
See the [WP Super Cache homepage](https://wordpress.org/plugins/wp-super-cache/) for further information. [Developer documentation](http://z9.io/wp-super-cache-developers/) is also available for those who need to interact with the cache or write plugins.
There's a [GIT repository](https://github.com/Automattic/wp-super-cache) too if you want to contribute a patch.
The [changelog](http://svn.wp-plugins.org/wp-super-cache/trunk/Changelog.txt) is a good place to start if you want to know what has changed since you last downloaded the plugin.
Interested in translating WP Super Cache to your language? Grab the [development version](http://downloads.wordpress.org/plugin/wp-super-cache.zip) where you will find an up to date wp-super-cache.pot. Send any translation files to donncha @ ocaoimh.ie and thank you!
The cache directory, usually wp-content/cache/ is only for temporary files. Do not ever put important files or symlinks to important files or directories in that directory. They will be deleted if the plugin has write access to them.
== Upgrade Notice ==
= 1.4.9 =
Fixed XSS on the settings page, settings page updates, file locking fixes and PHP 7.1 fix, caching fixes on static homepage blogs and more.
== Changelog ==
= 1.4.9 =
* Fixed bug when not running sem_remove after sem_release. See https://github.com/Automattic/wp-super-cache/issues/85
* Fixed a PHP error impacting PHP 7.1.
* Fixed a bug where we cached PUT and DELETE requests. We're treating them like POST requests now.
* Delete supercache cache files, even when supercache is disabled, because mod_rewrite rules might still be active.
* Updated the settings page, moving things around. [#173](https://github.com/Automattic/wp-super-cache/pull/173)
* Make file locking less attractive on the settings page and fixed the WPSC_DISABLE_LOCKING constant so it really disables file locking even if the user has enabled it already.
* Added a WPSC_REMOVE_SEMAPHORE constant that must be defined if sem_remove() is to be used as it may cause problems. [#174](https://github.com/Automattic/wp-super-cache/pull/174)
* Added a "wpsc_delete_related_pages_on_edit" filter that on returning 0 will disable deletion of pages outside of page being edited. [#175](https://github.com/Automattic/wp-super-cache/pull/175)
* Fixed plugin deleting all cached pages when a site had a static homepage. [#175](https://github.com/Automattic/wp-super-cache/pull/175)
* Make sure $cache_path has a trailing slash [#177](https://github.com/Automattic/wp-super-cache/pull/77)
* Remove flush() [#127](https://github.com/Automattic/wp-super-cache/pull/127) but also check if headers are empty and flush and get headers again. [#179](https://github.com/Automattic/wp-super-cache/pull/179)
* Add fix for customizer [#161](https://github.com/Automattic/wp-super-cache/pull/161) and don't cache PUT AND DELETE requests [#178](https://github.com/Automattic/wp-super-cache/pull/178)
* Check for superglobals before using them. [#131](https://github.com/Automattic/wp-super-cache/pull/131)
= 1.4.8 =
* Removed malware URL in a code comment. (harmless to operation of plugin but gets flagged by A/V software)
* Updated translation file.
= 1.4.7 =
* Update the settings page for WordPress 4.4. layout changes.
= 1.4.6 =
* Generate the file cache/.htaccess even when one exists so gzip rules are created and gzipped pages are served correctly. Props Tigertech. https://wordpress.org/support/topic/all-website-pages-downloading-gz-file-after-latest-update?replies=36#post-7494087
= 1.4.5 =
* Enhancement: Only preload public post types. Props webaware.
* Added an uninstall function that deletes the config file. Deactivate function doesn't delete it any more.
* Possible to deactivate the plugin without visiting the settings page now.
* Fixed the cache rebuild system. Rebuild files now survive longer than the request that generate them.
* Minor optimisations: prune_super_cache() exits immediately if the file doesn't exist. The output of wp_cache_get_cookies_values() is now cached.
* Added PHP pid to the debug log to aid debugging.
* Various small bug fixes.
* Fixed reset of expiry time and GC settings when updating advanced settings.
* Removed CacheMeta class to avoid APC errors. It's not used any more.
* Fixed reset of advanced settings when using "easy" settings page.
* Fixed XSS in settings page.
* Hide cache files when servers display directory indexes.
* Prevent PHP object injection through use of serialize().
= 1.4.4 =
* Fixed fatal error in output handler if GET parameters present in query. Props webaware.
* Fixed debug log. It wasn't logging the right message.
= 1.4.3 =
* Security release fixing an XSS bug in the settings page. Props Marc Montpas from Sucuri.
* Added wp_debug_log(). Props Jen Heilemann.
* Minor fixes.
= 1.4.2 =
* Fixed "acceptable file list".
* Fixed "Don't cache GET requests" feature.
* Maybe fixed "304 not modified" problem for some users.
* Fixed some PHP warnings.
= 1.4.1 =
* Fixed XSS in settings page. Props Simon Waters, Surevine Limited.
* Fix to object cache so entries may now be deleted when posts updated. (object cache still experimental)
* Documentation updates and cleanup of settings page.
= 1.4 =
* Replace legacy mfunc/mnclude/dynamic-cached-content functionality with a "wpsc_cachedata" cacheaction filter.
* Added dynamic-cache-test.php plugin example wpsc_cachedata filter plugin.
* Delete post, tag and category cache when a post changes from draft to publish or vice versa. Props @Biranit.
* Update advanced-cache.php and wp-config.php if wp-cache-phase1.php doesn't load, usually happening after migrating to a new hosting service.
* Misc bugfixes.
= 1.3.2 =
* Any mfunc/mclude/dynamic-cached-content tags in comments are now removed.
* Dynamic cached content feature disabled by default and must be enabled on the Advanced Settings page.
* Support for the mobile theme in Jetpack via helper plugin on script's Plugins tab.
= 1.3.1 =
* Minor updates to documentation
* Fixed XSS in settings page.
= 1.3 =
* mfunc tags could be executed in comments. Fixed.
* More support for sites that use the LOGGED_IN_COOKIE constant and custom cookies.
= 1.2 =
* Garbage collection of old cache files is significantly improved. I added a scheduled job that keeps an eye on things and restarts the job if necessary. Also, if you enable caching from the Easy page garbage collection will be enabled too.
* Editors can delete single cached files from the admin bar now.
* Fixed the cached page counter on the settings page.
* Some sites that updated to 1.0 experienced too much garbage collection. There are still stragglers out there who haven't upgraded but that's fixed now!
* Supercached mobile files are now used as there was a tiny little typo that needed fixing.
* If your site is in a directory and you saw problems updating a page then that should be fixed now.
* The deactivate hook has been changed so your configuration isn.t hosed when you upgrade. Unfortunately this will only happen after you do this upgrade.
* Some sites use custom cookies with the LOGGED_IN_COOKIE constant. Added support for that.
* Added support for WPTouch Pro, but it appears to be flaky still. Anyone have time to work on that? I don.t.
* Some sites had problems with scheduled posts. For some reason the plugin thought the post was in draft mode and then because it only checked the same post once, when the post magically became published the cache wasn.t cleared. That.s fixed, thanks to the debug logging of several patient users.
* And more bug fixes and translation updates.
= 1.1 =
* Use $_SERVER[ 'SERVER_NAME' ] to create cache directories.
* Only create blogs cached directories if valid requests and blogs exist.
* Only clear current blog's cache files if navigation menu is modified
* Added clean_post_cache action to clear cache on post actions
* Removed garbage collection details on Contents tab
* Added wp_cache_check_mobile cacheaction filter to shortcircuit mobile device check.
* Don't delete cache files for draft posts
* Added action on wp_trash_post to clear the cache when trashed posts are deleted
* Show a warning when 304 browser caching is disabled (because mod_rewrite caching is on)
* New check for safe mode if using less that PHP 5.3.0
* Added wp_supercache_remove_cookies filter to disable anonymous browsing mode.
* Fixed garbage collection schedule dropdown
* Fixed preload problem clearing site's cache on "page on front" sites.
* Fix for PHP variable not defined warnings
* Fixed problem refreshing cache when comments made as siteurl() sometimes didn't work
* Preloading of taxonomies is now optional
* Domain mapping fixes.
* Better support for https sites. Remove https:// to get cache paths.
* Added AddDefaultCharset .htaccess rule back in and added an option to remove it if required.
* Added multisite plugin that adds a "Cached" column to Network->Sites to disable caching on a per site basis.
* Added WPTouch plugin to modify browser and prefix list in mobile detection code. Added support for that plugin's exclude list.
* Fixed cache tester
* Filter the tags that are used to detect end-of-page using the wp_cache_eof_tags filter.
* Removed debug level from logging as it wasn't helpful.
* Removed mention of wp-minify.
= 1.0 =
* Removed AddDefaultCharset .htaccess rule
* Fixed problem with blogs in a folder and don't have a trailing slash
* New scheduling of garbage collection
* Added a "Delete cache" link to admin bar to delete cache of current page.
* Updated documentation
* Sorry Digg, Stephen Fry power now!
* Updated translations
* Preload taxonomies and all post types except revisionsand nav menu items
* Fixed previews by logged in users.
* Added option to make logged in users anonymous
* Use WP 3.0 variables to detect multisite installs
* Hash filenames so files are served from the same CDNs
= 0.9.9.9 =
* Fixed typo, is_front_page.
* Serve repeated static files from the same CDN hostname.
* Updated translations.
* Make supercache dir lowercase to avoid problems with unicode URLs.
* Add option to skip https loaded static content.
* Remove 5 second check on age of existing cache files. Should help with posts that get lots of comments and traffic.
* Lots of bugs fixed.
= 0.9.9.8 =
* CDN updates: can be switched off, multiple CNAMEs.
* Uninstall process improved. It removes generated files and fixes edited files.
* Cached dynamic pages can now be stored in Supercache files and compressed.
* 1and1 Webhosting fix (/kunden/)
* Remove log by email functionality as it caused problems for users who were inundated by email
* Many more minor fixes and changes.
= 0.9.9.6 =
* Fixed problem serving cached files with PHP
* Added support for 304 "file not modified" header to help browser caching. (PHP caching only)
* Added French & German translations, updated Italian translation and fixed translation strings.
* Sleep 4 seconds between preload urls to reduce load on the server
* Updated docs and FAQs.
= 0.9.9.5 =
* Disable compression on on easy setup page. Still causes problems on some hosts.
* Remove footerlink on easy setup page.
* Don't delete mod_rewrite rules when caching is disabled.
* Don't stop users using settings page when in safe mode.
= 0.9.9.4 =
* Settings page split into tabbed pages.
* Added new "Easy" settings page for new users.
* New PHP caching mode to serve supercached files.
* Mobile support fixes.
* Added Domain mapping support plugin.
* Added "awaiting moderation" plugin that removes that text from posts.
* Terminology change. Changed "half on" to "legacy caching".
* Fixed cache tester on some installs of WordPress.
* Updated documentation
* Added $wp_super_cache_lock_down config variable to hide lockdown and directly cached pages admin items.
* Preloaded checks if it has stalled and reschedules the job to continue.
* Serve the gzipped page when first cached if the client supports compression.
* Lots more bug fixes..
= 0.9.9.3 =
* Fixed division by zero error in half on mode.
* Always show "delete cache" button.
* Fixed "Update mod_rewrite rules" button.
* Minor text changes to admin page.
= 0.9.9.2 =
* Forgot to change version number in wp-cache.php
= 0.9.9.1 =
* Added preloading of static cache.
* Better mobile plugin support
* .htaccess rules can be updated now. Added wpsc_update_htaccess().
* Fixed "page on front" cache clearing bug.
* Check for wordpress_logged_in cookie so test cookie isn't detected.
* Added clear_post_supercache() to clear supercache for a single post.
* Put quotes around rewrite rules in case paths have spaces.
= 0.9.9 =
* Added experimental object cache support.
* Added Chinese(Traditional) translation by Pseric.
* Added FAQ on WP-Cache vs Supercache files.
* Use Supercache file if WP-Cache file not found. Useful if mod_rewrite rules are broken or not working.
* Get mobile browser list from WP Mobile Edition if found. Warn user if .htaccess out of date.
* Make sure writer lock is unlocked after writing cache files.
* Added link to developer docs in readme.
* Added Ukranian translation by Vitaly Mylo.
* Added Upgrade Notice section to readme.
* Warn if zlib compression in PHP is enabled.
* Added compression troubleshooting answer. Props Vladimir (http://blog.sjinks.pro/)
* Added Japanese translation by Tai (http://tekapo.com/)
* Updated Italian translation.
* Link to WP Mobile Edition from admin page for mobile support.
= 0.9.8 =
* Added Spanish translation by Omi.
* Added Italian translation by Gianni Diurno.
* Addded advanced debug code to check front page for category problem. Enable by setting $wp_super_cache_advanced_debug to 1 in the config file.
* Fixed wordpress vs wordpress_logged_in cookie mismatch in cookie checking function.
* Correctly check if WP_CACHE is set or not. PHP is weird.
* Added wp_cache_clear_cache() to clear out cache directory.
* Only show logged in message when debugging enabled.
* Added troubleshooting point 20. PHP vs Apache user.
* Fixed problem deleting cache file.
* Don't delete cache files when moderated comments are deleted.
= 0.9.7 =
* Fixed problem with blogs in folders.
* Added cache file listing and delete links to admin page.
* Added "Newest Cached Pages" listing in sidebox.
* Made admin page translatable.
* Added "How do I make certain parts of the page stay dynamic?" to FAQ.
* Advanced: added "late init" feature so that plugin activates on "init". Set $wp_super_cache_late_init to true in config file to use.
* Disable supercaching when GET parameters present instead of disabling all caching. Disable on POST (as normal) and preview.
* Fixed problem with cron job and mutex filename.
* Warn users they must enable mobile device support if rewrite rules detected. Better detection of when to warn that .htaccess rules must be updated (no need when rewrite rules not present)
* Advanced: Added "wpsupercache_404" filter. Return true to cache 404 error pages.
* Use the wordpress_test_cookie in the cache key.
* Show correct number of cache files when compression off.
* Fixed problem with PHP safe_mode detection.
* Various bugfixes and documentation updates. See Changelog.txt
= 0.9.6.1 =
* Move "not logged in" message init below check for POST.
* Add is_admin() check so plugin definitely can't cache the backend.
* Add "do not cache" page type to admin page.
= 0.9.6 =
* Add uninstall.php uninstall script.
* Updated cache/.htaccess rules (option to upgrade that)
* Added FAQ about category and static homepage problem.
* Add wp_cache_user_agent_is_rejected() back to wp-cache-phase2.php
* Show message for logged in users when caching disable for them.
* Check filemtime on correct supercache file
= 0.9.5 =
* Show next and last GC times in minutes, not local time.
* Don't serve wp_cache cache files to rejected user agents. Supercache files are still served to them.
* If enabled, mobile support now serves php cached files to mobile clients and static cached files to everyone else.
* Added checks for "WPSC_DISABLE_COMPRESSION" and "WPSC_DISABLE_LOCKING" constants to disable compression and file locking. For hosting companies primarily.
* Added check for DONOTCACHEPAGE constant to avoid caching a page.
* Use PHP_DOCUMENT_ROOT when creating .htaccess if necessary.
= 0.9.4.3 =
1. Added "Don't cache for logged in users" option.
2. Display file size stats on admin page.
3. Clear the cache when profile page is updated.
4. Don't cache post previews.
5. Added backslashes to rejected URI regex list.
6. Fixed problems with posts and comments not refreshing.
== Installation ==
Install like any other plugin, directly from your plugins page but make sure you have custom permalinks enabled. Go to the plugin settings page at Settings->WP Super Cache and enable caching.
== How to uninstall WP Super Cache ==
Almost all you have to do is deactivate the plugin on the plugins page. The plugin should clean up most of the files it created and modified, but it doesn't as yet remove the mod_rewrite rules from the .htaccess file. Look for the section in that file marked by SuperCache BEGIN and END tags. The plugin doesn't remove those because some people add the WordPress rules in that block too.
To manually uninstall:
1. Turn off caching on the plugin settings page and clear the cache.
2. Deactivate the plugin on the plugins page.
3. Remove the WP_CACHE define from wp-config.php. It looks like `define( 'WP_CACHE', true );`
4. Remove the Super Cache mod_rewrite rules from your .htaccess file.
5. Remove the files wp-content/advanced-cache.php and wp-content/wp-cache-config.php
6. Remove the directory wp-content/cache/
7. Remove the directory wp-super-cache from your plugins directory.
== If all else fails and your site is broken ==
1. Remove the WP_CACHE define from wp-config.php. It looks like `define( 'WP_CACHE', true );`
2. Remove the rules (see above) that the plugin wrote to the .htaccess file in your root directory.
3. Delete the wp-super-cache folder in the plugins folder.
4. Optionally delete advanced-cache.php, wp-cache-config.php and the cache folder in wp-content/.
== Frequently Asked Questions ==
= How do I know my blog is being cached? =
Go to Settings->WP Super Cache and look for the "Cache Tester" form on the easy settings page. Click "Test Cache" and the plugin will request the front page of the site twice, comparing a timestamp on each to make sure they match.
If you want to do it manually, enable debugging in the plugin settings page and load the log file in a new browser tab. Then view your blog while logged in and logged out. You should see activity in the log. View the source of any page on your site. When a page is first created, you'll see the text "Dynamic page generated in XXXX seconds." and "Cached page generated by WP-Super-Cache on YYYY-MM-DD HH:MM:SS" at the end of the source code. On reload, a cached page will show the same timestamp so wait a few seconds before checking.
In legacy caching mode, if you have compression enabled, the text "Compression = gzip" will be added. If compression is disabled and the page is served as a static html file, the text "super cache" will be added. The only other way to check if your cached file was served by PHP script or from the static cache is by looking at the HTTP headers. PHP cached pages will have the header "WP-Super-Cache: Served supercache file from PHP". Legacy cached files will have the header, "WP-Super-Cache: Served legacy cache file". I used the
Live HTTP Headers extension for Firefox to examine the headers. You should also check your cache directory in wp-content/cache/supercache/hostname/ for static cache files.
If the plugin rules are missing from your .htaccess file, the plugin will attempt to serve the super cached page if it's found. The header "WP-Super-Cache: Served supercache file from PHP" if this happens.
= Legacy (WP-Cache) vs Supercache files =
WP-Cache files are stored in wp-content/cache/ (or on MU sites in a blogs sub directory) and are named wp-cache-XXXXXXXXXXXXXXXXX.html. Associated meta files are stored in a meta sub directory. Those files contain information about the cached file. These files are generated by the "legacy caching" code in the plugin.
Supercache files are stored in wp-content/cache/supercache/HOSTNAME/ where HOSTNAME is your domain name. The files are stored in directories matching your site's permalink structure.
= Will comments and other dynamic parts of my blog update immediately? =
Comments will show as soon as they are moderated, depending on the comment policy of the blog owner. Other dynamic elements on a page may not update unless they are written in Javascript, Flash, Java or another client side browser language. The plugin really produces static html pages. No PHP is executed when those pages are served. "Popularity Contest" is one such plugin that will not work.
= Will the Super Cache compression slow down my server? =
No, it will do the opposite. Super Cache files are compressed and stored that way so the heavy compression is done only once. These files are generally much smaller and are sent to a visitor's browser much more quickly than uncompressed html. As a result, your server spends less time talking over the network which saves CPU time and bandwidth, and can also serve the next request much more quickly.
= How do I make certain parts of the page stay dynamic? =
Note: this functionality is disabled by default. You will have to enable it on the Advanced Settings page.
There are 2 ways of doing this. You can use Javascript to draw the part of the page you want to keep dynamic. That's what Google Adsense and many widgets from external sites do and is the recommended way. Or you can use a WP Super Cache filter to do the job but you can't use mod_rewrite mode caching. You have to switch to PHP or legacy caching.
WP Super Cache 1.4 introduced a cacheaction filter called wpsc_cachedata. The cached page to be displayed goes through this filter and allows modification of the page. If the page contains a placeholder tag the filter can be used to replace that tag with your dynamically generated html.
The function that hooks on to the wpsc_cachedata filter should be put in a file in the WP Super Cache plugins folder unless you use the late_init feature. An example plugin is included. Edit [dynamic-cache-test.php](http://svn.wp-plugins.org/wp-super-cache/trunk/plugins/dynamic-cache-test.php) to see the example code.
There are two example functions there. There's a simple function that replaces a string (or tag) you define when the cached page is served. The other example function uses an output buffer to generate the dynamic content. Due to a limitation in how PHP works the output buffer code MUST run before the wpsc_cachedata filter is hit, at least for when a page is cached. It doesn't matter when serving cached pages. See [this post](http://z9.io/y/6j) for a more technical and longer explanation.
To execute WordPress functions you must enable the 'Late init' feature on the advanced settings page.
= How do I use WordPress functions in cached dynamic pages? =
= How do I delay serving the cache until the "init" action fires? =
Cached files are served before almost all of WordPress is loaded. While that's great for performance it's a pain when you want to extend the plugin using a core part of WordPress. Enable 'Late init' mode on the Advanced settings page and cached files will be served when "init" fires. WordPress and it's plugins will be loaded now.
= Why don't WP UserOnline, Popularity Contest, WP Postratings or plugin X not work or update on my blog now? =
This plugin caches entire pages but some plugins think they can run PHP code every time a page loads. To fix this, the plugin needs to use Javascript/AJAX methods or the wpsc_cachedata filter described in the previous answer to update or display dynamic information.
= Why do my WP Super Cache plugin disappear when I upgrade the plugin? =
WordPress deletes the plugin folder when it updates a plugin. This is the same with WP Super Cache so any modified files in wp-super-cache/plugins/ will be deleted. You can define the variable $wp_cache_plugins_dir in wp-config.php or wp-content/wp-cache-config.php and point it at a directory outside of the wp-super-cache folder. The plugin will look there for it's plugins.
= What does the Cache Rebuild feature do? =
When a visitor leaves a comment the cached file for that page is deleted and the next visitor recreates the cached page. A page takes time to load so what happens if it receives 100 visitors during this time? There won't be a cached page so WordPress will serve a fresh page for each user and the plugin will try to create a cached page for each of those 100 visitors causing a huge load on your server. This feature stops this happening. The cached page is not cleared when a comment is left. It is marked for rebuilding instead. The next visitor within the next 10 seconds will regenerate the cached page while the old page is served to the other 99 visitors. The page is eventually loaded by the first visitor and the cached page updated. See [this post](http://z9.io/2009/01/23/wp-super-cache-089/) for more.
= Why doesn't the plugin cache requests by search engine bots by default? =
Those bots usually only visit each page once and if the page is not popular there's no point creating a cache file that will sit idle on your server. However if you're not using legacy caching you can allow these visits to be cached by removing the list of bots from "Rejected User Agents" on the Advanced settings page.
= A category page is showing instead of my homepage =
A tiny proportion of websites will have problems with the following configuration:
1. Uses a static page for the front page.
2. Uses /%category%/%postname%/ permalink structure.
Sometimes a category page is cached as the homepage of the site instead of the static page. I can't [replicate the problem](http://wordpress.org/support/topic/237415/page/2?replies=38) but a simple solution is to switch the plugin to PHP mode. For normal traffic you will see no difference in the speed of your site. You can also enable "Extra homepage checks" on the Advanced Settings page.
= Why do I get warnings about caching from http://ismyblogworking.com/ =
"Your blog doesn't support client caching (no 304 response to If-modified-since)."
"Your feed doesn't support caching (no 304 response to If-modified-since)"
Supercache doesn't support 304 header checks in mod_rewrite mode but does support it in PHP mode. This is caching done by your browser, not the server. It is a check your browser does to ask the server if an updated version of the current page is available. If not, it doesn't download the old version again. The page is still cached by your server, just not by your visitors' browsers.
Try the Cacheability Engine at http://www.ircache.net/cgi-bin/cacheability.py or http://redbot.org/ for further analysis.
= How should I best use the utm_source tracking tools in Google Analytics with this plugin? =
That tracking adds a query string to each url linked from various sources like Twitter and feedreaders. Unfortunately it stops pages being supercached. See [Joost's comment here](http://z9.io/remove-unused-utmsource-urls/#comment-672813) for how to turn it into an anchor tag which can be supercached.
= The plugin complains that wp-content is writable! htdocs is writable! =
It's not good when the web server can write to these directories but sometimes shared hosting accounts are set up in this way to make administration easier. Use `chmod 755 directory` to fix the permissions or find the permissions section of your ftp client. This [Google search](http://www.google.ie/search?sourceid=chrome&ie=UTF-8&q=ftp+fix+directory+permissions+755) will lead you to more information on this topic and there's also [this codex page](http://codex.wordpress.org/Changing_File_Permissions) too. Unfortunately some hosts require that those directories be writable. If that's the case just ignore this warning.
= How do I delete the WP_CACHE define from wp-config.php? =
Load your desktop ftp client and connect to your site. Navigate to the root (or the directory below it) of your site where you'll find wp-config.php. Download that file and edit it in a text editor. Delete the line `define( 'WP_CACHE', true );` and save the file. Now upload it, overwriting the wp-config.php on your server.
= How do I delete the Super Cache rules from the .htaccess file? =
Load your desktop ftp client and connect to your site. You may need to enable "Show hidden files" in the preferences of the ftp client. Navigate to the root of your site where you'll find the .htaccess file. Download that file and edit it in a text editor. Delete the lines between "# BEGIN WPSuperCache" and "# END WPSuperCache" and save the file. Now upload it, overwriting the .htaccess file on your server.
= How do I change file permissions? =
This [page](http://codex.wordpress.org/Changing_File_Permissions) on the WordPress Codex explains everything you need to know about file permissions on your server and various ways of changing them.
= Why do I get load spikes when new posts are made? =
You may have the "clear all cached files when new posts are made" option set. Clearing those files can take time plus your visitors will now be visiting uncached pages. Are you using Google Analytics campaign tracking with utm_source in the url? Those pages aren't cached. See the question, "How should I best use the utm_source tracking tools in Google Analytics with this plugin" above for how to use them properly.
Cached pages have to be refreshed when posts are made. Perhaps your server just isn't up to the job of serving the amount of traffic you get. Enable the "cache rebuild" feature as that may help.
= How many pages can I cache? =
The only real limit are limits defined by your server. For example, EXT2 and EXT3 allow a maximum of 31,999 sub directories so if you have a flat permalink structure (like /%POSTNAME%/) and more than 32,000 posts you may run into problems. Likewise, if you run a multisite network and have more than 31,999 sites (blogs) you won't be able to cache all of them. Realistically if you had that many active sites you wouldn't be running on one server.
= How do I serve cached mobile pages to clients on small screens like phones and tablets? =
You'll have to use a separate mobile plugin to render a page formatted for those visitors. The following plugins have been tested but YMMV depending on mobile client.
* [Jetpack's Mobile Theme Module](http://wordpress.org/plugins/jetpack)
* [WPTouch](http://wordpress.org/plugins/wptouch/)
* [WordPress Mobile Edition](http://wordpress.org/plugins/wordpress-mobile-edition/)
* [WordPress Mobile Pack](http://wordpress.org/plugins/wordpress-mobile-pack/) (can't have "Don't cache pages for known users." enabled)
= Troubleshooting =
If things don't work when you installed the plugin here are a few things to check:
1. Is wp-content writable by the web server?
2. Is there a wp-content/wp-cache-config.php ? If not, copy the file wp-super-cache/wp-cache-config-sample.php to wp-content/wp-cache-config.php and make sure WPCACHEHOME points at the right place.
3. Is there a wp-content/advanced-cache.php ? If not, then you must copy wp-super-cache/advanced-cache.php into wp-content/. You must edit the file and change the path so it points at the wp-super-cache folder.
4. If pages are not cached at all, remove wp-content/advanced-cache.php and recreate it, following the advice above.
5. Make sure the following line is in wp-config.php and it is ABOVE the "require_once(ABSPATH.'wp-settings.php');" line:
`define( 'WP_CACHE', true );`
6. Try the Settings->WP Super Cache page again and enable cache.
7. Look in wp-content/cache/supercache/. Are there directories and files there?
8. Anything in your php error_log?
9. If your browser keeps asking you to save the file after the super cache is installed you must disable Super Cache compression. Go to the Settings->WP Super Cache page and disable it there.
10. The plugin does not work very well when PHP's safe mode is active. This must be disabled by your administrator.
11. If pages are randomly super cached and sometimes not, your blog can probably be viewed with and without the "www" prefix on the URL. You should choose one way and install the [Enforce www preference](http://txfx.net/code/wordpress/enforce-www-preference/) plugin if you are using an old WordPress install. The latest versions redirect themselves (you should always be running the latest version of WordPress anyway!)
12. Private Server users at Dreamhost should edit wp-content/wp-cache-config.php and set the cache dir to "/tmp/" if they are getting errors about increasing CPU usage. See this [discussion](http://wordpress.org/support/topic/145895?replies=42) for more.
13. File locking errors such as "failed to acquire key 0x152b: Permission denied in..." or "Page not cached by WP Super Cache. Could not get mutex lock." are a sign that you may have to use file locking. Edit wp-content/wp-cache-config.php and uncomment "$use_flock = true" or set $sem_id to a different value. You can also disable file locking from the Admin screen as a last resort.
14. Make sure cache/wp_cache_mutex.lock is writable by the web server if using coarse file locking.
15. The cache folder cannot be put on an NFS or Samba or NAS share. It has to be on a local disk. File locking and deleting expired files will not work properly unless the cache folder is on the local machine.
16. Garbage collection of old cache files won't work if WordPress can't find wp-cron.php. If your hostname resolves to 127.0.0.1 it could be preventing the garbage collection from working. Check your access_logs for wp-cron.php entries. Do they return a 404 (file not found) or 200 code? If it's 404 or you don't see wp-cron.php anywhere WordPress may be looking for that script in the wrong place. You should speak to your server administator to correct this or edit /etc/hosts on Unix servers and remove the following line. Your hostname must resolve to the external IP address other servers on the network/Internet use. See http://yoast.com/wp-cron-issues/ for more. A line like "127.0.0.1 localhost localhost.localdomain" is ok.
`127.0.0.1 myhostname.com`
17. If old pages are being served to your visitors via the supercache, you may be missing Apache modules (or their equivalents if you don't use Apache). 3 modules are required: mod_mime, mod_headers and mod_expires. The last two are especially important for making sure browsers load new versions of existing pages on your site.
18. The error message, "WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed!" appears at the end of every page. Open the file wp-content/advanced-cache.php in your favourite editor. Is the path to wp-cache-phase1.php correct? This file will normally be in wp-content/plugins/wp-super-cache/. If it is not correct the caching engine will not load.
19. Caching doesn't work. The timestamp on my blog keeps changing when I reload. Check that the path in your .htaccess rules matches where the supercache directory is. You may have to hardcode it. Or use the plugin in PHP or legacy caching mode.
20. If supercache cache files are generated but not served, check the permissions on all your wp-content/cache/supercache folders (and each of wp-content cache and supercache folders) and wp-content/cache/.htaccess. If your PHP runs as a different user to Apache and permissions are strict Apache may not be able to read the PHP generated cache files. To fix you must add the following line to your wp-config.php (Add it above the WP_CACHE define.) Then clear your cache.
`umask( 0022 );`
21. If you see garbage in your browser after enabling compression in the plugin, compression may already be enabled in your web server. In Apache you must disable mod_deflate, or in PHP zlib compression may be enabled. You can disable that in three ways. If you have root access, edit your php.ini and find the zlib.output_compression setting and make sure it's "Off" or add this line to your .htaccess:
`php_flag zlib.output_compression off`
If that doesn't work, add this line to your wp-config.php:
`ini_set('zlib.output_compression', 0);`
22. The "white screen of death" or a blank page when you visit your site is almost always caused by a PHP error but [it may also be caused by APC](http://www.johnberns.com/2010/03/19/wp-super-cache-blank-page-problem-fixed/). Disable that PHP extension if you have trouble and replace with eAccelerator or Xcache.
23. After uninstalling, your permalinks may break if you remove the WordPress mod_rewrite rules too. Regenerate those rules by visiting the Settings->Permalink page and saving that form again.
24. If your blog refuses to load make sure your wp-config.php is correct. Are you missing an opening or closing PHP tag?
25. Your front page is ok but posts and pages give a 404? Go to Settings->permalinks and click "Save" once you've selected a custom permalink structure. You may need to manually update your .htaccess file.
26. If certain characters do not appear correctly on your website your server may not be configured correctly. You need to tell visitors what character set is used. Go to Settings->Reading and copy the 'Encoding for pages and feeds' value. Edit the .htaccess file with all your Supercache and WordPress rewrite rules and add this at the top, replacing CHARSET with the copied value. (for example, 'UTF-8')
`AddDefaultCharset CHARSET`
27. Use [Cron View](http://wordpress.org/plugins/cron-view/) to help diagnose garbage collection and preload problems. Use the plugin to make sure jobs are scheduled and for what time. Look for the wp_cache_gc and wp_cache_full_preload_hook jobs.
18. The error message, "WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory." appears at the end of every page. You can delete wp-content/advanced-cache.php and reload the plugin settings page or edit wp-config.php and look for WPCACHEHOME and make sure it points at the wp-super-cache folder. This will normally be wp-content/plugins/wp-super-cache/ but you'll likely need the full path to that file (so it's easier to let the settings page fix it). If it is not correct the caching engine will not load.
19. If your server is running into trouble because of the number of semaphores used by the plugin it's because your users are using file locking which is not recommended (but is needed by a small number of users). You can globally disable file locking by defining the constant WPSC_DISABLE_LOCKING, or defining the constant WPSC_REMOVE_SEMAPHORE so that sem_remove() is called after every page is cached but that seems to cause problems for other processes requesting the same semaphore. Best to disable it.
== CDN ==
A Content Delivery Network (CDN) is usually a network of computers situated around the world that will serve the content of your website faster by using servers close to you. Static files like images, Javascript and CSS files can be served through these networks to speed up how fast your site loads. You can also create a "poor man's CDN" by using a sub domain of your domain to serve static files too.
[OSSDL CDN off-linker](http://wordpress.org/plugins/ossdl-cdn-off-linker/) has been integrated into WP Super Cache to provide basic CDN support. It works by rewriting the URLs of files (excluding .php files) in wp-content and wp-includes on your server so they point at a different hostname. Many CDNs support [origin pull](http://www.google.com/search?hl=en&q=%22origin+pull%22). This means the CDN will download the file automatically from your server when it's first requested, and will continue to serve it for a configurable length of time before downloading it again from your server.
Configure this on the "CDN" tab of the plugin settings page. This is an advanced technique and requires a basic understanding of how your webserver or CDNs work. Please be sure to clear the file cache after you configure the CDN.
== Custom Caching ==
It is now possible to hook into the caching process using the add_cacheaction() function.
Three hooks are available:
1. 'wp_cache_get_cookies_values' - modify the key used by WP Cache.
2. 'add_cacheaction' - runs in phase2. Allows a plugin to add WordPress hooks.
3. 'cache_admin_page' - runs in the admin page. Use it to modify that page, perhaps by adding new configuration options.
There is one regular WordPress filter too. Use the "do_createsupercache" filter
to customize the checks made before caching. The filter accepts one parameter.
The output of WP-Cache's wp_cache_get_cookies_values() function.
See plugins/searchengine.php as an example I use for my [No Adverts for Friends](http://z9.io/no-adverts-for-friends/) plugin.
== Links ==
[WP Widget Cache](http://wordpress.org/plugins/wp-widget-cache/) is another caching plugin for WordPress. This plugin caches the output of widgets and may significantly speed up dynamic page generation times.
== Updates ==
Updates to the plugin will be posted here, to [Holy Shmoly!](http://z9.io/) and the [WP Super Cache homepage](https://wordpress.org/plugins/wp-super-cache/) will always link to the newest version.
== Thanks ==
I would sincerely like to thank [John Pozadzides](http://onemansblog.com/) for giving me the idea for this, for writing the "How it works" section and for testing the plugin through 2 front page appearances on digg.com
Thanks to James Farmer and Andrew Billits of [Edu Blogs](http://edublogs.org/) fame who helped me make this more WordPress MU friendly.
Translators who did a great job converting the text of the plugin to their native language. Thank you!
* [Gianni Diurno](http://gidibao.net/) (Italian)
* [Omi](http://equipajedemano.info/) (Spanish)
* [tomchen1989](http://emule-fans.com/) and [Christopher Meng](http://cicku.me) (Simplified Chinese)
* Tai (Japanese)
* [Vitaly](http://pressword.com.ua/wordpress/) (Ukranian)
* [Pseric](http://pseric.com/) and [Priv](http://priv.tw/blog) (Traditional Chinese)
* [Ma�tre M�](http://maitremo.fr/) (French)
* [Mathias Roth](http://trade-service.eu/) (German)
* Bar�� �nver (Turkish)
* [Elvis Fweb](http://wp.turkenichev.ru/) (Russian)
* Fredrik Fors�ll (Swedish)
* [Alyona Lompar](http://wwww.webhostinggeeks.com/) (Ukranian)
* [Nata Strazda](http://www.webhostingrating.com/) (Lithuanian)
* [Alexander Alexandrov](http://www.designcontest.com/) (Belarusian)
* [Michail Bogdanov](http://www.webhostinghub.com/) (Romanian)
* [Anja Skrba](http://science.webhostinggeeks.com/wordpress-super-cache) (Serbo-Croatian)
plugins/badbehaviour.php 0000666 00000006656 15213303524 0011410 0 ustar 00
" . __( 'Warning!', 'wp-super-cache' ) . " $err";
}
add_cacheaction( 'cache_admin_page', 'wp_supercache_badbehaviour_admin' );
?>
plugins/dynamic-cache-test.php 0000666 00000017373 15213303524 0012415 0 ustar 00 ", $cachedata );
}
add_cacheaction( 'wpsc_cachedata', 'dynamic_cache_test_filter' );
function dynamic_cache_test_template_tag() {
echo DYNAMIC_CACHE_TEST_TAG; // This is the template tag
}
function dynamic_cache_test_init() {
add_action( 'wp_footer', 'dynamic_cache_test_template_tag' );
}
add_cacheaction( 'add_cacheaction', 'dynamic_cache_test_init' );
}
/*
* EXAMPLE 2
*
* This is going to be complicated. Hang on!
*
* When the cache file for a new page is generated the plugin uses an output
* buffer to capture the page. A callback function processes the buffer and
* writes to the cache file. The placeholder tag for any dynamic content has
* to be written to that cache file but also, it has to be replaced with
* dynamic content before the page is shown to the user.
* More on output buffers here: http://php.net/ob_start
*
* Unfortunately an extra output buffer is often required when capturing dynamic
* content such as sidebar widgets. Due to a quirk of the way PHP works it's
* not possible to have an output buffer run in an output buffer callback. That
* dynamic content has to be generated before the callback function is reached.
* The following error occurs when an output buffer is created in the
* callback function of another output buffer:
* "PHP Fatal error: ob_start(): Cannot use output buffering in output buffering display handlers in..."
*
* In this example the function add_action() isn't available when this file is
* loaded so dynamic_output_buffer_init() is hooked on to the "add_cacheaction"
* cacheaction. That function then hooks dynamic_output_buffer_test() on to the
* familiar wp_footer action.
*
* The first time dynamic_output_buffer_test() runs it generates the dynamic
* content and captures it with ob_start() in the DYNAMIC_OB_TEXT constant.
*
* When the main WP Super Cache output buffer is ready the callback is called.
* This fires the wpsc_cachedata_safety filter. If the DYNAMIC_OB_TEXT constant
* is set, which means dynamic content is ready, then it returns 1, a signal
* that everything is ok.
* Finally, the wpsc_cachedata filter is run. The function
* dynamic_output_buffer_test() is hooked on to it. Since DYNAMIC_OB_TEXT is
* set it replaces the placeholder text with that constant.
* The resulting html is then sent to the browser.
*
* Already cached pages call the safety filter, and then the wpsc_cachedata
* filter so any hooked function must be ready to generate dynamic content. The
* very last line of dynamic_output_buffer_test() replaces the placeholder tag
* with the dynamic content in the cache file.
*
*
* Use an output buffer to capture dynamic content while the page is generated
* and insert into the right place:
* Remember to add the DYNAMIC_OUTPUT_BUFFER_TAG text (as defined below) to
* your theme where the dynamic content should be.
*
* dynamic_output_buffer_test() is a function that uses the wpsc_cachedata
* filter to add a small message and the current server time to every web
* page. The time increments on every reload.
*
*/
define( 'DYNAMIC_OUTPUT_BUFFER_TAG', '' ); // Change this to a secret placeholder tag
if ( DYNAMIC_OUTPUT_BUFFER_TAG != '' ) {
function dynamic_output_buffer_test( &$cachedata = 0 ) {
if ( defined( 'DYNAMIC_OB_TEXT' ) )
return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, DYNAMIC_OB_TEXT, $cachedata );
ob_start();
// call the sidebar function, do something dynamic
echo "
This is a test. The current time on the server is: " . date( 'H:i:s' ) . "
";
$text = ob_get_contents();
ob_end_clean();
if ( $cachedata === 0 ) { // called directly from the theme so store the output
define( 'DYNAMIC_OB_TEXT', $text );
} else // called via the wpsc_cachedata filter. We only get here in cached pages in wp-cache-phase1.php
return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, $text, $cachedata );
}
add_cacheaction( 'wpsc_cachedata', 'dynamic_output_buffer_test' );
function dynamic_output_buffer_init() {
add_action( 'wp_footer', 'dynamic_output_buffer_test' );
}
add_cacheaction( 'add_cacheaction', 'dynamic_output_buffer_init' );
function dynamic_output_buffer_test_safety( $safety ) {
if ( defined( 'DYNAMIC_OB_TEXT' ) ) // this is set when you call dynamic_output_buffer_test() from the theme
return 1; // ready to replace tag with dynamic content.
else
return 0; // tag cannot be replaced.
}
add_cacheaction( 'wpsc_cachedata_safety', 'dynamic_output_buffer_test_safety' );
}
?>
plugins/jetpack.php 0000666 00000006161 15213303524 0010365 0 ustar 00
" . sprintf( __( "Jetpack not found in %s. Install it and enable the mobile theme and this helper plugin to cache visits by mobile visitors." ), dirname( WPCACHEHOME ) ) . "";
} else { ?>
plugins/searchengine.php 0000666 00000006772 15213303524 0011407 0 ustar 00
plugins/awaitingmoderation.php 0000666 00000004453 15213303524 0012633 0 ustar 00
plugins/wptouch.php 0000666 00000011200 15213303524 0010423 0 ustar 00
' . __('WPTouch plugin detected! Please go to the Supercache plugins page and enable the WPTouch helper plugin.', 'wp-super-cache' ) . '
';
}
function wp_super_cache_wptouch_exists() {
global $cache_wptouch;
if ( $cache_wptouch == 1 )
return false;
if ( is_admin() && function_exists( 'wptouch_get_plugin_dir_name' ) )
add_action( 'admin_notices', 'wp_super_cache_wptouch_notice' );
}
if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'wpsupercache' ) {
add_cacheaction( 'add_cacheaction', 'wp_super_cache_wptouch_exists' );
}
// disable mobile checking if
function wp_super_cache_maybe_disable_wptouch( $t ) {
global $cache_wptouch, $wptouch_exclude_ua;
if ( $cache_wptouch != 1 )
return false;
if ( ( isset( $_COOKIE[ 'wptouch_switch_toggle' ] ) && $_COOKIE[ 'wptouch_switch_toggle' ] == 'normal' ) ||
( isset( $_COOKIE[ 'wptouch-pro-view' ] ) && $_COOKIE[ 'wptouch-pro-view' ] == 'desktop' ) )
return true;
$ua = explode( ",", $wptouch_exclude_ua );
foreach( $ua as $agent ) {
if ( preg_match( "#$agent#i", $_SERVER[ 'HTTP_HOST' ] ) )
return true; // disable mobile ua check if matches the exclude list in wptouch
}
return false;
}
add_cacheaction( 'disable_mobile_check', 'wp_super_cache_maybe_disable_wptouch' );
function wp_super_cache_wptouch_browsers( $browsers ) {
global $cache_wptouch, $wptouch_exclude_ua, $wp_cache_config_file;
if ( false == function_exists( 'bnc_wptouch_get_exclude_user_agents' ) || false == function_exists( 'bnc_wptouch_get_user_agents' ) )
return $browsers;
$browsers = implode( ',', bnc_wptouch_get_exclude_user_agents() ); // hack, support exclude agents too
if ( $browsers != $wptouch_exclude_ua ) {
wp_cache_replace_line('^ *\$wptouch_exclude_ua', "\$wptouch_exclude_ua = '$browsers';", $wp_cache_config_file);
$wptouch_exclude_ua = $browsers;
}
return bnc_wptouch_get_user_agents();
}
function wp_super_cache_wptouch_prefixes( $prefixes ) {
return array(); // wptouch doesn't support UA prefixes
}
function wp_super_cache_wptouch_cookie_check( $cache_key ) {
if ( false == isset( $_COOKIE[ 'wptouch_switch_toggle' ] ) )
return $cache_key;
if ( $_COOKIE[ 'wptouch_switch_toggle' ] == 'normal' || $_COOKIE[ 'wptouch_switch_toggle' ] == 'mobile' )
return $_COOKIE[ 'wptouch_switch_toggle' ];
if ( isset( $_COOKIE[ 'wptouch-pro-view' ] ) ) {
if ( $_COOKIE[ 'wptouch-pro-view' ] == 'desktop' )
return 'normal';
else
return $_COOKIE[ 'wptouch-pro-view' ];
}
return $cache_key;
}
if ( isset( $cache_wptouch ) && $cache_wptouch == 1 ) {
add_cacheaction( 'wp_super_cache_mobile_browsers', 'wp_super_cache_wptouch_browsers' );
add_cacheaction( 'wp_super_cache_mobile_prefixes', 'wp_super_cache_wptouch_prefixes' );
add_cacheaction( 'wp_cache_check_mobile', 'wp_super_cache_wptouch_cookie_check' );
}
?>
plugins/multisite.php 0000666 00000004574 15213303524 0010771 0 ustar 00 'enable_cache', 'id' => $blog_id ) ), 'wp-cache' . $blog_id ) . "'>" . __( 'Enable', 'wp-super-cache' ) . "";
} else {
echo "WARNING: Test some static urls e.g., %s to ensure your CDN service is fully working before saving changes.', 'wp-super-cache' ), '' . $example_cdn_uri . '' ); ?>