|
9 | 9 | */ |
10 | 10 | // Exit if accessed directly |
11 | 11 | if ( !defined( 'ABSPATH' ) ) { |
12 | | - exit; |
| 12 | + exit; |
13 | 13 | } |
14 | 14 |
|
15 | 15 | /** |
16 | 16 | * * Add and remove Cron job in WordPress easily! |
17 | 17 | */ |
18 | 18 | class CronPlus { |
19 | 19 |
|
20 | | - /** |
21 | | - * Args of the class |
22 | | - * |
23 | | - * @var array |
24 | | - * @since 1.0.0 |
25 | | - */ |
26 | | - private $args; |
| 20 | + /** |
| 21 | + * Args of the class |
| 22 | + * |
| 23 | + * @var array |
| 24 | + * @since 1.0.0 |
| 25 | + */ |
| 26 | + private $args; |
27 | 27 |
|
28 | | - /** |
29 | | - * Construct the class parameter |
30 | | - * |
31 | | - * @param array $args Parameters of class. |
32 | | - * @return void |
33 | | - */ |
34 | | - function __construct( $args ) { |
35 | | - $defaults = array( |
36 | | - 'recurrence' => 'hourly', // Hourly,daily,twicedaily,weekly,monthly |
37 | | - 'name' => 'cronplus', |
38 | | - 'schedule' => 'schedule', // Schedule or single, |
39 | | - 'cb' => '', |
40 | | - 'args' => '' // Args passed to the hook |
41 | | - ); |
| 28 | + /** |
| 29 | + * Construct the class parameter |
| 30 | + * |
| 31 | + * @param array $args Parameters of class. |
| 32 | + * @return void |
| 33 | + */ |
| 34 | + function __construct( $args ) { |
| 35 | + $defaults = array( |
| 36 | + 'recurrence' => 'hourly', // Hourly,daily,twicedaily,weekly,monthly |
| 37 | + 'name' => 'cronplus', |
| 38 | + 'schedule' => 'schedule', // Schedule or single, |
| 39 | + 'cb' => '', |
| 40 | + 'args' => array( '' ) // Args passed to the hook |
| 41 | + ); |
42 | 42 |
|
43 | | - $this->args = wp_parse_args( $args, $defaults ); |
44 | | - if ( isset( $this->args['cb'] ) && isset( $this->args['name'] ) ) { |
45 | | - add_action( $this->args[ 'name' ], $this->args['cb'] ); |
46 | | - } |
47 | | - } |
| 43 | + $this->args = wp_parse_args( $args, $defaults ); |
| 44 | + if ( isset( $this->args[ 'cb' ] ) && isset( $this->args[ 'name' ] ) ) { |
| 45 | + add_action( $this->args[ 'name' ], $this->args[ 'cb' ] ); |
| 46 | + } |
| 47 | + } |
48 | 48 |
|
49 | | - /** |
50 | | - * Schedule the event |
51 | | - * |
52 | | - * @since 1.0.0 |
53 | | - * @return void |
54 | | - */ |
55 | | - public function schedule_event() { |
56 | | - if ( !wp_next_scheduled( $this->args[ 'name' ] ) ) { |
57 | | - if ( $this->args[ 'schedule' ] === 'schedule' ) { |
58 | | - wp_schedule_event( current_time( 'timestamp' ), $this->args[ 'recurrence' ], $this->args[ 'name' ], $this->args[ 'args' ] ); |
59 | | - } elseif ( $this->args[ 'schedule' ] === 'single' ) { |
60 | | - wp_schedule_single_event( $this->args[ 'recurrence' ], $this->args[ 'name' ], $this->args[ 'args' ] ); |
| 49 | + /** |
| 50 | + * Schedule the event |
| 51 | + * |
| 52 | + * @since 1.0.0 |
| 53 | + * @return void |
| 54 | + */ |
| 55 | + public function schedule_event() { |
| 56 | + if ( !wp_next_scheduled( $this->args[ 'name' ] ) ) { |
| 57 | + if ( $this->args[ 'schedule' ] === 'schedule' ) { |
| 58 | + wp_schedule_event( current_time( 'timestamp' ), $this->args[ 'recurrence' ], $this->args[ 'name' ], $this->args[ 'args' ] ); |
| 59 | + } elseif ( $this->args[ 'schedule' ] === 'single' ) { |
| 60 | + wp_schedule_single_event( $this->args[ 'recurrence' ], $this->args[ 'name' ], $this->args[ 'args' ] ); |
| 61 | + } |
| 62 | + } |
61 | 63 | } |
62 | | - } |
63 | | - } |
64 | 64 |
|
65 | | - /** |
66 | | - * Clear the schedule |
67 | | - * |
68 | | - * @since 1.0.0 |
69 | | - * @return void |
70 | | - */ |
71 | | - public function clear_schedule() { |
72 | | - wp_clear_scheduled_hook( $this->args[ 'name' ] ); |
73 | | - } |
| 65 | + /** |
| 66 | + * Clear the schedule |
| 67 | + * |
| 68 | + * @since 1.0.0 |
| 69 | + * @return void |
| 70 | + */ |
| 71 | + public function clear_schedule() { |
| 72 | + wp_clear_scheduled_hook( $this->args[ 'name' ] ); |
| 73 | + } |
74 | 74 |
|
75 | | - /** |
76 | | - * UnSchedule the event |
77 | | - * |
78 | | - * @since 1.0.0 |
79 | | - * @return void |
80 | | - */ |
81 | | - public function unschedule_event() { |
82 | | - $timestamp = wp_next_scheduled( $this->args[ 'name' ] ); |
83 | | - wp_unschedule_event( $timestamp, $this->args[ 'name' ] ); |
84 | | - } |
| 75 | + /** |
| 76 | + * UnSchedule the event |
| 77 | + * |
| 78 | + * @since 1.0.0 |
| 79 | + * @return void |
| 80 | + */ |
| 81 | + public function unschedule_event() { |
| 82 | + $timestamp = wp_next_scheduled( $this->args[ 'name' ] ); |
| 83 | + wp_unschedule_event( $timestamp, $this->args[ 'name' ] ); |
| 84 | + } |
85 | 85 |
|
86 | 86 | } |
0 commit comments