ActionScheduler_Action

Base class for all scheduled actions. It encapsulates the hook to execute, arguments, schedule, group, and priority. It is the default class used for stored actions with status pending (see ActionScheduler_ActionFactory::get_stored_action()).

Source: classes/actions/ActionScheduler_Action.php

Properties

protected string $hook = ''

The hook name that will be triggered when this action executes.

protected array<string, mixed> $args = array()

Arguments passed to the hook when the action executes.

protected ActionScheduler_Schedule $schedule = null

The schedule object defining when the action runs (and whether it recurs). The constructor ensures this is never null by defaulting to ActionScheduler_NullSchedule when an empty schedule is provided.

protected string $group = ''

The action’s group identifier, used for grouping and filtering in queries.

protected int $priority = 10

Priority controls the order in which actions are claimed and processed. Lower numbers are higher priority. The priority is clamped to the range 0–255.

Methods

__construct( string $hook, array $args = array(), ?ActionScheduler_Schedule $schedule = null, string $group = '' )

Constructs a new action and sets its hook, schedule, args, and group.

Behavior details:

  • If $schedule is empty, a new ActionScheduler_NullSchedule is created and used.
  • The hook, schedule, args, and group are set using the protected setters.

public function execute()

Executes the action by calling do_action_ref_array() with the action’s hook and args.

Before execution, it checks that at least one callback is registered for the hook using has_action(). If no callbacks are registered, it throws an Exception with a translated message:

Scheduled action for %1$s will not be executed as no callbacks are registered.

This is intended to detect cases where the scheduled action’s hook is no longer registered by any code.

protected function set_hook( string $hook )

Sets the action’s hook name.

public function get_hook()

Returns the action’s hook name.

protected function set_schedule( ActionScheduler_Schedule $schedule )

Sets the action’s schedule object.

public function get_schedule()

Returns the action’s schedule object.

protected function set_args( array $args )

Sets the action’s arguments.

public function get_args()

Returns the action’s arguments.

protected function set_group( string $group )

Sets the action’s group.

public function get_group()

Returns the action’s group.

public function is_finished()

Returns false for the base action class. Subclasses that represent completed/canceled actions override this to return true.

public function set_priority( int $priority )

Sets the action’s priority, clamping the value into the range 0–255:

  • Values below 0 become 0.
  • Values above 255 become 255.

The value is then cast to integer and stored on $this->priority.

public function get_priority()

Returns the action’s priority as an integer.

Related Classes