/**
  * @param string $hook The hook to trigger when this action runs
  * @param array $args Args to pass when the hook is triggered
  * @param int $first Unix timestamp for the first run
  * @param int $schedule A cron definition string
  * @param string $group A group to put the action in
  *
  * @return string The ID of the stored action
  */
 public function cron($hook, $args = array(), $first = NULL, $schedule = NULL, $group = '')
 {
     if (empty($schedule)) {
         return $this->single($hook, $args, $first, $group);
     }
     $date = ActionScheduler::get_datetime_object($first);
     $cron = CronExpression::factory($schedule);
     $schedule = new ActionScheduler_CronSchedule($date, $cron);
     $action = new ActionScheduler_Action($hook, $args, $schedule, $group);
     return $this->store($action);
 }
/**
 * Find scheduled actions
 *
 * @param array $args Possible arguments, with their default values:
 *        'hook' => '' - the name of the action that will be triggered
 *        'args' => NULL - the args array that will be passed with the action
 *        'date' => NULL - the scheduled date of the action. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime().
 *        'date_compare' => '<=' - operator for testing "date". accepted values are '!=', '>', '>=', '<', '<=', '='
 *        'modified' => NULL - the date the action was last updated. Expects a DateTime object, a unix timestamp, or a string that can parsed with strtotime().
 *        'modified_compare' => '<=' - operator for testing "modified". accepted values are '!=', '>', '>=', '<', '<=', '='
 *        'group' => '' - the group the action belongs to
 *        'status' => '' - ActionScheduler_Store::STATUS_COMPLETE or ActionScheduler_Store::STATUS_PENDING
 *        'claimed' => NULL - TRUE to find claimed actions, FALSE to find unclaimed actions, a string to find a specific claim ID
 *        'per_page' => 5 - Number of results to return
 *        'offset' => 0
 *        'orderby' => 'date' - accepted values are 'hook', 'group', 'modified', or 'date'
 *        'order' => 'ASC'
 *
 * @param string $return_format OBJECT, ARRAY_A, or ids
 *
 * @return array
 */
function wc_get_scheduled_actions($args = array(), $return_format = OBJECT)
{
    $store = ActionScheduler::store();
    foreach (array('date', 'modified') as $key) {
        if (isset($args[$key])) {
            $args[$key] = ActionScheduler::get_datetime_object($args[$key]);
        }
    }
    $ids = $store->query_actions($args);
    if ($return_format == 'ids' || $return_format == 'int') {
        return $ids;
    }
    $actions = array();
    foreach ($ids as $action_id) {
        $actions[$action_id] = $store->fetch_action($action_id);
    }
    if ($return_format == ARRAY_A) {
        foreach ($actions as $action_id => $action_object) {
            $actions[$action_id] = get_object_vars($action_object);
        }
    }
    return $actions;
}