theme-template-library
3 weeks ago
class-advanced-import-activator.php
4 years ago
class-advanced-import-cron.php
4 years ago
class-advanced-import-deactivator.php
3 weeks ago
class-advanced-import-i18n.php
3 weeks ago
class-advanced-import-loader.php
5 years ago
class-advanced-import.php
3 months ago
class-theme-template-library-base.php
3 weeks ago
functions-advanced-import.php
3 weeks ago
index.php
5 years ago
class-advanced-import-cron.php
92 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Advanced Import Cron |
| 4 | * |
| 5 | * @package Advanced Import |
| 6 | * @subpackage Classes/Cron |
| 7 | * @since 3.2.1 |
| 8 | */ |
| 9 | |
| 10 | // Exit if accessed directly |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit; |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Advanced_Import_Cron Class |
| 17 | * |
| 18 | * This class handles scheduled events |
| 19 | * |
| 20 | * @since 3.2.1 |
| 21 | */ |
| 22 | class Advanced_Import_Cron { |
| 23 | |
| 24 | /** |
| 25 | * Init WordPress hook |
| 26 | * |
| 27 | * @since 3.2.1 |
| 28 | * @see Advanced_Import_Cron::weekly_events() |
| 29 | */ |
| 30 | public function __construct() { |
| 31 | add_filter( 'cron_schedules', array( $this, 'add_schedules' ) ); |
| 32 | add_action( 'wp', array( $this, 'schedule_events' ) ); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Registers new cron schedules |
| 37 | * |
| 38 | * @since 3.2.1 |
| 39 | * |
| 40 | * @param array $schedules |
| 41 | * @return array |
| 42 | */ |
| 43 | public function add_schedules( $schedules = array() ) { |
| 44 | /*Adds once weekly to the existing schedules*/ |
| 45 | $schedules['weekly'] = array( |
| 46 | 'interval' => 604800, |
| 47 | 'display' => __( 'Once Weekly', 'advanced-import' ), |
| 48 | ); |
| 49 | |
| 50 | return $schedules; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Schedules our events |
| 55 | * |
| 56 | * @since 3.2.1 |
| 57 | * @return void |
| 58 | */ |
| 59 | public function schedule_events() { |
| 60 | $this->weekly_events(); |
| 61 | $this->daily_events(); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Schedule weekly events |
| 66 | * |
| 67 | * @access private |
| 68 | * @since 3.2.1 |
| 69 | * @return void |
| 70 | */ |
| 71 | private function weekly_events() { |
| 72 | if ( ! wp_next_scheduled( 'advanced_import_weekly_scheduled_events' ) ) { |
| 73 | wp_schedule_event( time(), 'weekly', 'advanced_import_weekly_scheduled_events' ); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Schedule daily events |
| 79 | * |
| 80 | * @access private |
| 81 | * @since 3.2.1 |
| 82 | * @return void |
| 83 | */ |
| 84 | private function daily_events() { |
| 85 | if ( ! wp_next_scheduled( 'advanced_import_daily_scheduled_events' ) ) { |
| 86 | wp_schedule_event( time(), 'daily', 'advanced_import_daily_scheduled_events' ); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | } |
| 91 | $advanced_import_cron = new Advanced_Import_Cron(); |
| 92 |