@@ -55,28 +55,31 @@ function __construct( $args ) {
5555 /**
5656 * Schedule the event
5757 *
58- * @since 1.0.0
58+ * @since 1.0.0
59+ *
5960 * @return void
6061 */
6162 public function schedule_event () {
62- if ($ this ->isScheduled ( $ this ->args ['name ' ], _get_cron_array ()) ) {
63- return ;
64- }
65- if ( $ this ->args [ 'run_on_creation ' ] ) {
66- call_user_func ( $ this ->args [ 'cb ' ], $ this ->args [ 'args ' ] );
67- }
68- if ( $ this ->args [ 'schedule ' ] === 'schedule ' ) {
69- wp_schedule_event ( current_time ( 'timestamp ' ), $ this ->args [ 'recurrence ' ], $ this ->args [ 'name ' ], $ this ->args [ 'args ' ] );
70- } elseif ( $ this ->args [ 'schedule ' ] === 'single ' ) {
71- wp_schedule_single_event ( $ this ->args [ 'recurrence ' ], $ this ->args [ 'name ' ], $ this ->args [ 'args ' ] );
72- }
63+ if ( $ this ->is_scheduled ( $ this ->args [ 'name ' ] ) ) {
64+ return ;
65+ }
66+ if ( $ this ->args [ 'run_on_creation ' ] ) {
67+ call_user_func ( $ this ->args [ 'cb ' ], $ this ->args [ 'args ' ] );
68+ }
69+ if ( $ this ->args [ 'schedule ' ] === 'schedule ' ) {
70+ wp_schedule_event ( current_time ( 'timestamp ' ), $ this ->args [ 'recurrence ' ], $ this ->args [ 'name ' ], $ this ->args [ 'args ' ] );
71+ } elseif ( $ this ->args [ 'schedule ' ] === 'single ' ) {
72+ wp_schedule_single_event ( $ this ->args [ 'recurrence ' ], $ this ->args [ 'name ' ], $ this ->args [ 'args ' ] );
73+ }
7374
74- // Save all the site ids where is the corn for the deactivation
75- if ( is_multisite () && !wp_is_large_network () ) {
76- $ sites = ( array ) get_site_option ( $ this ->args [ 'name ' ] . '_sites ' , array () );
77- $ sites [] = get_current_blog_id ();
78- update_site_option ( $ this ->args [ 'name ' ] . '_sites ' , $ sites );
79- }
75+ // Save all the site ids where is the corn for the deactivation
76+ if ( is_multisite () && !wp_is_large_network () ) {
77+ $ sites = ( array ) get_site_option ( $ this ->args [ 'name ' ] . '_sites ' , array () );
78+ $ sites [] = get_current_blog_id ();
79+ update_site_option ( $ this ->args [ 'name ' ] . '_sites ' , $ sites );
80+ }
81+
82+ return true ;
8083 }
8184
8285 /**
@@ -130,18 +133,21 @@ public function deactivate() {
130133 }
131134
132135 /**
136+ * Check if the event is scheduled
137+ *
133138 * @param string $name
134139 * @param array $crons
135140 * @return bool
136141 */
137- private function isScheduled ($ name , $ crons )
138- {
139- if (empty ($ crons )) {
142+ private function is_scheduled ( $ name ) {
143+ $ crons = _get_cron_array ();
144+
145+ if ( empty ( $ crons ) ) {
140146 return false ;
141147 }
142148
143- foreach ($ crons as $ cron ) {
144- if (isset ($ cron [$ name]) ) {
149+ foreach ( $ crons as $ cron ) {
150+ if ( isset ( $ cron [ $ name ] ) ) {
145151 return true ;
146152 }
147153 }
0 commit comments