| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Surge |
| 4 |
* Plugin URI: https://github.com/kovshenin/surge |
| 5 |
* Description: A fast and simple page caching plugin for WordPress |
| 6 |
* Author: Konstantin Kovshenin |
| 7 |
* Author URI: https://konstantin.blog |
| 8 |
* Text Domain: surge |
| 9 |
* Domain Path: /languages |
| 10 |
* Version: 1.0.0 |
| 11 |
* |
| 12 |
* @package Surge |
| 13 |
*/ |
| 14 |
|
| 15 |
namespace Surge; |
| 16 |
|
| 17 |
// Attempt to cache this request if cache is on. |
| 18 |
if ( defined( 'WP_CACHE' ) && WP_CACHE ) { |
| 19 |
include_once( __DIR__ . '/include/cache.php' ); |
| 20 |
} |
| 21 |
|
| 22 |
// Load more files later when necessary. |
| 23 |
add_action( 'plugins_loaded', function() { |
| 24 |
if ( false === get_option( 'surge_installed', false ) ) { |
| 25 |
if ( add_option( 'surge_installed', 0 ) ) { |
| 26 |
require_once( __DIR__ . '/include/install.php' ); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
if ( wp_doing_cron() ) { |
| 31 |
include_once( __DIR__ . '/include/cron.php' ); |
| 32 |
} |
| 33 |
|
| 34 |
include_once( __DIR__ . '/include/invalidate.php' ); |
| 35 |
} ); |
| 36 |
|
| 37 |
// Site Health events |
| 38 |
add_filter( 'site_status_tests', function( $tests ) { |
| 39 |
include_once( __DIR__ . '/include/health.php' ); |
| 40 |
|
| 41 |
$tests['direct']['surge'] = [ |
| 42 |
'label' => 'Caching Test', |
| 43 |
'test' => '\Surge\health_test', |
| 44 |
]; |
| 45 |
|
| 46 |
return $tests; |
| 47 |
} ); |
| 48 |
|
| 49 |
// Schedule cron events. |
| 50 |
add_action( 'shutdown', function() { |
| 51 |
if ( ! wp_next_scheduled( 'surge_delete_expired' ) ) { |
| 52 |
wp_schedule_event( time(), 'hourly', 'surge_delete_expired' ); |
| 53 |
} |
| 54 |
} ); |
| 55 |
|
| 56 |
// Re-install on activation |
| 57 |
register_activation_hook( __FILE__, function() { |
| 58 |
delete_option( 'surge_installed' ); |
| 59 |
} ); |
| 60 |
|