$autoptimize_ccss_options['ao_ccss_queue_raw'] = get_option( 'autoptimize_ccss_queue', false ); $autoptimize_ccss_options['ao_ccss_viewport'] = get_option( 'autoptimize_ccss_viewport', false ); $autoptimize_ccss_options['ao_ccss_finclude'] = get_option( 'autoptimize_ccss_finclude', false ); $autoptimize_ccss_options['ao_ccss_rtimelimit'] = get_option( 'autoptimize_ccss_rtimelimit', '30' ); $autoptimize_ccss_options['ao_ccss_noptimize'] = get_option( 'autoptimize_ccss_noptimize', false ); $autoptimize_ccss_options['ao_ccss_debug'] = get_option( 'autoptimize_ccss_debug', false ); $autoptimize_ccss_options['ao_ccss_key'] = get_option( 'autoptimize_ccss_key' ); $autoptimize_ccss_options['ao_ccss_keyst'] = get_option( 'autoptimize_ccss_keyst' ); $autoptimize_ccss_options['ao_ccss_loggedin'] = get_option( 'autoptimize_ccss_loggedin', '1' ); $autoptimize_ccss_options['ao_ccss_forcepath'] = get_option( 'autoptimize_ccss_forcepath', '1' ); $autoptimize_ccss_options['ao_ccss_servicestatus'] = get_option( 'autoptimize_service_availablity' ); $autoptimize_ccss_options['ao_ccss_deferjquery'] = get_option( 'autoptimize_ccss_deferjquery', false ); $autoptimize_ccss_options['ao_ccss_domain'] = get_option( 'autoptimize_ccss_domain' ); $autoptimize_ccss_options['ao_ccss_unloadccss'] = get_option( 'autoptimize_ccss_unloadccss', false ); if ( strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'http' ) === false && strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'uggc' ) === 0 ) { $autoptimize_ccss_options['ao_ccss_domain'] = str_rot13( $autoptimize_ccss_options['ao_ccss_domain'] ); } elseif ( strpos( $autoptimize_ccss_options['ao_ccss_domain'], 'http' ) !== false ) { // not rot13'ed yet, do so now (goal; avoid migration plugins change the bound domain). update_option( 'autoptimize_ccss_domain', str_rot13( $autoptimize_ccss_options['ao_ccss_domain'] ) ); } // Setup the rules array. if ( empty( $autoptimize_ccss_options['ao_ccss_rules_raw'] ) ) { $autoptimize_ccss_options['ao_ccss_rules']['paths'] = array(); $autoptimize_ccss_options['ao_ccss_rules']['types'] = array(); } else { $autoptimize_ccss_options['ao_ccss_rules'] = json_decode( $autoptimize_ccss_options['ao_ccss_rules_raw'], true ); } // Setup the queue array. if ( empty( $autoptimize_ccss_options['ao_ccss_queue_raw'] ) ) { $autoptimize_ccss_options['ao_ccss_queue'] = array(); } else { $autoptimize_ccss_options['ao_ccss_queue'] = json_decode( $autoptimize_ccss_options['ao_ccss_queue_raw'], true ); } // Override API key if constant is defined. if ( defined( 'AUTOPTIMIZE_CRITICALCSS_API_KEY' ) ) { $autoptimize_ccss_options['ao_ccss_key'] = AUTOPTIMIZE_CRITICALCSS_API_KEY; } } return $autoptimize_ccss_options; } public function on_upgrade() { global $ao_ccss_key; // Create the cache directory if it doesn't exist already. if ( ! file_exists( AO_CCSS_DIR ) ) { mkdir( AO_CCSS_DIR, 0755, true ); } // Create a scheduled event for the queue. if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_queue' ) ) { wp_schedule_event( time(), apply_filters( 'ao_ccss_queue_schedule', 'ao_ccss' ), 'ao_ccss_queue' ); } // Create a scheduled event for log maintenance. if ( isset( $ao_ccss_key ) && ! empty( $ao_ccss_key ) && ! wp_next_scheduled( 'ao_ccss_maintenance' ) ) { wp_schedule_event( time(), 'twicedaily', 'ao_ccss_maintenance' ); } } public function check_upgrade() { $db_version = get_option( 'autoptimize_ccss_version', '' ); if ( AO_CCSS_VER !== $db_version ) { // check schedules & re-schedule if needed. $this->on_upgrade(); // and update db_version. update_option( 'autoptimize_ccss_version', AO_CCSS_VER ); } } public function ao_ccss_interval( $schedules ) { // Let interval be configurable. if ( ! defined( 'AO_CCSS_DEBUG_INTERVAL' ) ) { $intsec = 600; } else { $intsec = AO_CCSS_DEBUG_INTERVAL; if ( $intsec >= 120 ) { $inttxt = $intsec / 60 . ' minutes'; } else { $inttxt = $intsec . ' second(s)'; } autoptimizeCriticalCSSCore::ao_ccss_log( 'Using custom WP-Cron interval of ' . $inttxt, 3 ); } // Attach interval to schedule. $schedules['ao_ccss'] = array( 'interval' => $intsec, 'display' => __( 'Autoptimize CriticalCSS' ), ); return $schedules; } }