WordPress.org

Plugin Directory

Changeset 581266


Ignore:
Timestamp:
08/03/12 09:57:36 (21 months ago)
Author:
donncha
Message:
  • Added warning if garbage collection wasn't enabled
  • schedule watcher job when GC form is submitted
  • Enable GC when using the easy settings page
File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-super-cache/trunk/wp-cache.php

    r578009 r581266  
    157157function wp_cache_manager_error_checks() { 
    158158    global $wpmu_version, $wp_cache_debug, $wp_cache_cron_check, $cache_enabled, $super_cache_enabled, $wp_cache_config_file, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_mobile_enabled, $wp_cache_mod_rewrite, $cache_path; 
    159     global $dismiss_htaccess_warning, $dismiss_readable_warning; 
     159    global $dismiss_htaccess_warning, $dismiss_readable_warning, $dismiss_gc_warning, $wp_cache_shutdown_gc; 
    160160 
    161161    if ( !wpsupercache_site_admin() ) 
     
    252252 
    253253    $valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false; 
     254    // Check that garbage collection is running 
     255    if ( $valid_nonce && $_POST[ 'action' ] == 'dismiss_gc_warning' ) { 
     256        wp_cache_replace_line('^ *\$dismiss_gc_warning', "\$dismiss_gc_warning = 1;", $wp_cache_config_file); 
     257        $dismiss_gc_warning = 1; 
     258    } elseif ( !isset( $dismiss_gc_warning ) ) { 
     259        $dismiss_gc_warning = 0; 
     260    } 
     261    if ( $cache_enabled && ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) && function_exists( 'get_gc_flag' ) ) { 
     262        $gc_flag = get_gc_flag(); 
     263        if ( $dismiss_gc_warning == 0 ) { 
     264            if ( false == maybe_stop_gc( $gc_flag ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) { 
     265                ?><div id="message" class="updated fade"><h3><?php _e( 'Warning! Garbage collection is not scheduled!', 'wp-super-cache' ); ?></h3> 
     266                <p><?php _e( 'Garbage collection by this plugin clears out expired and old cached pages on a regular basis. Use <a href="#expirytime">this form</a> to enable it.', 'wp-super-cache' ); ?> </p> 
     267                <form action="" method="POST"> 
     268                <input type="hidden" name="action" value="dismiss_gc_warning" /> 
     269                <input type="hidden" name="page" value="wpsupercache" /> 
     270                <?php wp_nonce_field( 'wp-cache' ); ?> 
     271                <input type='submit' value='<?php _e( 'Dismiss', 'wp-super-cache' ); ?>' /> 
     272                </form> 
     273                <br /> 
     274                </div> 
     275                <?php 
     276            } 
     277        } 
     278    } 
     279 
    254280    // Server could be running as the owner of the wp-content directory.  Therefore, if it's 
    255281    // writable, issue a warning only if the permissions aren't 755. 
     
    359385        return false; 
    360386 
    361     // set up garbage collection with some default settings 
    362     if ( ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) { 
    363         if ( false == isset( $cache_schedule_type ) ) { 
    364             $cache_schedule_type = 'interval'; 
    365             $cache_time_interval = 600; 
    366             $cache_max_time = 1800; 
    367             wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file); 
    368             wp_cache_replace_line('^ *\$cache_time_interval', "\$cache_time_interval = '$cache_time_interval';", $wp_cache_config_file); 
    369             wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = '$cache_max_time';", $wp_cache_config_file); 
    370         } 
    371         wp_schedule_single_event( time() + 600, 'wp_cache_gc' ); 
    372     } 
    373     // schedule gc watcher 
    374     if ( false == wp_next_scheduled( 'wp_cache_gc_watcher' ) ) 
    375         wp_schedule_event( time()+600, 'hourly', 'wp_cache_gc_watcher' ); 
    376  
    377387    if ( false == isset( $cache_page_secret ) ) { 
    378388        $cache_page_secret = md5( date( 'H:i:s' ) . mt_rand() ); 
     
    403413            $_POST[ 'cache_rebuild_files' ] = 1; 
    404414            unset( $_POST[ 'cache_compression' ] ); 
     415            // 
     416            // set up garbage collection with some default settings 
     417            if ( ( !isset( $wp_cache_shutdown_gc ) || $wp_cache_shutdown_gc == 0 ) && false == wp_next_scheduled( 'wp_cache_gc' ) ) { 
     418                if ( false == isset( $cache_schedule_type ) ) { 
     419                    $cache_schedule_type = 'interval'; 
     420                    $cache_time_interval = 600; 
     421                    $cache_max_time = 1800; 
     422                    wp_cache_replace_line('^ *\$cache_schedule_type', "\$cache_schedule_type = '$cache_schedule_type';", $wp_cache_config_file); 
     423                    wp_cache_replace_line('^ *\$cache_time_interval', "\$cache_time_interval = '$cache_time_interval';", $wp_cache_config_file); 
     424                    wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = '$cache_max_time';", $wp_cache_config_file); 
     425                } 
     426                wp_schedule_single_event( time() + 600, 'wp_cache_gc' ); 
     427            } 
     428 
    405429        } else { 
    406430            unset( $_POST[ 'wp_cache_status' ] ); 
    407431            $_POST[ 'super_cache_enabled' ] = 0; 
     432            wp_clear_scheduled_hook( 'wp_cache_check_site_hook' ); 
     433            wp_clear_scheduled_hook( 'wp_cache_gc' ); 
     434            wp_clear_scheduled_hook( 'wp_cache_gc_watcher' ); 
    408435        } 
    409436    } 
     
    15431570        $cache_max_time = (int)$_POST['wp_max_time']; 
    15441571        wp_cache_replace_line('^ *\$cache_max_time', "\$cache_max_time = $cache_max_time;", $wp_cache_config_file); 
     1572        // schedule gc watcher 
     1573        if ( false == wp_next_scheduled( 'wp_cache_gc_watcher' ) ) 
     1574            wp_schedule_event( time()+600, 'hourly', 'wp_cache_gc_watcher' ); 
    15451575    } 
    15461576 
     
    18641894    global $wp_cache_config_file, $cache_enabled; 
    18651895 
     1896    wp_clear_scheduled_hook( 'wp_cache_check_site_hook' ); 
     1897    wp_clear_scheduled_hook( 'wp_cache_gc' ); 
     1898    wp_clear_scheduled_hook( 'wp_cache_gc_watcher' ); 
    18661899    if (wp_cache_replace_line('^ *\$cache_enabled', '$cache_enabled = false;', $wp_cache_config_file)) { 
    18671900        $cache_enabled = false; 
Note: See TracChangeset for help on using the changeset viewer.