Skip to content

Commit

Permalink
bump new release
Browse files Browse the repository at this point in the history
  • Loading branch information
Mte90 committed Sep 29, 2017
1 parent 1d3fc67 commit 49d5ca9
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions cronplus.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,31 @@ function __construct( $args ) {
/**
* Schedule the event
*
* @since 1.0.0
* @since 1.0.0
*
* @return void
*/
public function schedule_event() {
if ($this->isScheduled($this->args['name'], _get_cron_array())) {
return;
}
if ( $this->args[ 'run_on_creation' ] ) {
call_user_func( $this->args[ 'cb' ], $this->args[ 'args' ] );
}
if ( $this->args[ 'schedule' ] === 'schedule' ) {
wp_schedule_event( current_time( 'timestamp' ), $this->args[ 'recurrence' ], $this->args[ 'name' ], $this->args[ 'args' ] );
} elseif ( $this->args[ 'schedule' ] === 'single' ) {
wp_schedule_single_event( $this->args[ 'recurrence' ], $this->args[ 'name' ], $this->args[ 'args' ] );
}
if ( $this->is_scheduled( $this->args[ 'name' ] ) ) {
return;
}
if ( $this->args[ 'run_on_creation' ] ) {
call_user_func( $this->args[ 'cb' ], $this->args[ 'args' ] );
}
if ( $this->args[ 'schedule' ] === 'schedule' ) {
wp_schedule_event( current_time( 'timestamp' ), $this->args[ 'recurrence' ], $this->args[ 'name' ], $this->args[ 'args' ] );
} elseif ( $this->args[ 'schedule' ] === 'single' ) {
wp_schedule_single_event( $this->args[ 'recurrence' ], $this->args[ 'name' ], $this->args[ 'args' ] );
}

// Save all the site ids where is the corn for the deactivation
if ( is_multisite() && !wp_is_large_network() ) {
$sites = ( array ) get_site_option( $this->args[ 'name' ] . '_sites', array() );
$sites[] = get_current_blog_id();
update_site_option( $this->args[ 'name' ] . '_sites', $sites );
}
// Save all the site ids where is the corn for the deactivation
if ( is_multisite() && !wp_is_large_network() ) {
$sites = ( array ) get_site_option( $this->args[ 'name' ] . '_sites', array() );
$sites[] = get_current_blog_id();
update_site_option( $this->args[ 'name' ] . '_sites', $sites );
}

return true;
}

/**
Expand Down Expand Up @@ -130,18 +133,21 @@ public function deactivate() {
}

/**
* Check if the event is scheduled
*
* @param string $name
* @param array $crons
* @return bool
*/
private function isScheduled($name, $crons)
{
if(empty($crons)) {
private function is_scheduled( $name ) {
$crons = _get_cron_array();

if ( empty( $crons ) ) {
return false;
}

foreach ($crons as $cron) {
if (isset($cron[$name])) {
foreach ( $crons as $cron ) {
if ( isset( $cron[ $name ] ) ) {
return true;
}
}
Expand Down

0 comments on commit 49d5ca9

Please sign in to comment.