| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) die('No direct access allowed'); |
| 3 |
|
| 4 |
if (!class_exists('WP_Optimize_404_Detector_Cron')) : |
| 5 |
|
| 6 |
class WP_Optimize_404_Detector_Cron { |
| 7 |
|
| 8 |
/** |
| 9 |
* Class constructor |
| 10 |
*/ |
| 11 |
private function __construct() { |
| 12 |
$this->initialize(); |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Initialize the class as a singleton |
| 17 |
* |
| 18 |
* @return WP_Optimize_404_Detector_Cron |
| 19 |
*/ |
| 20 |
public static function get_instance() { |
| 21 |
static $_instance = null; |
| 22 |
if (null === $_instance) { |
| 23 |
$_instance = new self(); |
| 24 |
} |
| 25 |
return $_instance; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Initialize class actions |
| 30 |
*/ |
| 31 |
public function initialize() { |
| 32 |
if (WP_Optimize()->get_options()->get_option('404_detector')) { |
| 33 |
$this->setup_cron_event(); |
| 34 |
} else { |
| 35 |
$this->remove_cron_event(); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Schedule cron event |
| 41 |
*/ |
| 42 |
private function setup_cron_event() { |
| 43 |
if (!wp_next_scheduled('wpo_prune_404_log')) { |
| 44 |
wp_schedule_event(time(), 'wpo_daily', 'wpo_prune_404_log'); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Remove scheduled cron event |
| 50 |
*/ |
| 51 |
private function remove_cron_event() { |
| 52 |
wp_clear_scheduled_hook('wpo_prune_404_log'); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
endif; |
| 57 |
|