PluginProbe
WANotifier for Forms and Actions / 2.7.13
WANotifier for Forms and Actions v2.7.13
3.1.1 3.1.0 3.0.4 2.7.10 2.7.11 2.7.12 2.7.13 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 3.0.0 3.0.1 3.0.2 3.0.3 trunk 0.1.0 0.1.1 1.0.0 1.0.1 1.0.2 All 67 releases
notifier / libraries / action-scheduler / classes / actions / ActionScheduler_Action.php

ActionScheduler_Action.php in WANotifier for Forms and Actions 2.7.13, at libraries/action-scheduler/classes/actions/ActionScheduler_Action.php

97 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class ActionScheduler_Action
5 */
6 class ActionScheduler_Action {
7 protected $hook = '';
8 protected $args = array();
9 /** @var ActionScheduler_Schedule */
10 protected $schedule = NULL;
11 protected $group = '';
12
13 public function __construct( $hook, array $args = array(), ActionScheduler_Schedule $schedule = NULL, $group = '' ) {
14 $schedule = empty( $schedule ) ? new ActionScheduler_NullSchedule() : $schedule;
15 $this->set_hook($hook);
16 $this->set_schedule($schedule);
17 $this->set_args($args);
18 $this->set_group($group);
19 }
20
21 /**
22 * Executes the action.
23 *
24 * If no callbacks are registered, an exception will be thrown and the action will not be
25 * fired. This is useful to help detect cases where the code responsible for setting up
26 * a scheduled action no longer exists.
27 *
28 * @throws Exception If no callbacks are registered for this action.
29 */
30 public function execute() {
31 $hook = $this->get_hook();
32
33 if ( ! has_action( $hook ) ) {
34 throw new Exception(
35 sprintf(
36 /* translators: 1: action hook. */
37 __( 'Scheduled action for %1$s will not be executed as no callbacks are registered.', 'action-scheduler' ),
38 $hook
39 )
40 );
41 }
42
43 do_action_ref_array( $hook, array_values( $this->get_args() ) );
44 }
45
46 /**
47 * @param string $hook
48 */
49 protected function set_hook( $hook ) {
50 $this->hook = $hook;
51 }
52
53 public function get_hook() {
54 return $this->hook;
55 }
56
57 protected function set_schedule( ActionScheduler_Schedule $schedule ) {
58 $this->schedule = $schedule;
59 }
60
61 /**
62 * @return ActionScheduler_Schedule
63 */
64 public function get_schedule() {
65 return $this->schedule;
66 }
67
68 protected function set_args( array $args ) {
69 $this->args = $args;
70 }
71
72 public function get_args() {
73 return $this->args;
74 }
75
76 /**
77 * @param string $group
78 */
79 protected function set_group( $group ) {
80 $this->group = $group;
81 }
82
83 /**
84 * @return string
85 */
86 public function get_group() {
87 return $this->group;
88 }
89
90 /**
91 * @return bool If the action has been finished
92 */
93 public function is_finished() {
94 return FALSE;
95 }
96 }
97