Constants

STATUS_COMPLETE

STATUS_COMPLETE = 'complete'

STATUS_PENDING

STATUS_PENDING = 'pending'

STATUS_RUNNING

STATUS_RUNNING = 'in-progress'

STATUS_FAILED

STATUS_FAILED = 'failed'

STATUS_CANCELED

STATUS_CANCELED = 'canceled'

DEFAULT_CLASS

DEFAULT_CLASS = 'ActionScheduler_wpPostStore'

Properties

$max_args_length

$max_args_length : int

Maximum length of args.

Type

normal

$store

$store : \ActionScheduler_Store

ActionScheduler_Store instance.

Type

normal

Methods

mark_failed_fetch_action()

mark_failed_fetch_action(int  $action_id) : mixed

Mark an action that failed to fetch correctly as failed.

Parameters

int $action_id

The ID of the action.

Returns

mixed

save_action()

save_action(\ActionScheduler_Action  $action, null|\DateTime  $scheduled_date = null) : int

Save action.

Parameters

\ActionScheduler_Action $action

Action to save.

null|\DateTime $scheduled_date

Optional Date of the first instance to store. Otherwise uses the first date of the action's schedule.

Returns

int —

The action ID

fetch_action()

fetch_action(string  $action_id) : \ActionScheduler_Action

Get action.

Parameters

string $action_id

Action ID.

Returns

\ActionScheduler_Action

find_action()

find_action(string  $hook, array  $params = array()) : string|null

Find an action.

Note: the query ordering changes based on the passed 'status' value.

Parameters

string $hook

Action hook.

array $params

Parameters of the action to find.

Returns

string|null —

ID of the next action matching the criteria or NULL if not found.

query_actions()

query_actions(array  $query = array(), string  $query_type = 'select') : string|array|null

Query for action count or list of action IDs.

Parameters

array $query

{ Query filtering options.

 @type string       $hook             The name of the actions. Optional.
 @type string|array $status           The status or statuses of the actions. Optional.
 @type array        $args             The args array of the actions. Optional.
 @type DateTime     $date             The scheduled date of the action. Used in UTC timezone. Optional.
 @type string       $date_compare     Operator for selecting by $date param. Accepted values are '!=', '>', '>=', '<', '<=', '='. Defaults to '<='.
 @type DateTime     $modified         The last modified date of the action. Used in UTC timezone. Optional.
 @type string       $modified_compare Operator for comparing $modified param. Accepted values are '!=', '>', '>=', '<', '<=', '='. Defaults to '<='.
 @type string       $group            The group the action belongs to. Optional.
 @type bool|int     $claimed          TRUE to find claimed actions, FALSE to find unclaimed actions, an int to find a specific claim ID. Optional.
 @type int          $per_page         Number of results to return. Defaults to 5.
 @type int          $offset           The query pagination offset. Defaults to 0.
 @type int          $orderby          Accepted values are 'hook', 'group', 'modified', 'date' or 'none'. Defaults to 'date'.
 @type string       $order            Accepted values are 'ASC' or 'DESC'. Defaults to 'ASC'.

}

string $query_type

Whether to select or count the results. Default, select.

Returns

string|array|null —

The IDs of actions matching the query. Null on failure.

query_action()

query_action(array  $query) : int|null

Run query to get a single action ID.

Parameters

array $query

Query parameters.

Returns

int|null

action_counts()

action_counts() : array

Get a count of all actions in the store, grouped by status

Returns

array

extra_action_counts()

extra_action_counts() : array

Get additional action counts.

  • add past-due actions

Returns

array

cancel_action()

cancel_action(string  $action_id) : mixed

Cancel action.

Parameters

string $action_id

Action ID.

Returns

mixed

delete_action()

delete_action(string  $action_id) : mixed

Delete action.

Parameters

string $action_id

Action ID.

Returns

mixed

get_date()

get_date(string  $action_id) : \DateTime

Get action's schedule or run timestamp.

Parameters

string $action_id

Action ID.

Returns

\DateTime —

The date the action is schedule to run, or the date that it ran.

stake_claim()

stake_claim(int  $max_actions = 10, \DateTime|null  $before_date = null, array  $hooks = array(), string  $group = '') : \ActionScheduler_ActionClaim

Make a claim.

Parameters

int $max_actions

Maximum number of actions to claim.

\DateTime|null $before_date

Claim only actions schedule before the given date. Defaults to now.

array $hooks

Claim only actions with a hook or hooks.

string $group

Claim only actions in the given group.

Returns

\ActionScheduler_ActionClaim

get_claim_count()

get_claim_count() : int

Get claim count.

Returns

int

release_claim()

release_claim(\ActionScheduler_ActionClaim  $claim) : mixed

Release the claim.

Parameters

\ActionScheduler_ActionClaim $claim

Claim object.

Returns

mixed

unclaim_action()

unclaim_action(string  $action_id) : mixed

Un-claim the action.

Parameters

string $action_id

Action ID.

Returns

mixed

mark_failure()

mark_failure(string  $action_id) : mixed

Mark action as failed.

Parameters

string $action_id

Action ID.

Returns

mixed

log_execution()

log_execution(string  $action_id) : mixed

Log action's execution.

Parameters

string $action_id

Actoin ID.

Returns

mixed

mark_complete()

mark_complete(string  $action_id) : mixed

Mark action as complete.

Parameters

string $action_id

Action ID.

Returns

mixed

get_status()

get_status(string  $action_id) : string

Get action's status.

Parameters

string $action_id

Action ID.

Returns

string

get_claim_id()

get_claim_id(string  $action_id) : mixed

Get action's claim ID.

Parameters

string $action_id

Action ID.

Returns

mixed

find_actions_by_claim_id()

find_actions_by_claim_id(string  $claim_id) : array

Find actions by claim ID.

Parameters

string $claim_id

Claim ID.

Returns

array

cancel_actions_by_hook()

cancel_actions_by_hook(string  $hook) : void

Cancel pending actions by hook.

Parameters

string $hook

Hook name.

cancel_actions_by_group()

cancel_actions_by_group(string  $group) : void

Cancel pending actions by group.

Parameters

string $group

Group slug.

get_status_labels()

get_status_labels() : array<string,string>

Get status labels.

Returns

array

has_pending_actions_due()

has_pending_actions_due() : string

Check if there are any pending scheduled actions due to run.

Returns

string

init()

init() : mixed

Callable initialization function optionally overridden in derived classes.

Returns

mixed

mark_migrated()

mark_migrated(int  $action_id) : mixed

Callable function to mark an action as migrated optionally overridden in derived classes.

Parameters

int $action_id

Action ID.

Returns

mixed

instance()

instance() : \ActionScheduler_Store

Get instance.

Returns

\ActionScheduler_Store

hook()

hook() : mixed

Add base hooks

Returns

mixed

unhook()

unhook() : mixed

Remove base hooks

Returns

mixed

get_local_timezone()

get_local_timezone() : \DateTimeZone

Get the site's local time.

Returns

\DateTimeZone

validate_sql_comparator()

validate_sql_comparator(string  $comparison_operator) : string

Validate SQL operator.

Parameters

string $comparison_operator

Operator.

Returns

string

get_scheduled_date_string()

get_scheduled_date_string(\ActionScheduler_Action  $action, null|\DateTime  $scheduled_date = null) : string

Get the time MySQL formatted date/time string for an action's (next) scheduled date.

Parameters

\ActionScheduler_Action $action

Action.

null|\DateTime $scheduled_date

Action's schedule date (optional).

Returns

string

get_scheduled_date_string_local()

get_scheduled_date_string_local(\ActionScheduler_Action|null  $action, null|\DateTime  $scheduled_date = null) : string

Get the time MySQL formatted date/time string for an action's (next) scheduled date.

Parameters

\ActionScheduler_Action|null $action

Action.

null|\DateTime $scheduled_date

Action's scheduled date (optional).

Returns

string

validate_args()

validate_args(mixed  $args, int  $action_id) : mixed

Validate that we could decode action arguments.

Parameters

mixed $args

The decoded arguments.

int $action_id

The action ID.

Throws

\ActionScheduler_InvalidActionException

When the decoded arguments are invalid.

Returns

mixed

validate_schedule()

validate_schedule(mixed  $schedule, int  $action_id) : mixed

Validate a ActionScheduler_Schedule object.

Parameters

mixed $schedule

The unserialized ActionScheduler_Schedule object.

int $action_id

The action ID.

Throws

\ActionScheduler_InvalidActionException

When the schedule is invalid.

Returns

mixed

validate_action()

validate_action(\ActionScheduler_Action  $action) : mixed

InnoDB indexes have a maximum size of 767 bytes by default, which is only 191 characters with utf8mb4.

Previously, AS wasn't concerned about args length, as we used the (unindex) post_content column. However, with custom tables, we use an indexed VARCHAR column instead.

Parameters

\ActionScheduler_Action $action

Action to be validated.

Throws

\InvalidArgumentException

When json encoded args is too long.

Returns

mixed

bulk_cancel_actions()

bulk_cancel_actions(int[]  $action_ids) : void

Cancel a set of action IDs.

Parameters

int[] $action_ids

List of action IDs.