ActionScheduler_ActionFactory

Located in classes/ActionScheduler_ActionFactory.php.

Creates and stores scheduled actions with different schedule types (async, single, recurring, cron) and can hydrate stored actions from persisted data. This class is an internal helper used by the scheduling API and queue infrastructure.

Public Methods

get_stored_action( $status, $hook, array $args = array(), ?ActionScheduler_Schedule $schedule = null, $group = '' )

Return a stored action instance based on status and schedule data.

  • Parameters:
    • $status (string): Action status from the store (pending, canceled, etc.).
    • $hook (string): Hook to trigger when the action runs.
    • $args (array): Arguments passed to the hook callbacks.
    • $schedule (ActionScheduler_Schedule|null): Schedule object for the action.
    • $group (string): Group identifier.
    • Implicit 6th parameter: $priority (int), accepted via func_get_arg( 5 ) for backward compatibility.
  • Returns: ActionScheduler_Action

Notes:

  • Picks an action class based on status:
    • pending → ActionScheduler_Action
    • canceled → ActionScheduler_CanceledAction (with schedule coerced to ActionScheduler_CanceledSchedule)
    • otherwise → ActionScheduler_FinishedAction
  • Applies filters:
    • action_scheduler_stored_action_class
    • action_scheduler_stored_action_instance

async( $hook, $args = array(), $group = '' )

Schedule an async action (NullSchedule), due “now”.

  • Parameters: $hook (string), $args (array), $group (string)
  • Returns: int action ID

async_unique( $hook, $args = array(), $group = '', $unique = true )

Async scheduling with optional uniqueness.

  • Parameters: $hook (string), $args (array), $group (string), $unique (bool)
  • Returns: int action ID

single( $hook, $args = array(), $when = null, $group = '' )

Schedule a single action at a specific timestamp.

  • Parameters: $hook (string), $args (array), $when (int|null), $group (string)
  • Returns: int action ID

single_unique( $hook, $args = array(), $when = null, $group = '', $unique = true )

Schedule a single action only if there is no pending/running action with the same hook and args.

  • Parameters: $hook (string), $args (array), $when (int|null), $group (string), $unique (bool)
  • Returns: int action ID

recurring( $hook, $args = array(), $first = null, $interval = null, $group = '' )

Schedule the first instance of an interval-based recurring action.

  • Parameters: $hook (string), $args (array), $first (int|null), $interval (int|null), $group (string)
  • Returns: int action ID

recurring_unique( $hook, $args = array(), $first = null, $interval = null, $group = '', $unique = true )

Recurring schedule with optional uniqueness. If $interval is empty, falls back to single_unique().

  • Parameters: $hook (string), $args (array), $first (int|null), $interval (int|null), $group (string), $unique (bool)
  • Returns: int action ID

cron( $hook, $args = array(), $base_timestamp = null, $schedule = null, $group = '' )

Schedule the first instance of a cron-based recurring action.

  • Parameters: $hook (string), $args (array), $base_timestamp (int|null), $schedule (string|null), $group (string)
  • Returns: int action ID

cron_unique( $hook, $args = array(), $base_timestamp = null, $schedule = null, $group = '', $unique = true )

Cron scheduling with optional uniqueness. If $schedule is empty, falls back to single_unique().

  • Parameters: $hook (string), $args (array), $base_timestamp (int|null), $schedule (string|null), $group (string), $unique (bool)
  • Returns: int action ID

repeat( $action )

Create the next instance for a recurring or cron action based on the current time.

  • Parameters: $action (ActionScheduler_Action)
  • Returns: string action ID
  • Throws: InvalidArgumentException if the action is not recurring or has no next date.

create( array $options = array() )

General-purpose scheduling entry point used by the public API.

  • Parameters: $options (array) with keys:
    • type (string): async, cron, recurring, single
    • hook (string)
    • arguments (array)
    • group (string)
    • unique (bool)
    • when (int)
    • pattern (int|string|null) interval or cron expression
    • priority (int)
  • Returns: int action ID (0 on error)

Notes:

  • cron/recurring with an empty pattern are treated as single.
  • Logs an error and returns 0 if an unknown type is provided.

Filters

  • action_scheduler_stored_action_class — override class used for stored actions.
  • action_scheduler_stored_action_instance — override instantiated action object.