PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 1.1.4
JetFormBuilder — Dynamic Blocks Form Builder v1.1.4
3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / actions / action-handler.php
jetformbuilder / includes / actions Last commit date
types 5 years ago action-handler.php 5 years ago action-localize.php 5 years ago manager.php 5 years ago
action-handler.php
215 lines
1 <?php
2
3 namespace Jet_Form_Builder\Actions;
4
5 // If this file is called directly, abort.
6 use Jet_Form_Builder\Classes\Tools;
7 use Jet_Form_Builder\Exceptions\Action_Exception;
8 use Jet_Form_Builder\Exceptions\Condition_Exception;
9 use Jet_Form_Builder\Gateways\Gateway_Manager;
10 use Jet_Form_Builder\Plugin;
11
12 if ( ! defined( 'WPINC' ) ) {
13 die;
14 }
15
16 /**
17 * Define Actions handler class class
18 */
19 class Action_Handler {
20
21 public $form_id = null;
22 public $request_data = null;
23 public $manager = null;
24
25
26 public $form_actions = array();
27 public $is_ajax = false;
28
29 /**
30 * Data for actions
31 */
32 public $size_all;
33 public $current_position;
34 public $response_data = array();
35
36
37 /**
38 * Constructor for the class
39 *
40 * @param $form_id
41 */
42 public function __construct( $form_id ) {
43 $this->form_id = $form_id;
44 $this->set_form_actions();
45 }
46
47 public function add_request( $request ) {
48 $this->request_data = $request;
49
50 return $this;
51 }
52
53 /**
54 * Set form actions,
55 * which were saved in form meta
56 *
57 * @return $this
58 */
59 public function set_form_actions() {
60 $available_actions = Plugin::instance()->actions->get_actions();
61 $form_actions = Plugin::instance()->post_type->get_actions( $this->form_id );
62
63 foreach ( $form_actions as $form_action ) {
64 $id = $form_action['id'];
65 $type = $form_action['type'];
66 $conditions = isset( $form_action['conditions'] ) ? $form_action['conditions'] : array();
67
68 if ( isset( $available_actions[ $type ] ) ) {
69 $action = clone $available_actions[ $type ];
70 /**
71 * Save action settings to the class field,
72 * it allows to not send action settings
73 * in action hook
74 */
75 $action->_id = $id;
76 $action->settings = $form_action['settings'];
77 $action->conditions = $conditions;
78
79 $this->form_actions[ $id ] = $action;
80 }
81 }
82
83 return $this;
84 }
85
86
87 /**
88 * Unregister notification by id
89 *
90 * @param $id [description]
91 *
92 * @return void [description]
93 */
94 public function unregister_action( $key ) {
95 if ( is_numeric( $key ) && isset( $this->form_actions[ $key ] ) ) {
96 unset( $this->form_actions[ $key ] );
97
98 return;
99 }
100 foreach ( $this->form_actions as $index => $action ) {
101 if ( $key === $action->get_id() ) {
102 unset( $this->form_actions[ $index ] );
103 }
104 }
105 }
106
107 /**
108 * Returns all registered notifications
109 *
110 * @return array [description]
111 */
112 public function get_all() {
113 return $this->form_actions;
114 }
115
116 /**
117 * Send form notifications
118 *
119 * @return array [type] [description]
120 * @throws Action_Exception
121 */
122 public function do_actions() {
123
124 $this->before_run_actions();
125 $this->run_actions();
126 $this->after_run_actions();
127
128 return $this->response_data;
129 }
130
131 public function before_run_actions() {
132 $callbacks = array();
133
134 if ( Plugin::instance()->allow_gateways ) {
135 $callbacks[] = array(
136 Gateway_Manager::instance(),
137 Gateway_Manager::BEFORE_ACTIONS_CALLABLE
138 );
139 }
140
141 Tools::run_callbacks(
142 apply_filters( 'jet-form-builder/actions/before-send/callbacks', $callbacks ),
143 $this
144 );
145 }
146
147 public function after_run_actions() {
148 $callbacks = array();
149
150 if ( Plugin::instance()->allow_gateways ) {
151 $callbacks[] = array(
152 Gateway_Manager::instance(),
153 Gateway_Manager::AFTER_ACTIONS_CALLABLE
154 );
155 }
156
157 Tools::run_callbacks(
158 apply_filters( 'jet-form-builder/actions/after-send/callbacks', $callbacks ),
159 $this
160 );
161
162 }
163
164 public function run_actions() {
165 if ( empty( $this->form_actions ) ) {
166 throw new Action_Exception( 'failed' );
167 }
168
169 $this->size_all = sizeof( $this->form_actions );
170
171 foreach ( $this->form_actions as $index => $action ) {
172
173 $this->current_position = $index;
174
175 /**
176 * Check conditions for action
177 */
178 try {
179 $action->condition( $this );
180 } catch ( Condition_Exception $exception ) {
181 continue;
182 }
183 /**
184 * Process single action
185 */
186 $action->do_action( $this->request_data, $this );
187 }
188
189 }
190
191 public function get_inserted_post_id( $action_id = 0 ) {
192 if ( ! $action_id ) {
193 return absint( $this->response_data['inserted_post_id'] );
194 }
195
196 $action_id = absint( $action_id );
197
198 if ( empty( $this->response_data['inserted_posts'] ) ) {
199 return absint( $this->response_data['inserted_post_id'] );
200 }
201
202 foreach ( $this->response_data['inserted_posts'] as $posts ) {
203 if ( $action_id === $posts['action_id'] ) {
204 return $posts['post_id'];
205 }
206 }
207 }
208
209 public function add_response( $values ) {
210 Plugin::instance()->form_handler->add_response_data( $values );
211 }
212
213
214 }
215