| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('WPO_VERSION')) die('No direct access allowed'); |
| 4 |
|
| 5 |
if (!class_exists('WPO_WebP_Cron_Scheduler')) : |
| 6 |
|
| 7 |
class WPO_WebP_Cron_Scheduler { |
| 8 |
|
| 9 |
/** |
| 10 |
* Constructor |
| 11 |
*/ |
| 12 |
private function __construct() { |
| 13 |
$this->setup_cron_event(); |
| 14 |
add_action('wpo_reset_webp_conversion_test_result', array($this, 'reset_webp_conversion_flags')); |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Returns singleton instance of this class |
| 19 |
* |
| 20 |
* @return WPO_WebP_Cron_Scheduler Singleton Instance |
| 21 |
*/ |
| 22 |
public static function get_instance() { |
| 23 |
static $instance = null; |
| 24 |
if (null === $instance) { |
| 25 |
$instance = new self(); |
| 26 |
} |
| 27 |
return $instance; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Setup cron event to reset webp conversion test result |
| 32 |
*/ |
| 33 |
private function setup_cron_event() { |
| 34 |
if (!wp_next_scheduled('wpo_reset_webp_conversion_test_result')) { |
| 35 |
wp_schedule_event(time(), 'wpo_daily', 'wpo_reset_webp_conversion_test_result'); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Reset all webp conversion flags |
| 41 |
*/ |
| 42 |
public function reset_webp_conversion_flags() { |
| 43 |
WP_Optimize()->get_webp_instance()->reset_webp_serving_method(); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
endif; |
| 48 |
|