Skip to content

Commit 1ae4d32

Browse files
authored
fix for empty args
1 parent dbc518c commit 1ae4d32

File tree

1 file changed

+60
-60
lines changed

1 file changed

+60
-60
lines changed

cronplus.php

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -9,78 +9,78 @@
99
*/
1010
// Exit if accessed directly
1111
if ( !defined( 'ABSPATH' ) ) {
12-
exit;
12+
exit;
1313
}
1414

1515
/**
1616
* * Add and remove Cron job in WordPress easily!
1717
*/
1818
class CronPlus {
1919

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;
2727

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+
);
4242

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+
}
4848

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+
}
6163
}
62-
}
63-
}
6464

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+
}
7474

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+
}
8585

8686
}

0 commit comments

Comments
 (0)