Skip to content

Commit

Permalink
Check if set_transient() is set before using it. (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
donnchawp committed Jun 15, 2018
1 parent a7a5e92 commit 154eaf0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions wp-cache-phase2.php
Original file line number Diff line number Diff line change
Expand Up @@ -1062,11 +1062,15 @@ function wp_cache_setting( $field, $value ) {

function wp_cache_replace_line( $old, $new, $my_file ) {
if ( @is_file( $my_file ) == false ) {
set_transient( 'wpsc_config_error', 'config_file_missing', 10 );
if ( function_exists( 'set_transient' ) ) {
set_transient( 'wpsc_config_error', 'config_file_missing', 10 );
}
return false;
}
if (!is_writeable_ACLSafe($my_file)) {
set_transient( 'wpsc_config_error', 'config_file_ro', 10 );
if ( function_exists( 'set_transient' ) ) {
set_transient( 'wpsc_config_error', 'config_file_ro', 10 );
}
trigger_error( "Error: file $my_file is not writable." );
return false;
}
Expand All @@ -1082,7 +1086,9 @@ function wp_cache_replace_line( $old, $new, $my_file ) {
} else {
$c++;
if ( $c > 100 ) {
set_transient( 'wpsc_config_error', 'config_file_not_loaded', 10 );
if ( function_exists( 'set_transient' ) ) {
set_transient( 'wpsc_config_error', 'config_file_not_loaded', 10 );
}
trigger_error( "wp_cache_replace_line: Error - file $my_file could not be loaded." );
return false;
}
Expand All @@ -1097,7 +1103,9 @@ function wp_cache_replace_line( $old, $new, $my_file ) {

$fd = fopen( $my_file, 'w' );
if ( ! $fd ) {
set_transient( 'wpsc_config_error', 'config_file_ro', 10 );
if ( function_exists( 'set_transient' ) ) {
set_transient( 'wpsc_config_error', 'config_file_ro', 10 );
}
trigger_error( "wp_cache_replace_line: Error - could not write to $my_file" );
return false;
}
Expand Down

0 comments on commit 154eaf0

Please sign in to comment.