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:

  • $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.

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

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

  • $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.

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

Async scheduling with optional uniqueness.

  • 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

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

Schedule a single action at a specific timestamp.

  • pending → ActionScheduler_Action
  • canceled → ActionScheduler_CanceledAction (with schedule coerced to ActionScheduler_CanceledSchedule)
  • otherwise → ActionScheduler_FinishedAction

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.

  • action_scheduler_stored_action_class
  • action_scheduler_stored_action_instance

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

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

  • pending → ActionScheduler_Action
  • canceled → ActionScheduler_CanceledAction (with schedule coerced to ActionScheduler_CanceledSchedule)
  • otherwise → ActionScheduler_FinishedAction

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().

  • action_scheduler_stored_action_class
  • action_scheduler_stored_action_instance

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), $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), $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: $hook (string), $args (array), $when (int|null), $group (string)
  • Returns: int action ID

create( array $options = array() )

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

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

Notes:

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

Filters

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