Skip to content

Commit

Permalink
fix for empty args
Browse files Browse the repository at this point in the history
  • Loading branch information
Mte90 authored Jun 23, 2017
1 parent dbc518c commit 1ae4d32
Showing 1 changed file with 60 additions and 60 deletions.
120 changes: 60 additions & 60 deletions cronplus.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,78 +9,78 @@
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) {
exit;
exit;
}

/**
* * Add and remove Cron job in WordPress easily!
*/
class CronPlus {

/**
* Args of the class
*
* @var array
* @since 1.0.0
*/
private $args;
/**
* Args of the class
*
* @var array
* @since 1.0.0
*/
private $args;

/**
* Construct the class parameter
*
* @param array $args Parameters of class.
* @return void
*/
function __construct( $args ) {
$defaults = array(
'recurrence' => 'hourly', // Hourly,daily,twicedaily,weekly,monthly
'name' => 'cronplus',
'schedule' => 'schedule', // Schedule or single,
'cb' => '',
'args' => '' // Args passed to the hook
);
/**
* Construct the class parameter
*
* @param array $args Parameters of class.
* @return void
*/
function __construct( $args ) {
$defaults = array(
'recurrence' => 'hourly', // Hourly,daily,twicedaily,weekly,monthly
'name' => 'cronplus',
'schedule' => 'schedule', // Schedule or single,
'cb' => '',
'args' => array( '' ) // Args passed to the hook
);

$this->args = wp_parse_args( $args, $defaults );
if ( isset( $this->args['cb'] ) && isset( $this->args['name'] ) ) {
add_action( $this->args[ 'name' ], $this->args['cb'] );
}
}
$this->args = wp_parse_args( $args, $defaults );
if ( isset( $this->args[ 'cb' ] ) && isset( $this->args[ 'name' ] ) ) {
add_action( $this->args[ 'name' ], $this->args[ 'cb' ] );
}
}

/**
* Schedule the event
*
* @since 1.0.0
* @return void
*/
public function schedule_event() {
if ( !wp_next_scheduled( $this->args[ 'name' ] ) ) {
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' ] );
/**
* Schedule the event
*
* @since 1.0.0
* @return void
*/
public function schedule_event() {
if ( !wp_next_scheduled( $this->args[ 'name' ] ) ) {
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' ] );
}
}
}
}
}

/**
* Clear the schedule
*
* @since 1.0.0
* @return void
*/
public function clear_schedule() {
wp_clear_scheduled_hook( $this->args[ 'name' ] );
}
/**
* Clear the schedule
*
* @since 1.0.0
* @return void
*/
public function clear_schedule() {
wp_clear_scheduled_hook( $this->args[ 'name' ] );
}

/**
* UnSchedule the event
*
* @since 1.0.0
* @return void
*/
public function unschedule_event() {
$timestamp = wp_next_scheduled( $this->args[ 'name' ] );
wp_unschedule_event( $timestamp, $this->args[ 'name' ] );
}
/**
* UnSchedule the event
*
* @since 1.0.0
* @return void
*/
public function unschedule_event() {
$timestamp = wp_next_scheduled( $this->args[ 'name' ] );
wp_unschedule_event( $timestamp, $this->args[ 'name' ] );
}

}

0 comments on commit 1ae4d32

Please sign in to comment.