/home/edulekha/public_html/wp-content/plugins/css-optimizer/classlesses/bpminifycssCacheChecker.php
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

/* 
 * cachechecker code
 * 
 * daily cronned job (filter to change freq. + filter to disable)
 * checks if cachesize is > 0.5GB (filter to change maxsize)
 * if so an option is set
 * if that option is set, notice on admin is shown
 * 
 */

if (is_admin()) {
    add_action('plugins_loaded','ao_cachechecker_setup');
}

function ao_cachechecker_setup() {
    $doCacheCheck = (bool) apply_filters( 'bpminifycss_filter_cachecheck_do', true);
    $cacheCheckSchedule = wp_get_schedule( 'ao_cachechecker' );
    $AOCCfreq = apply_filters('bpminifycss_filter_cachecheck_frequency','daily');
    if (!in_array($AOCCfreq,array('hourly','daily','monthly'))) {
        $AOCCfreq='daily';
    }
    if ( $doCacheCheck && ( !$cacheCheckSchedule || $cacheCheckSchedule !== $AOCCfreq ) ) {
        wp_schedule_event(time(), $AOCCfreq, 'ao_cachechecker');
    } else if ( $cacheCheckSchedule && !$doCacheCheck ) {
        wp_clear_scheduled_hook( 'ao_cachechecker' );
    }
}

add_action('ao_cachechecker', 'ao_cachechecker_cronjob');
function ao_cachechecker_cronjob() {
    $maxSize = (int) apply_filters( "bpminifycss_filter_cachecheck_maxsize", 512000);
    $doCacheCheck = (bool) apply_filters( "bpminifycss_filter_cachecheck_do", true);
    $statArr=bpminifycssCache::stats(); 
    $cacheSize=round($statArr[1]/1024);
    if (($cacheSize>$maxSize) && ($doCacheCheck)) {
        update_option("bpminifycss_cachesize_notice",true);
        if (apply_filters('bpminifycss_filter_cachecheck_sendmail',true)) {
            $ao_mailto=apply_filters('bpminifycss_filter_cachecheck_mailto',get_option('admin_email',''));
            $ao_mailsubject=__('bpminifycss cache size warning','bpminifycss');
            $ao_mailbody=__('bpminifycss\'s cache size is getting big, consider purging the cache. Have a look at https://wordpress.org/plugins/bpminifycss/faq/ to see how you can keep the cache size under control.', 'bpminifycss');
            
            if (!empty($ao_mailto)) {
                $ao_mailresult=wp_mail($ao_mailto,$ao_mailsubject,$ao_mailbody);
                if (!$ao_mailresult) {
                    error_log("bpminifycss could not send cache size warning mail.");
                }
            }
        }
    }
}

add_action('admin_notices', 'bpminifycss_cachechecker_notice');
function bpminifycss_cachechecker_notice() {
    if ((bool) get_option("bpminifycss_cachesize_notice",false)) {
        echo '<div class="notice notice-warning"><p>';
        _e('<strong>bpminifycss\'s cache size is getting big</strong>, consider purging the cache. Have a look at <a href="https://wordpress.org/plugins/bpminifycss/faq/" target="_blank">the bpminifycss FAQ</a> to see how you can keep the cache size under control.', 'bpminifycss' );
        echo '</p></div>';
        update_option("bpminifycss_cachesize_notice",false);
    }
}