Skip to content

Instantly share code, notes, and snippets.

@peterchester
Created May 28, 2012 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterchester/2817588 to your computer and use it in GitHub Desktop.
Save peterchester/2817588 to your computer and use it in GitHub Desktop.
Wp-supercache fixes to various PHP Notices
diff --git a/wp-content/plugins/wp-super-cache/plugins/badbehaviour.php b/wp-content/plugins/wp-super-cache/plugins/badbehaviour.php
index 6c07488..478dd85 100644
--- a/wp-content/plugins/wp-super-cache/plugins/badbehaviour.php
+++ b/wp-content/plugins/wp-super-cache/plugins/badbehaviour.php
@@ -66,7 +66,7 @@ function wp_supercache_badbehaviour_admin() {
<label><input type="radio" name="cache_badbehaviour" value="0" <?php if( !$cache_badbehaviour ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
<p><?php _e( '', 'wp-super-cache' ); ?></p><?php
echo '<p>' . sprintf( __( '(Only legacy caching supported, disabled compression and requires <a href="http://www.bad-behavior.ioerror.us/">Bad Behavior</a> in "%s/plugins/bad-behavior/") ', 'wp-super-cache' ), WP_CONTENT_DIR ) . '</p>';
- if ($changed) {
+ if ( isset( $changed ) && $changed ) {
if ( $cache_badbehaviour )
$status = __( "enabled" );
else
diff --git a/wp-content/plugins/wp-super-cache/plugins/domain-mapping.php b/wp-content/plugins/wp-super-cache/plugins/domain-mapping.php
index f141e6d..7910612 100644
--- a/wp-content/plugins/wp-super-cache/plugins/domain-mapping.php
+++ b/wp-content/plugins/wp-super-cache/plugins/domain-mapping.php
@@ -10,7 +10,7 @@ function domain_mapping_gc_cache( $function, $directory ) {
if ( !$siteurl )
return false;
- $protocol = ( 'on' == strtolower( $_SERVER['HTTPS' ] ) ) ? 'https://' : 'http://';
+ $protocol = ( isset( $_SERVER['HTTPS' ] ) && 'on' == strtolower( $_SERVER['HTTPS' ] ) ) ? 'https://' : 'http://';
$siteurl = trailingslashit( str_replace( $protocol, '', $siteurl ) );
if ( $directory == 'homepage' )
@@ -39,7 +39,7 @@ function domain_mapping_supercachedir( $dir ) {
if ( !$siteurl )
return $dir;
- $protocol = ( 'on' == strtolower( $_SERVER['HTTPS' ] ) ) ? 'https://' : 'http://';
+ $protocol = ( isset( $_SERVER['HTTPS' ] ) && 'on' == strtolower( $_SERVER['HTTPS' ] ) ) ? 'https://' : 'http://';
$siteurl = str_replace( $protocol, '', $siteurl );
return $cache_path . 'supercache/' . $siteurl;
}
@@ -76,7 +76,7 @@ function wp_supercache_domain_mapping_admin() {
<label><input type="radio" name="cache_domain_mapping" value="0" <?php if( !$cache_domain_mapping ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
<p><?php _e( '', 'wp-super-cache' ); ?></p><?php
echo '<p>' . __( 'Provides support for <a href="http://wordpress.org/extend/plugins/wordpress-mu-domain-mapping/">Domain Mapping</a> plugin to map multiple domains to a blog.', 'wp-super-cache' ) . '</p>';
- if ($changed) {
+ if ( isset( $changed ) && $changed ) {
if ( $cache_domain_mapping )
$status = __( "enabled" );
else
diff --git a/wp-content/plugins/wp-super-cache/plugins/searchengine.php b/wp-content/plugins/wp-super-cache/plugins/searchengine.php
index 9e0da37..6a66220 100644
--- a/wp-content/plugins/wp-super-cache/plugins/searchengine.php
+++ b/wp-content/plugins/wp-super-cache/plugins/searchengine.php
@@ -70,7 +70,7 @@ function wp_supercache_searchengine_admin() {
<label><input type="radio" name="cache_no_adverts_for_friends" value="0" <?php if( $cache_no_adverts_for_friends == 'no' ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
<p><?php _e( '', 'wp-super-cache' ); ?></p><?php
echo '<p>' . __( 'Provides support for <a href="http://ocaoimh.ie/no-adverts-for-friends/">No Adverts for Friends</a>.', 'wp-super-cache' ) . '</p>';
- if ($changed) {
+ if ( isset( $changed ) && $changed ) {
if ( 'yes' == $cache_no_adverts_for_friends )
$status = __( "enabled" );
else
diff --git a/wp-content/plugins/wp-super-cache/plugins/wptouch.php b/wp-content/plugins/wp-super-cache/plugins/wptouch.php
index 258b46e..34d4892 100644
--- a/wp-content/plugins/wp-super-cache/plugins/wptouch.php
+++ b/wp-content/plugins/wp-super-cache/plugins/wptouch.php
@@ -23,7 +23,7 @@ function wp_super_cache_wptouch_admin() {
<label><input type="radio" name="cache_wptouch" value="0" <?php if( !$cache_wptouch ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
<p><?php _e( '', 'wp-super-cache' ); ?></p><?php
echo '<p>' . __( 'Provides support for <a href="http://wordpress.org/extend/plugins/wptouch/">WPTouch</a> mobile theme and plugin.', 'wp-super-cache' ) . '</p>';
- if ($changed) {
+ if ( isset( $changed ) && $changed ) {
if ( $cache_wptouch )
$status = __( "enabled" );
else
@@ -106,7 +106,7 @@ function wp_super_cache_wptouch_cookie_check( $cache_key ) {
return $cache_key;
}
-if ( $cache_wptouch == 1 ) {
+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' );
diff --git a/wp-content/plugins/wp-super-cache/wp-cache.php b/wp-content/plugins/wp-super-cache/wp-cache.php
index 8afc314..86cb9d1 100644
--- a/wp-content/plugins/wp-super-cache/wp-cache.php
+++ b/wp-content/plugins/wp-super-cache/wp-cache.php
@@ -261,7 +261,7 @@ function wp_cache_manager_error_checks() {
}
}
- if ( function_exists( "is_main_site" ) && true == is_main_site() || function_exists( 'is_main_blog' ) && true == is_main_blog() ) {
+ if ( true == is_main_site() ) {
$home_path = trailingslashit( get_home_path() );
$scrules = implode( "\n", extract_from_markers( $home_path.'.htaccess', 'WPSuperCache' ) );
if ( $cache_enabled && $wp_cache_mod_rewrite && !$wp_cache_mobile_enabled && strpos( $scrules, addcslashes( implode( '|', $wp_cache_mobile_browsers ), ' ' ) ) ) {
@@ -398,7 +398,7 @@ function wp_cache_manager_updates() {
}
wp_cache_replace_line('^ *\$wp_cache_front_page_checks', "\$wp_cache_front_page_checks = " . $wp_cache_front_page_checks . ";", $wp_cache_config_file);
- $wp_supercache_cache_list = $_POST[ 'wp_supercache_cache_list' ] == 1 ? 1 : 0;
+ $wp_supercache_cache_list = ( isset( $_POST[ 'wp_supercache_cache_list' ] ) && $_POST[ 'wp_supercache_cache_list' ] == 1 ) ? 1 : 0;
wp_cache_replace_line('^ *\$wp_supercache_cache_list', "\$wp_supercache_cache_list = " . $wp_supercache_cache_list . ";", $wp_cache_config_file);
if ( isset( $_POST[ 'wp_cache_status' ] ) ) {
@@ -635,7 +635,8 @@ jQuery(document).ready(function(){
}
?> <table><td valign='top'><?php
- switch( $_GET[ 'tab' ] ) {
+ $current = ( isset( $_GET[ 'tab' ] ) ) ? $_GET[ 'tab' ] : '';
+ switch( $current ) {
case "cdn":
scossdl_off_options();
break;
@@ -1035,7 +1036,7 @@ jQuery(document).ready(function(){
}
echo '<form name="cache_tester" action="" method="post">';
echo '<input type="hidden" name="action" value="test" />';
- if ( 'on' == strtolower( $_SERVER['HTTPS' ] ) )
+ if ( isset( $_SERVER['HTTPS' ] ) && 'on' == strtolower( $_SERVER['HTTPS' ] ) )
echo "<input type='checkbox' name='httponly' checked='checked' value='1' /> " . __( 'Send non-secure (non https) request for homepage', 'wp-super-cache' );
echo '<div class="submit"><input type="submit" name="test" value="' . __( 'Test Cache', 'wp-super-cache' ) . '" /></div>';
wp_nonce_field('wp-cache');
@@ -1179,9 +1180,9 @@ function wsc_mod_rewrite() {
if ( isset( $wpmu_version ) || function_exists( 'is_multisite' ) && is_multisite() ) {
if ( false == wpsupercache_site_admin() )
return false;
- if ( function_exists( "is_main_site" ) && false == is_main_site() || function_exists( 'is_main_blog' ) && false == is_main_blog() ) {
+ if ( false == is_main_site() ) {
global $current_site;
- $protocol = ( 'on' == strtolower( $_SERVER['HTTPS' ] ) ) ? 'https://' : 'http://';
+ $protocol = ( isset( $_SERVER['HTTPS' ] ) && 'on' == strtolower( $_SERVER['HTTPS' ] ) ) ? 'https://' : 'http://';
if ( isset( $wpmu_version ) ) {
$link_to_admin = admin_url( "wpmu-admin.php?page=wpsupercache" );
} else {
@@ -1192,7 +1193,7 @@ function wsc_mod_rewrite() {
}
}
- if ( function_exists( "is_main_site" ) && false == is_main_site() || function_exists( 'is_main_blog' ) && false == is_main_blog() )
+ if ( false == is_main_site() )
return true;
?>
<a name="modrewrite"></a><fieldset class="options">
@@ -1488,7 +1489,7 @@ function wp_cache_edit_max_time () {
$cache_gc_email_me = 0;
wp_cache_replace_line('^ *\$cache_gc_email_me', "\$cache_gc_email_me = $cache_gc_email_me;", $wp_cache_config_file);
}
- if ( $_POST[ 'cache_schedule_type' ] == 'interval' && isset( $_POST['cache_time_interval'] ) && $valid_nonce ) {
+ if ( isset( $_POST['cache_time_interval'] ) && $_POST[ 'cache_schedule_type' ] == 'interval' && $valid_nonce ) {
wp_clear_scheduled_hook( 'wp_cache_gc' );
$cache_schedule_type = 'interval';
if ( (int)$_POST[ 'cache_time_interval' ] == 0 )
@@ -1500,11 +1501,11 @@ function wp_cache_edit_max_time () {
} elseif ( $valid_nonce ) { // clock
wp_clear_scheduled_hook( 'wp_cache_gc' );
$cache_schedule_type = 'time';
- if ( $_POST[ 'cache_scheduled_time' ] == '' )
+ if ( empty($_POST[ 'cache_scheduled_time' ]) )
$_POST[ 'cache_scheduled_time' ] = '00:00';
$cache_scheduled_time = $_POST[ 'cache_scheduled_time' ];
$schedules = wp_get_schedules();
- if ( isset( $schedules[ $_POST[ 'cache_schedule_interval' ] ] ) )
+ if ( isset( $_POST[ 'cache_schedule_interval' ] ) && isset( $schedules[ $_POST[ 'cache_schedule_interval' ] ] ) )
$cache_schedule_interval = $_POST[ 'cache_schedule_interval' ];
wp_schedule_single_event( strtotime( $cache_scheduled_time ), 'wp_cache_gc' );
wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file);
@@ -1639,17 +1640,19 @@ function wp_cache_edit_rejected_ua() {
function wp_cache_edit_rejected_pages() {
global $wp_cache_config_file, $valid_nonce, $wp_cache_pages;
- if ( isset( $_POST[ 'wp_edit_rejected_pages' ] ) && $valid_nonce ) {
- $pages = array( 'single', 'pages', 'archives', 'tag', 'frontpage', 'home', 'category', 'feed', 'author', 'search' );
- foreach( $pages as $page ) {
+ $pages = array( 'single', 'pages', 'archives', 'tag', 'frontpage', 'home', 'category', 'feed', 'author', 'search' );
+ foreach( $pages as $page ) {
+ if ( isset( $_POST[ 'wp_edit_rejected_pages' ] ) && $valid_nonce ) {
if ( isset( $_POST[ 'wp_cache_pages' ][ $page ] ) ) {
$value = 1;
} else {
$value = 0;
}
wp_cache_replace_line('^ *\$wp_cache_pages\[ "' . $page . '" \]', "\$wp_cache_pages[ \"{$page}\" ] = $value;", $wp_cache_config_file);
- $wp_cache_pages[ $page ] = $value;
+ } else {
+ $value = 0;
}
+ $wp_cache_pages[ $page ] = $value;
}
echo '<a name="rejectpages"></a>';
@@ -2198,7 +2201,7 @@ function wp_cache_files() {
echo "<li>" . sprintf( __( '%s Expired Pages', 'wp-super-cache' ), intval( $cache_stats[ 'supercache' ][ 'expired' ] / $divisor ) ) . "</li></ul>";
if ( $valid_nonce && array_key_exists('listfiles', $_GET) && $_GET[ 'listfiles' ] ) {
echo "<div style='padding: 10px; border: 1px solid #333; height: 400px; width: 90%; overflow: auto'>";
- if ( is_array( $cached_list ) && !empty( $cached_list ) ) {
+ if ( !empty( $cached_list ) && is_array( $cached_list ) ) {
echo "<h4>" . __( 'Fresh WP-Cached Files', 'wp-super-cache' ) . "</h4>";
echo "<table class='widefat'><tr><th>#</th><th>" . __( 'URI', 'wp-super-cache' ) . "</th><th>" . __( 'Key', 'wp-super-cache' ) . "</th><th>" . __( 'Age', 'wp-super-cache' ) . "</th><th>" . __( 'Delete', 'wp-super-cache' ) . "</th></tr>";
$c = 1;
@@ -2214,7 +2217,7 @@ function wp_cache_files() {
}
echo "</table>";
}
- if ( is_array( $expired_list ) && !empty( $expired_list ) ) {
+ if ( !empty( $expired_list ) && is_array( $expired_list ) ) {
echo "<h4>" . __( 'Stale WP-Cached Files', 'wp-super-cache' ) . "</h4>";
echo "<table class='widefat'><tr><th>#</th><th>" . __( 'URI', 'wp-super-cache' ) . "</th><th>" . __( 'Key', 'wp-super-cache' ) . "</th><th>" . __( 'Age', 'wp-super-cache' ) . "</th><th>" . __( 'Delete', 'wp-super-cache' ) . "</th></tr>";
$c = 1;
@@ -3007,4 +3010,16 @@ function supercache_admin_bar_render() {
}
add_action( 'wp_before_admin_bar_render', 'supercache_admin_bar_render' );
+// backwards compatibility for is_main_blog
+if ( !function_exists( 'is_main_site' ) ) {
+ function is_main_site() {
+ if ( function_exists( 'is_main_blog' ) ) {
+ return is_main_blog();
+ } else {
+ // if the function doesn't exist assume an old single install.
+ return true;
+ }
+ }
+}
+
?>
@romulodl
Copy link

Thank you very much for this!
I've applied on my env and looks great!

@peterchester
Copy link
Author

My pleasure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment