' ); } if ( ! file_exists( $htaccess ) ) { wpsco_write_file( $htaccess, "\nDeny from all\n\nOptions -Indexes" ); } // Grant capability to administrators. $role = get_role( 'administrator' ); if ( $role ) { $role->add_cap( WPSCO_CAPABILITY ); } // Set default options if not existing. if ( false === get_option( 'wpsco_settings' ) ) { update_option( 'wpsco_settings', wpsco_get_default_settings() ); } // Set cache version. if ( false === get_option( 'wpsco_cache_version' ) ) { update_option( 'wpsco_cache_version', md5( (string) time() ) ); } // Schedule cron events. if ( ! wp_next_scheduled( 'wpsco_cache_cleanup' ) ) { wp_schedule_event( time(), 'daily', 'wpsco_cache_cleanup' ); } if ( ! wp_next_scheduled( 'wpsco_expired_transients_cleanup' ) ) { wp_schedule_event( time(), 'twicedaily', 'wpsco_expired_transients_cleanup' ); } // Flush rewrite rules. flush_rewrite_rules(); } register_activation_hook( __FILE__, 'wpsco_activate' ); /** * Deactivation hook. */ function wpsco_deactivate() { // Clear scheduled events. wp_clear_scheduled_hook( 'wpsco_cache_cleanup' ); wp_clear_scheduled_hook( 'wpsco_expired_transients_cleanup' ); wp_clear_scheduled_hook( 'wpsco_cache_warming' ); wp_clear_scheduled_hook( 'wpsco_image_optimization_queue' ); // Flush rewrite rules. flush_rewrite_rules(); } register_deactivation_hook( __FILE__, 'wpsco_deactivate' ); /** * Initialize the plugin. */ function wpsco_init() { // Auto-flush stale caches upon activating or upgrading to 1.4.1. if ( get_option( 'wpsco_version' ) !== '1.4.1' ) { update_option( 'wpsco_version', '1.4.1' ); delete_option( 'wpsco_speed_scores' ); delete_transient( 'wpsco_speed_audit_mobile_' . md5( home_url() ) ); delete_transient( 'wpsco_speed_audit_desktop_' . md5( home_url() ) ); wpsco_increment_cache_version(); if ( function_exists( 'wpsco_delete_dir_contents' ) ) { wpsco_delete_dir_contents( wpsco_get_cache_dir( 'html/' ) ); wpsco_delete_dir_contents( wpsco_get_cache_dir( 'css/' ) ); wpsco_delete_dir_contents( wpsco_get_cache_dir( 'js/' ) ); } } // Initialize main plugin class. WPSCO_Plugin::get_instance(); } add_action( 'plugins_loaded', 'wpsco_init', 5 ); /** * WP-CLI commands. */ if ( defined( 'WP_CLI' ) && WP_CLI ) { require_once WPSCO_PLUGIN_DIR . 'includes/class-cli.php'; }