Skip to content

Commit

Permalink
Merge pull request #7 from mannion007/apply_extract_method
Browse files Browse the repository at this point in the history
Refactor - Apply extract method
  • Loading branch information
Mte90 authored Sep 29, 2017
2 parents eda6378 + 5572f82 commit 1d3fc67
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions cronplus.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,9 @@ function __construct( $args ) {
* @return void
*/
public function schedule_event() {
$find = false;
$crons = _get_cron_array();
if ( !empty( $crons ) ) {
foreach ( $crons as $timestamp => $cron ) {
if ( isset( $cron[ $this->args[ 'name' ] ] ) ) {
$find = true;
}
if ($this->isScheduled($this->args['name'], _get_cron_array())) {
return;
}
}
if ( !$find ) {
if ( $this->args[ 'run_on_creation' ] ) {
call_user_func( $this->args[ 'cb' ], $this->args[ 'args' ] );
}
Expand All @@ -84,7 +77,6 @@ public function schedule_event() {
$sites[] = get_current_blog_id();
update_site_option( $this->args[ 'name' ] . '_sites', $sites );
}
}
}

/**
Expand Down Expand Up @@ -137,4 +129,24 @@ public function deactivate() {
delete_site_option( $this->args[ 'name' ] . '_sites' );
}

/**
* @param string $name
* @param array $crons
* @return bool
*/
private function isScheduled($name, $crons)
{
if(empty($crons)) {
return false;
}

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

return false;
}

}

0 comments on commit 1d3fc67

Please sign in to comment.