PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 3.06.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v3.06.06
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmFormAction.php +237 -410 6.5.33.06.06 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) {
3 - die( 'You are not allowed to call this page directly.' );
4 -}
5 2
6 3 class FrmFormAction {
7 4
8 5 public $id_base; // Root id for all actions of this type.
@@ -24,9 +21,8 @@
24 21 * If "false" is returned, the instance won't be saved/updated.
25 22 *
26 23 * @param array $new_instance New settings for this instance as input by the user via form()
27 24 * @param array $old_instance Old settings for this instance
28 - *
29 25 * @return array Settings to save or bool false to cancel saving
30 26 */
31 27 public function update( $new_instance, $old_instance ) {
32 28 return $new_instance;
@@ -32,16 +28,14 @@
32 28 return $new_instance;
33 29 }
34 30
35 31 /**
36 - * Echo the settings update form
32 + * Echo the settings update form
37 33 *
38 - * @param WP_Post $instance Current settings
39 - * @param array $args
34 + * @param array $instance Current settings
40 35 */
41 36 public function form( $instance, $args = array() ) {
42 37 echo '<p class="no-options-widget">' . esc_html__( 'There are no options for this action.', 'formidable' ) . '</p>';
43 -
44 38 return 'noform';
45 39 }
46 40
47 41 /**
@@ -47,20 +41,17 @@
47 41 /**
48 42 * @return array of the default options
49 43 */
50 44 public function get_defaults() {
51 - return array();
45 + return array();
52 46 }
53 47
54 - /**
55 - * @return array
56 - */
57 48 public function get_switch_fields() {
58 - return array();
49 + return array();
59 50 }
60 51
61 52 public function migrate_values( $action, $form ) {
62 - return $action;
53 + return $action;
63 54 }
64 55
65 56 // Functions you'll need to call.
66 57
@@ -81,50 +72,26 @@
81 72 if ( ! defined( 'ABSPATH' ) ) {
82 73 die( 'You are not allowed to call this page directly.' );
83 74 }
84 75
85 - $this->id_base = strtolower( $id_base );
86 - $this->name = $name;
76 + $this->id_base = strtolower( $id_base );
77 + $this->name = $name;
87 78 $this->option_name = 'frm_' . $this->id_base . '_action';
88 79
89 - $default_options = array(
90 - 'classes' => '',
91 - 'active' => true,
92 - 'event' => array( 'create' ),
93 - 'limit' => 1,
94 - 'force_event' => false,
95 - 'priority' => 20,
96 - 'ajax_load' => true,
97 - 'plugin' => $this->id_base,
98 - 'tooltip' => $name,
99 - 'group' => $id_base,
100 - 'color' => '',
101 - 'keywords' => '',
102 - );
80 + $default_options = array(
81 + 'classes' => '',
82 + 'active' => true,
83 + 'event' => array( 'create' ),
84 + 'limit' => 1,
85 + 'force_event' => false,
86 + 'priority' => 20,
87 + 'ajax_load' => true,
88 + 'plugin' => $this->id_base,
89 + 'tooltip' => $name,
90 + );
103 91
104 - $action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options );
105 - $group = $this->get_group( $action_options );
106 - $action_options['group'] = $group['id'];
107 -
108 - if ( ! isset( $action_options['color'] ) ) {
109 - $colors = array( 'green', 'orange', 'purple' );
110 - shuffle( $colors );
111 - $action_options['color'] = 'var(--' . reset( $colors ) . ')';
112 - }
113 -
114 - $upgrade_class = isset( $action_options['classes'] ) && $action_options['classes'] === 'frm_show_upgrade';
115 - if ( $action_options['group'] === $id_base ) {
116 - $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false;
117 - $action_options['classes'] = $group['icon'];
118 - } elseif ( ! isset( $action_options['classes'] ) || empty( $action_options['classes'] ) || $upgrade_class ) {
119 - $action_options['classes'] = $group['icon'];
120 - }
121 -
122 - if ( $upgrade_class ) {
123 - $action_options['classes'] .= ' frm_show_upgrade';
124 - }
125 -
126 - $this->action_options = wp_parse_args( $action_options, $default_options );
92 + $action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options );
93 + $this->action_options = wp_parse_args( $action_options, $default_options );
127 94 $this->control_options = wp_parse_args( $control_options, array( 'id_base' => $this->id_base ) );
128 95 }
129 96
130 97 /**
@@ -134,53 +101,13 @@
134 101 self::__construct( $id_base, $name, $action_options, $control_options );
135 102 }
136 103
137 104 /**
138 - * Help to switch old field id by new field id for duplicate form
139 - *
140 - * @param string $action id of the field that needs to be switched
141 - *
142 - * @return string
143 - */
144 - public function maybe_switch_field_ids( $action ) {
145 - $updated_action = apply_filters( 'frm_maybe_switch_field_ids', $action );
146 - if ( $updated_action === $action ) {
147 - $updated_action = FrmFieldsHelper::switch_field_ids( $action );
148 - }
149 - return $updated_action;
150 - }
151 -
152 - /**
153 - * @since 4.0
154 - */
155 - protected function get_group( $action_options ) {
156 - $groups = FrmFormActionsController::form_action_groups();
157 - $group = 'misc';
158 -
159 - if ( isset( $action_options['group'] ) && isset( $groups[ $action_options['group'] ] ) ) {
160 - $group = $action_options['group'];
161 - } elseif ( isset( $groups[ $this->id_base ] ) ) {
162 - $group = $this->id_base;
163 - } else {
164 - foreach ( $groups as $name => $check_group ) {
165 - if ( isset( $check_group['actions'] ) && in_array( $this->id_base, $check_group['actions'] ) ) {
166 - $group = $name;
167 - break;
168 - }
169 - }
170 - }
171 -
172 - $groups[ $group ]['id'] = $group;
173 - return $groups[ $group ];
174 - }
175 -
176 - /**
177 105 * Constructs name attributes for use in form() fields
178 106 *
179 107 * This function should be used in form() methods to create name attributes for fields to be saved by update()
180 108 *
181 109 * @param string $field_name Field name
182 - *
183 110 * @return string Name attribute for $field_name
184 111 */
185 112 public function get_field_name( $field_name, $post_field = 'post_content' ) {
186 113 $name = $this->option_name . '[' . $this->number . ']';
@@ -185,9 +112,8 @@
185 112 public function get_field_name( $field_name, $post_field = 'post_content' ) {
186 113 $name = $this->option_name . '[' . $this->number . ']';
187 114 $name .= ( empty( $post_field ) ? '' : '[' . $post_field . ']' );
188 115 $name .= '[' . $field_name . ']';
189 -
190 116 return $name;
191 117 }
192 118
193 119 /**
@@ -195,9 +121,8 @@
195 121 *
196 122 * This function should be used in form() methods to create id attributes for fields to be saved by update()
197 123 *
198 124 * @param string $field_name Field name
199 - *
200 125 * @return string ID attribute for $field_name
201 126 */
202 127 public function get_field_id( $field_name ) {
203 128 return $field_name . '_' . $this->number;
@@ -202,27 +127,22 @@
202 127 public function get_field_id( $field_name ) {
203 128 return $field_name . '_' . $this->number;
204 129 }
205 130
206 - /**
207 - * @param int|string $number
208 - * @return void
209 - */
131 + // Private Function. Don't worry about this.
132 +
210 133 public function _set( $number ) {
211 134 $this->number = $number;
212 - $this->id = $this->id_base . '-' . $number;
135 + $this->id = $this->id_base . '-' . $number;
213 136 }
214 137
215 - /**
216 - * @return object
217 - */
218 138 public function prepare_new( $form_id = false ) {
219 - if ( $form_id ) {
220 - $this->form_id = $form_id;
221 - }
139 + if ( $form_id ) {
140 + $this->form_id = $form_id;
141 + }
222 142
223 - $post_content = array();
224 - $default_values = $this->get_global_defaults();
143 + $post_content = array();
144 + $default_values = $this->get_global_defaults();
225 145
226 146 // fill default values
227 147 $post_content = wp_parse_args( $post_content, $default_values );
228 148
@@ -229,87 +149,79 @@
229 149 if ( ! isset( $post_content['event'] ) && ! $this->action_options['force_event'] ) {
230 150 $post_content['event'] = array( reset( $this->action_options['event'] ) );
231 151 }
232 152
233 - $form_action = array(
234 - 'post_title' => $this->name,
235 - 'post_content' => $post_content,
236 - 'post_excerpt' => $this->id_base,
237 - 'ID' => '',
238 - 'post_status' => 'publish',
239 - 'post_type' => FrmFormActionsController::$action_post_type,
240 - 'post_name' => $this->form_id . '_' . $this->id_base . '_' . $this->number,
241 - 'menu_order' => $this->form_id,
242 - );
153 + $form_action = array(
154 + 'post_title' => $this->name,
155 + 'post_content' => $post_content,
156 + 'post_excerpt' => $this->id_base,
157 + 'ID' => '',
158 + 'post_status' => 'publish',
159 + 'post_type' => FrmFormActionsController::$action_post_type,
160 + 'post_name' => $this->form_id . '_' . $this->id_base . '_' . $this->number,
161 + 'menu_order' => $this->form_id,
162 + );
243 163 unset( $post_content );
244 164
245 - return (object) $form_action;
246 - }
165 + return (object) $form_action;
166 + }
247 167
248 168 public function create( $form_id ) {
249 - $this->form_id = $form_id;
169 + $this->form_id = $form_id;
250 170
251 - $action = $this->prepare_new();
171 + $action = $this->prepare_new();
252 172
253 173 return $this->save_settings( $action );
254 - }
174 + }
255 175
256 - /**
257 - * @return void
258 - */
259 176 public function duplicate_form_actions( $form_id, $old_id ) {
260 - if ( $form_id == $old_id ) {
261 - // don't duplicate the actions if this is a template getting updated
262 - return;
263 - }
177 + if ( $form_id == $old_id ) {
178 + // don't duplicate the actions if this is a template getting updated
179 + return;
180 + }
264 181
265 - $this->form_id = $old_id;
266 - $actions = $this->get_all( $old_id );
182 + $this->form_id = $old_id;
183 + $actions = $this->get_all( $old_id );
267 184
268 - $this->form_id = $form_id;
269 - foreach ( $actions as $action ) {
185 + $this->form_id = $form_id;
186 + foreach ( $actions as $action ) {
270 187 $this->duplicate_one( $action, $form_id );
271 188 unset( $action );
272 - }
273 - }
189 + }
190 + }
274 191
275 - /* Check if imported action should be created or updated
276 - *
277 - * @since 2.0
278 - *
279 - * @param array $action
280 - * @return integer $post_id
281 - */
282 - public function maybe_create_action( $action, $forms ) {
192 + /* Check if imported action should be created or updated
193 + *
194 + * Since 2.0
195 + *
196 + * @param array $action
197 + * @return integer $post_id
198 + */
199 + public function maybe_create_action( $action, $forms ) {
283 200 if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] == 'updated' ) {
284 - // Update action only
285 - $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
286 - $post_id = $this->save_settings( $action );
287 - } else {
201 + // Update action only
202 + $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
203 + $post_id = $this->save_settings( $action );
204 + } else {
288 205 // Create action
289 206 $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
290 - $post_id = $this->duplicate_one( (object) $action, $action['menu_order'] );
291 - }
207 + $post_id = $this->duplicate_one( (object) $action, $action['menu_order'] );
208 + }
209 + return $post_id;
210 + }
292 211
293 - return $post_id;
294 - }
295 -
296 - /**
297 - * @param object $action
298 - */
299 212 public function duplicate_one( $action, $form_id ) {
300 - global $frm_duplicate_ids;
213 + global $frm_duplicate_ids;
301 214
302 - $action->menu_order = $form_id;
303 - $switch = $this->get_global_switch_fields();
304 -
305 - foreach ( (array) $action->post_content as $key => $val ) {
215 + $action->menu_order = $form_id;
216 + $switch = $this->get_global_switch_fields();
217 + foreach ( (array) $action->post_content as $key => $val ) {
306 218 if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) {
307 219 $action->post_content[ $key ] = $frm_duplicate_ids[ $val ];
308 - } elseif ( ! is_array( $val ) ) {
220 + } else if ( ! is_array( $val ) ) {
309 221 $action->post_content[ $key ] = FrmFieldsHelper::switch_field_ids( $val );
310 - } elseif ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) {
311 - // loop through each value if empty
222 + } else if ( isset( $switch[ $key ] ) && is_array( $switch[ $key ] ) ) {
223 + // loop through each value if empty
312 224 if ( empty( $switch[ $key ] ) ) {
313 225 $switch[ $key ] = array_keys( $val );
314 226 }
315 227
@@ -314,10 +226,10 @@
314 226 }
315 227
316 228 foreach ( $switch[ $key ] as $subkey ) {
317 229 $action->post_content[ $key ] = $this->duplicate_array_walk( $action->post_content[ $key ], $subkey, $val );
318 - }
319 - }
230 + }
231 + }
320 232
321 233 unset( $key, $val );
322 234 }
323 235 unset( $action->ID );
@@ -322,37 +234,35 @@
322 234 }
323 235 unset( $action->ID );
324 236
325 237 return $this->save_settings( $action );
326 - }
238 + }
327 239
328 240 private function duplicate_array_walk( $action, $subkey, $val ) {
329 - global $frm_duplicate_ids;
241 + global $frm_duplicate_ids;
330 242
331 243 if ( is_array( $subkey ) ) {
332 - foreach ( $subkey as $subkey2 ) {
333 - foreach ( (array) $val as $ck => $cv ) {
244 + foreach ( $subkey as $subkey2 ) {
245 + foreach ( (array) $val as $ck => $cv ) {
334 246 if ( is_array( $cv ) ) {
335 247 $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey2, $cv );
336 - } elseif ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) {
248 + } else if ( isset( $cv[ $subkey ] ) && is_numeric( $cv[ $subkey ] ) && isset( $frm_duplicate_ids[ $cv[ $subkey ] ] ) ) {
337 249 $action[ $ck ][ $subkey ] = $frm_duplicate_ids[ $cv[ $subkey ] ];
338 - }
339 - }
340 - }
341 - } else {
342 - foreach ( (array) $val as $ck => $cv ) {
250 + }
251 + }
252 + }
253 + } else {
254 + foreach ( (array) $val as $ck => $cv ) {
343 255 if ( is_array( $cv ) ) {
344 256 $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv );
345 - } elseif ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) {
257 + } else if ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) {
346 258 $action[ $ck ] = $frm_duplicate_ids[ $cv ];
347 - } elseif ( $ck == $subkey ) {
348 - $action[ $ck ] = $this->maybe_switch_field_ids( $action[ $ck ] );
349 - }
350 - }
351 - }
259 + }
260 + }
261 + }
352 262
353 - return $action;
354 - }
263 + return $action;
264 + }
355 265
356 266 /**
357 267 * Deal with changed settings.
358 268 *
@@ -357,31 +267,28 @@
357 267 * Deal with changed settings.
358 268 *
359 269 * Do NOT over-ride this function
360 270 */
361 - public function update_callback( $form_id ) {
362 - $this->form_id = $form_id;
271 + public function update_callback( $form_id ) {
272 + $this->form_id = $form_id;
363 273
364 - $all_instances = $this->get_settings();
274 + $all_instances = $this->get_settings();
365 275
366 - // We need to update the data
367 - if ( $this->updated ) {
368 - return;
369 - }
276 + // We need to update the data
277 + if ( $this->updated ) {
278 + return;
279 + }
370 280
371 - // phpcs:ignore WordPress.Security.NonceVerification.Missing
372 281 if ( isset( $_POST[ $this->option_name ] ) && is_array( $_POST[ $this->option_name ] ) ) {
373 - // Sanitizing removes scripts and <email> type of values.
374 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
375 - $settings = wp_unslash( $_POST[ $this->option_name ] );
376 - } else {
377 - return;
378 - }
282 + $settings = $_POST[ $this->option_name ];
283 + } else {
284 + return;
285 + }
379 286
380 - $action_ids = array();
287 + $action_ids = array();
381 288
382 - foreach ( $settings as $number => $new_instance ) {
383 - $this->_set( $number );
289 + foreach ( $settings as $number => $new_instance ) {
290 + $this->_set( $number );
384 291
385 292 $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
386 293
387 294 if ( ! isset( $new_instance['post_status'] ) ) {
@@ -388,21 +295,22 @@
388 295 $new_instance['post_status'] = 'draft';
389 296 }
390 297
391 298 // settings were never opened, so don't update
392 - if ( ! isset( $new_instance['post_title'] ) ) {
299 + if ( ! isset( $new_instance['post_title'] ) ) {
393 300 $this->maybe_update_status( $new_instance, $old_instance );
394 - $action_ids[] = $new_instance['ID'];
395 - $this->updated = true;
396 - continue;
397 - }
301 + $action_ids[] = $new_instance['ID'];
302 + $this->updated = true;
303 + continue;
304 + }
398 305
399 306 $new_instance['post_type'] = FrmFormActionsController::$action_post_type;
400 307 $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number;
401 308 $new_instance['menu_order'] = $this->form_id;
402 309 $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
403 - $instance = $this->update( $new_instance, $old_instance );
404 310
311 + $instance = $this->update( $new_instance, $old_instance );
312 +
405 313 /**
406 314 * Filter an action's settings before saving.
407 315 *
408 316 * Returning false will effectively short-circuit the widget's ability
@@ -409,17 +317,17 @@
409 317 * to update settings.
410 318 *
411 319 * @since 2.0
412 320 *
413 - * @param array $instance The current widget instance's settings.
414 - * @param array $new_instance Array of new widget settings.
415 - * @param array $old_instance Array of old widget settings.
416 - * @param WP_Widget $this The current widget instance.
321 + * @param array $instance The current widget instance's settings.
322 + * @param array $new_instance Array of new widget settings.
323 + * @param array $old_instance Array of old widget settings.
324 + * @param WP_Widget $this The current widget instance.
417 325 */
418 326 $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
419 327
420 328 $instance['post_content'] = apply_filters( 'frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this );
421 - $instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this );
329 + $instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this );
422 330
423 331 if ( false !== $instance ) {
424 332 $all_instances[ $number ] = $instance;
425 333 }
@@ -425,40 +333,33 @@
425 333 }
426 334
427 335 $action_ids[] = $this->save_settings( $instance );
428 336
429 - $this->updated = true;
430 - }
337 + $this->updated = true;
338 + }
431 339
432 - return $action_ids;
433 - }
340 + return $action_ids;
341 + }
434 342
435 343 /**
436 344 * If the status of the action has changed, update it
437 345 *
438 346 * @since 3.04
439 - *
440 - * @param array $new_instance
441 - * @param stdClass|array $old_instance
442 - * @return void
443 347 */
444 348 protected function maybe_update_status( $new_instance, $old_instance ) {
445 - if ( ! is_object( $old_instance ) || $new_instance['post_status'] === $old_instance->post_status ) {
446 - return;
349 + if ( $new_instance['post_status'] !== $old_instance->post_status ) {
350 + self::clear_cache();
351 + wp_update_post(
352 + array(
353 + 'ID' => $new_instance['ID'],
354 + 'post_status' => $new_instance['post_status'],
355 + )
356 + );
447 357 }
448 -
449 - self::clear_cache();
450 - wp_update_post(
451 - array(
452 - 'ID' => $new_instance['ID'],
453 - 'post_status' => $new_instance['post_status'],
454 - )
455 - );
456 358 }
457 359
458 360 public function save_settings( $settings ) {
459 361 self::clear_cache();
460 -
461 362 return FrmDb::save_settings( $settings, 'frm_actions' );
462 363 }
463 364
464 365 public function get_single_action( $id ) {
@@ -466,10 +367,9 @@
466 367 if ( $action ) {
467 368 $action = $this->prepare_action( $action );
468 369 $this->_set( $id );
469 370 }
470 -
471 - return $action;
371 + return $action;
472 372 }
473 373
474 374 public function get_one( $form_id ) {
475 375 return $this->get_all( $form_id, 1 );
@@ -474,14 +374,14 @@
474 374 public function get_one( $form_id ) {
475 375 return $this->get_all( $form_id, 1 );
476 376 }
477 377
478 - public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) {
479 - $action_controls = FrmFormActionsController::get_form_actions( $type );
378 + public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) {
379 + $action_controls = FrmFormActionsController::get_form_actions( $type );
480 380 if ( empty( $action_controls ) ) {
481 - // don't continue if there are no available actions
482 - return array();
483 - }
381 + // don't continue if there are no available actions
382 + return array();
383 + }
484 384
485 385 if ( 'all' != $type ) {
486 386 return $action_controls->get_all( $form_id, $atts );
487 387 }
@@ -489,47 +389,44 @@
489 389 self::prepare_get_action( $atts );
490 390
491 391 $limit = apply_filters( 'frm_form_action_limit', $atts['limit'], compact( 'type', 'form_id' ) );
492 392
493 - $args = self::action_args( $form_id, $limit );
393 + $args = self::action_args( $form_id, $limit );
494 394 $args['post_status'] = $atts['post_status'];
495 - $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
395 + $actions = FrmDb::check_cache( serialize( $args ), 'frm_actions', $args, 'get_posts' );
496 396
497 - if ( ! $actions ) {
498 - return array();
499 - }
397 + if ( ! $actions ) {
398 + return array();
399 + }
500 400
501 - $settings = array();
502 - foreach ( $actions as $action ) {
401 + $settings = array();
402 + foreach ( $actions as $action ) {
503 403 // some plugins/themes are formatting the post_excerpt
504 404 $action->post_excerpt = sanitize_title( $action->post_excerpt );
505 405
506 406 if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) {
507 - continue;
508 - }
407 + continue;
408 + }
509 409
510 - $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
410 + $action = $action_controls[ $action->post_excerpt ]->prepare_action( $action );
511 411 $settings[ $action->ID ] = $action;
512 412
513 413 if ( count( $settings ) >= $limit ) {
514 414 break;
515 415 }
516 - }
416 + }
517 417
518 - if ( 1 === $limit ) {
418 + if ( 1 === $limit ) {
519 419 $settings = reset( $settings );
520 - }
420 + }
521 421
522 - return $settings;
523 - }
422 + return $settings;
423 + }
524 424
525 425 /**
526 426 * @since 3.04
527 - *
528 427 * @param array $args
529 428 * @param string $default_status
530 - *
531 - * @return void
532 429 */
533 430 protected static function prepare_get_action( &$args, $default_status = 'publish' ) {
534 431 if ( is_numeric( $args ) ) {
535 432 // for reverse compatibility. $limit was changed to $args
@@ -540,9 +437,9 @@
540 437 $defaults = array(
541 438 'limit' => 99,
542 439 'post_status' => $default_status,
543 440 );
544 - $args = wp_parse_args( $args, $defaults );
441 + $args = wp_parse_args( $args, $defaults );
545 442 }
546 443
547 444 /**
548 445 * @param int $action_id
@@ -551,76 +448,65 @@
551 448 if ( ! $type ) {
552 449 return false;
553 450 }
554 451 $action_control = FrmFormActionsController::get_form_actions( $type );
555 -
556 452 return $action_control->get_single_action( $action_id );
557 453 }
558 454
559 455 /**
560 456 * @param int $form_id
561 - *
562 457 * @return bool
563 458 */
564 459 public static function form_has_action_type( $form_id, $type ) {
565 460 $payment_actions = self::get_action_for_form( $form_id, $type );
566 -
567 461 return ! empty( $payment_actions );
568 462 }
569 463
570 464 public function get_all( $form_id = false, $atts = array() ) {
571 - if ( is_array( $atts ) && ! isset( $atts['limit'] ) && $this->action_options['limit'] > 99 ) {
572 - $atts['limit'] = $this->action_options['limit'];
573 - }
574 -
575 465 self::prepare_get_action( $atts, 'any' );
576 -
577 466 $limit = $atts['limit'];
578 467
579 - if ( $form_id ) {
580 - $this->form_id = $form_id;
581 - }
468 + if ( $form_id ) {
469 + $this->form_id = $form_id;
470 + }
582 471
583 - $type = $this->id_base;
472 + $type = $this->id_base;
584 473
585 - global $frm_vars;
586 - $frm_vars['action_type'] = $type;
474 + global $frm_vars;
475 + $frm_vars['action_type'] = $type;
587 476
588 477 add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
589 478 $query = self::action_args( $form_id, $limit );
590 479 $query['post_status'] = $atts['post_status'];
591 - $query['suppress_filters'] = false;
480 + $query['suppress_filters'] = false;
592 481
593 - $actions = FrmDb::check_cache( json_encode( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
482 + $actions = FrmDb::check_cache( serialize( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
594 483 unset( $query );
595 484
596 485 remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
597 486
598 487 if ( empty( $actions ) ) {
599 - return array();
600 - }
488 + return array();
489 + }
601 490
602 - $settings = array();
603 - foreach ( $actions as $action ) {
491 + $settings = array();
492 + foreach ( $actions as $action ) {
604 493 if ( count( $settings ) >= $limit ) {
605 - continue;
606 - }
494 + continue;
495 + }
607 496
608 497 $action = $this->prepare_action( $action );
609 498
610 499 $settings[ $action->ID ] = $action;
611 - }
500 + }
612 501
613 - if ( 1 === $limit ) {
502 + if ( 1 === $limit ) {
614 503 $settings = reset( $settings );
615 - }
504 + }
616 505
617 - return $settings;
506 + return $settings;
618 507 }
619 508
620 - /**
621 - * @return array
622 - */
623 509 public static function action_args( $form_id = 0, $limit = 99 ) {
624 510 $args = array(
625 511 'post_type' => FrmFormActionsController::$action_post_type,
626 512 'post_status' => 'publish',
@@ -635,57 +521,51 @@
635 521
636 522 return $args;
637 523 }
638 524
639 - /**
640 - * @param WP_Post|array $action
641 - */
642 525 public function prepare_action( $action ) {
643 526 $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content );
644 527 $action->post_excerpt = sanitize_title( $action->post_excerpt );
645 528
646 - $default_values = $this->get_global_defaults();
529 + $default_values = $this->get_global_defaults();
647 530
648 - // fill default values
649 - $action->post_content += $default_values;
531 + // fill default values
532 + $action->post_content += $default_values;
650 533
651 - foreach ( $default_values as $k => $vals ) {
534 + foreach ( $default_values as $k => $vals ) {
652 535 if ( is_array( $vals ) && ! empty( $vals ) ) {
653 - if ( 'event' === $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
654 - continue;
655 - }
536 + if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
537 + continue;
538 + }
656 539 $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
657 - }
658 - }
540 + }
541 + }
659 542
660 543 if ( ! is_array( $action->post_content['event'] ) ) {
661 544 $action->post_content['event'] = explode( ',', $action->post_content['event'] );
662 545 }
663 546
664 - return $action;
547 + return $action;
665 548 }
666 549
667 - /**
668 - * @return void
669 - */
670 550 public function destroy( $form_id = false, $type = 'default' ) {
671 - global $wpdb;
551 + global $wpdb;
672 552
673 - $this->form_id = $form_id;
553 + $this->form_id = $form_id;
674 554
675 - $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
676 - if ( $form_id ) {
677 - $query['menu_order'] = $form_id;
678 - }
679 - if ( 'all' != $type ) {
680 - $query['post_excerpt'] = $this->id_base;
681 - }
555 + $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
556 + if ( $form_id ) {
557 + $query['menu_order'] = $form_id;
558 + }
559 + if ( 'all' != $type ) {
560 + $query['post_excerpt'] = $this->id_base;
561 + }
682 562
683 - $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
563 + $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
684 564
685 - foreach ( $post_ids as $id ) {
565 + foreach ( $post_ids as $id ) {
686 566 wp_delete_post( $id );
687 - }
567 + }
688 568 self::clear_cache();
689 569 }
690 570
691 571 /**
@@ -691,10 +571,8 @@
691 571 /**
692 572 * Delete the action cache when a form action is created, deleted, or updated
693 573 *
694 574 * @since 2.0.5
695 - *
696 - * @return void
697 575 */
698 576 public static function clear_cache() {
699 577 FrmDb::cache_delete_group( 'frm_actions' );
700 578 }
@@ -702,35 +580,29 @@
702 580 public function get_settings() {
703 581 return self::get_action_for_form( $this->form_id, $this->id_base );
704 582 }
705 583
706 - /**
707 - * @return array
708 - */
709 584 public function get_global_defaults() {
710 - $defaults = $this->get_defaults();
585 + $defaults = $this->get_defaults();
711 586
712 587 if ( ! isset( $defaults['event'] ) ) {
713 588 $defaults['event'] = array( 'create' );
714 - }
589 + }
715 590
716 591 if ( ! isset( $defaults['conditions'] ) ) {
717 - $defaults['conditions'] = array(
718 - 'send_stop' => '',
719 - 'any_all' => '',
720 - );
721 - }
592 + $defaults['conditions'] = array(
593 + 'send_stop' => '',
594 + 'any_all' => '',
595 + );
596 + }
722 597
723 - return $defaults;
598 + return $defaults;
724 599 }
725 600
726 601 public function get_global_switch_fields() {
727 - $switch = $this->get_switch_fields();
602 + $switch = $this->get_switch_fields();
728 603 $switch['conditions'] = array( 'hide_field' );
729 -
730 - $switch = apply_filters( 'frm_global_switch_fields', $switch );
731 -
732 - return $switch;
604 + return $switch;
733 605 }
734 606
735 607 /**
736 608 * Migrate settings from form->options into new action.
@@ -735,28 +607,28 @@
735 607 /**
736 608 * Migrate settings from form->options into new action.
737 609 */
738 610 public function migrate_to_2( $form, $update = 'update' ) {
739 - $action = $this->prepare_new( $form->id );
740 - FrmAppHelper::unserialize_or_decode( $form->options );
611 + $action = $this->prepare_new( $form->id );
612 + $form->options = maybe_unserialize( $form->options );
741 613
742 - // fill with existing options
743 - foreach ( $action->post_content as $name => $val ) {
614 + // fill with existing options
615 + foreach ( $action->post_content as $name => $val ) {
744 616 if ( isset( $form->options[ $name ] ) ) {
745 617 $action->post_content[ $name ] = $form->options[ $name ];
746 618 unset( $form->options[ $name ] );
747 - }
748 - }
619 + }
620 + }
749 621
750 622 $action = $this->migrate_values( $action, $form );
751 623
752 - // check if action already exists
624 + // check if action already exists
753 625 $post_id = get_posts(
754 626 array(
755 - 'name' => $action->post_name,
756 - 'post_type' => FrmFormActionsController::$action_post_type,
757 - 'post_status' => $action->post_status,
758 - 'numberposts' => 1,
627 + 'name' => $action->post_name,
628 + 'post_type' => FrmFormActionsController::$action_post_type,
629 + 'post_status' => $action->post_status,
630 + 'numberposts' => 1,
759 631 )
760 632 );
761 633
762 634 if ( empty( $post_id ) ) {
@@ -763,29 +635,24 @@
763 635 // create action now
764 636 $post_id = $this->save_settings( $action );
765 637 }
766 638
767 - if ( $post_id && 'update' == $update ) {
768 - global $wpdb;
639 + if ( $post_id && 'update' == $update ) {
640 + global $wpdb;
769 641 $form->options = maybe_serialize( $form->options );
770 642
771 - // update form options
643 + // update form options
772 644 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) );
773 - FrmForm::clear_form_cache();
774 - }
645 + FrmForm::clear_form_cache();
646 + }
775 647
776 - return $post_id;
777 - }
648 + return $post_id;
649 + }
778 650
779 651 public static function action_conditions_met( $action, $entry ) {
780 - if ( is_callable( 'FrmProFormActionsController::action_conditions_met' ) ) {
781 - return FrmProFormActionsController::action_conditions_met( $action, $entry );
782 - }
783 -
784 - // This is here for reverse compatibility.
785 652 $notification = $action->post_content;
786 - $stop = false;
787 - $met = array();
653 + $stop = false;
654 + $met = array();
788 655
789 656 if ( ! isset( $notification['conditions'] ) || empty( $notification['conditions'] ) ) {
790 657 return $stop;
791 658 }
@@ -798,9 +665,9 @@
798 665 if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) {
799 666 continue;
800 667 }
801 668
802 - self::prepare_logic_value( $condition['hide_opt'], $action, $entry );
669 + self::prepare_logic_value( $condition['hide_opt'] );
803 670
804 671 $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] );
805 672
806 673 $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] );
@@ -824,16 +691,11 @@
824 691 /**
825 692 * Prepare the logic value for comparison against the entered value
826 693 *
827 694 * @since 2.01.02
828 - *
829 - * @deprecated 4.06.02
830 - *
831 695 * @param array|string $logic_value
832 - *
833 - * @return void
834 696 */
835 - private static function prepare_logic_value( &$logic_value, $action, $entry ) {
697 + private static function prepare_logic_value( &$logic_value ) {
836 698 if ( is_array( $logic_value ) ) {
837 699 $logic_value = reset( $logic_value );
838 700 }
839 701
@@ -839,26 +701,17 @@
839 701
840 702 if ( $logic_value == 'current_user' ) {
841 703 $logic_value = get_current_user_id();
842 704 }
705 + }
843 706
844 - $logic_value = apply_filters( 'frm_content', $logic_value, $action->menu_order, $entry );
845 707
846 - /**
847 - * @since 4.04.05
848 - */
849 - $logic_value = apply_filters( 'frm_action_logic_value', $logic_value );
850 - }
851 -
852 708 /**
853 709 * Get the value from a specific field and entry
854 710 *
855 711 * @since 2.01.02
856 - * @deprecated 4.06.02
857 - *
858 712 * @param object $entry
859 713 * @param int $field_id
860 - *
861 714 * @return array|bool|mixed|string
862 715 */
863 716 private static function get_value_from_entry( $entry, $field_id ) {
864 717 $observed_value = '';
@@ -864,10 +717,10 @@
864 717 $observed_value = '';
865 718
866 719 if ( isset( $entry->metas[ $field_id ] ) ) {
867 720 $observed_value = $entry->metas[ $field_id ];
868 - } elseif ( $entry->post_id && FrmAppHelper::pro_is_installed() ) {
869 - $field = FrmField::getOne( $field_id );
721 + } else if ( $entry->post_id && FrmAppHelper::pro_is_installed() ) {
722 + $field = FrmField::getOne( $field_id );
870 723 $observed_value = FrmProEntryMetaHelper::get_post_or_meta_value(
871 724 $entry,
872 725 $field,
873 726 array(
@@ -879,49 +732,23 @@
879 732
880 733 return $observed_value;
881 734 }
882 735
883 - /**
884 - * @param string $class
885 - *
886 - * @return array
887 - */
888 736 public static function default_action_opts( $class = '' ) {
889 737 return array(
890 - 'classes' => 'frm_icon_font ' . $class,
891 - 'active' => false,
892 - 'limit' => 0,
738 + 'classes' => 'frm_icon_font ' . $class,
739 + 'active' => false,
740 + 'limit' => 0,
893 741 );
894 742 }
895 743
896 744 public static function trigger_labels() {
897 745 $triggers = array(
898 - 'draft' => __( 'Draft is saved', 'formidable' ),
899 - 'create' => __( 'Entry is created', 'formidable' ),
900 - 'update' => __( 'Entry is updated', 'formidable' ),
901 - 'delete' => __( 'Entry is deleted', 'formidable' ),
902 - 'import' => __( 'Entry is imported', 'formidable' ),
746 + 'draft' => __( 'Save Draft', 'formidable' ),
747 + 'create' => __( 'Create', 'formidable' ),
748 + 'update' => __( 'Update', 'formidable' ),
749 + 'delete' => __( 'Delete', 'formidable' ),
750 + 'import' => __( 'Import', 'formidable' ),
903 751 );
904 -
905 752 return apply_filters( 'frm_action_triggers', $triggers );
906 - }
907 -
908 - /**
909 - * @return void
910 - */
911 - public function render_conditional_logic_call_to_action() {
912 - ?>
913 - <h3>
914 - <a href="javascript:void(0)" class="frm_show_upgrade frm_noallow" data-upgrade="<?php echo esc_attr( $this->get_upgrade_text() ); ?>" data-medium="conditional-<?php echo esc_attr( $this->id_base ); ?>">
915 - <?php esc_html_e( 'Use Conditional Logic', 'formidable' ); ?>
916 - </a>
917 - </h3>
918 - <?php
919 - }
920 -
921 - /**
922 - * @return string
923 - */
924 - protected function get_upgrade_text() {
925 - return __( 'Conditional form actions', 'formidable' );
926 753 }
927 754 }