PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.07.01
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.07.01
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 +150 -356 6.26.14.07.01 View file →
@@ -4,71 +4,19 @@
4 4 }
5 5
6 6 class FrmFormAction {
7 7
8 - /**
9 - * Root id for all actions of this type.
10 - *
11 - * @var string
12 - */
13 - public $id_base;
14 -
15 - /**
16 - * Name for this action type.
17 - *
18 - * @var string
19 - */
20 - public $name;
21 -
22 - /**
23 - * Name of the option used to store the settings for this action type.
24 - *
25 - * @var string
26 - */
8 + public $id_base; // Root id for all actions of this type.
9 + public $name; // Name for this action type.
27 10 public $option_name;
11 + public $action_options; // Option array passed to wp_register_sidebar_widget()
12 + public $control_options; // Option array passed to wp_register_widget_control()
28 13
29 - /**
30 - * Option array passed to wp_register_sidebar_widget().
31 - *
32 - * @var array
33 - */
34 - public $action_options;
14 + public $form_id; // The ID of the form to evaluate
15 + public $number = false; // Unique ID number of the current instance.
16 + public $id = ''; // Unique ID string of the current instance (id_base-number)
17 + public $updated = false; // Set true when we update the data after a POST submit - makes sure we don't do it twice.
35 18
36 - /**
37 - * Option array passed to wp_register_widget_control().
38 - *
39 - * @var array
40 - */
41 - public $control_options;
42 -
43 - /**
44 - * The ID of the form to evaluate.
45 - *
46 - * @var int
47 - */
48 - public $form_id;
49 -
50 - /**
51 - * Unique ID number of the current instance.
52 - *
53 - * @var int
54 - */
55 - public $number = false;
56 -
57 - /**
58 - * Unique ID string of the current instance (id_base-number).
59 - *
60 - * @var string
61 - */
62 - public $id = '';
63 -
64 - /**
65 - * Set true when we update the data after a POST submit - makes sure we don't do it twice.
66 - *
67 - * @var bool
68 - */
69 - public $updated = false;
70 -
71 19 // Member functions that you must over-ride.
72 20
73 21 /**
74 22 * This function should check that $new_instance is set correctly.
@@ -74,10 +22,10 @@
74 22 * This function should check that $new_instance is set correctly.
75 23 * The newly calculated value of $instance should be returned.
76 24 * If "false" is returned, the instance won't be saved/updated.
77 25 *
78 - * @param array $new_instance New settings for this instance as input by the user via form().
79 - * @param array $old_instance Old settings for this instance.
26 + * @param array $new_instance New settings for this instance as input by the user via form()
27 + * @param array $old_instance Old settings for this instance
80 28 *
81 29 * @return array Settings to save or bool false to cancel saving
82 30 */
83 31 public function update( $new_instance, $old_instance ) {
@@ -86,12 +34,9 @@
86 34
87 35 /**
88 36 * Echo the settings update form
89 37 *
90 - * @param WP_Post $instance Current settings.
91 - * @param array $args
92 - *
93 - * @return string
38 + * @param array $instance Current settings
94 39 */
95 40 public function form( $instance, $args = array() ) {
96 41 echo '<p class="no-options-widget">' . esc_html__( 'There are no options for this action.', 'formidable' ) . '</p>';
97 42
@@ -104,21 +49,12 @@
104 49 public function get_defaults() {
105 50 return array();
106 51 }
107 52
108 - /**
109 - * @return array
110 - */
111 53 public function get_switch_fields() {
112 54 return array();
113 55 }
114 56
115 - /**
116 - * @param object $action
117 - * @param object $form
118 - *
119 - * @return object
120 - */
121 57 public function migrate_values( $action, $form ) {
122 58 return $action;
123 59 }
124 60
@@ -129,14 +65,14 @@
129 65 *
130 66 * @param string $id_base Optional Base ID for the widget, lower case,
131 67 * if left empty a portion of the widget's class name will be used. Has to be unique.
132 68 * @param string $name Name for the widget displayed on the configuration page.
133 - * @param array $action_options Optional Passed to wp_register_sidebar_widget().
134 - * - description: shown on the configuration page.
135 - * - classname.
136 - * @param array $control_options Optional Passed to wp_register_widget_control().
137 - * - width: required if more than 250px.
138 - * - height: currently not used but may be needed in the future.
69 + * @param array $action_options Optional Passed to wp_register_sidebar_widget()
70 + * - description: shown on the configuration page
71 + * - classname
72 + * @param array $control_options Optional Passed to wp_register_widget_control()
73 + * - width: required if more than 250px
74 + * - height: currently not used but may be needed in the future
139 75 */
140 76 public function __construct( $id_base, $name, $action_options = array(), $control_options = array() ) {
141 77 if ( ! defined( 'ABSPATH' ) ) {
142 78 die( 'You are not allowed to call this page directly.' );
@@ -157,9 +93,8 @@
157 93 'plugin' => $this->id_base,
158 94 'tooltip' => $name,
159 95 'group' => $id_base,
160 96 'color' => '',
161 - 'keywords' => '',
162 97 );
163 98
164 99 $action_options = apply_filters( 'frm_' . $id_base . '_action_options', $action_options );
165 100 $group = $this->get_group( $action_options );
@@ -170,14 +105,13 @@
170 105 shuffle( $colors );
171 106 $action_options['color'] = 'var(--' . reset( $colors ) . ')';
172 107 }
173 108
174 - $upgrade_class = isset( $action_options['classes'] ) && $action_options['classes'] === 'frm_show_upgrade';
175 -
109 + $upgrade_class = $action_options['classes'] === 'frm_show_upgrade';
176 110 if ( $action_options['group'] === $id_base ) {
177 - $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false;
111 + $upgrade_class = strpos( $action_options['classes'], 'frm_show_upgrade' ) !== false;
178 112 $action_options['classes'] = $group['icon'];
179 - } elseif ( empty( $action_options['classes'] ) || $upgrade_class ) {
113 + } elseif ( ! isset( $action_options['classes'] ) || empty( $action_options['classes'] ) || $upgrade_class ) {
180 114 $action_options['classes'] = $group['icon'];
181 115 }
182 116
183 117 if ( $upgrade_class ) {
@@ -189,13 +123,8 @@
189 123 }
190 124
191 125 /**
192 126 * @param string $id_base
193 - * @param string $name
194 - * @param array $action_options
195 - * @param array $control_options
196 - *
197 - * @return void
198 127 */
199 128 public function FrmFormAction( $id_base, $name, $action_options = array(), $control_options = array() ) {
200 129 self::__construct( $id_base, $name, $action_options, $control_options );
201 130 }
@@ -200,29 +129,9 @@
200 129 self::__construct( $id_base, $name, $action_options, $control_options );
201 130 }
202 131
203 132 /**
204 - * Help to switch old field id by new field id for duplicate form
205 - *
206 - * @param string $action id of the field that needs to be switched.
207 - *
208 - * @return string
209 - */
210 - public function maybe_switch_field_ids( $action ) {
211 - $updated_action = apply_filters( 'frm_maybe_switch_field_ids', $action );
212 -
213 - if ( $updated_action === $action ) {
214 - $updated_action = FrmFieldsHelper::switch_field_ids( $action );
215 - }
216 - return $updated_action;
217 - }
218 -
219 - /**
220 133 * @since 4.0
221 - *
222 - * @param array $action_options
223 - *
224 - * @return array
225 134 */
226 135 protected function get_group( $action_options ) {
227 136 $groups = FrmFormActionsController::form_action_groups();
228 137 $group = 'misc';
@@ -248,15 +157,14 @@
248 157 * Constructs name attributes for use in form() fields
249 158 *
250 159 * This function should be used in form() methods to create name attributes for fields to be saved by update()
251 160 *
252 - * @param string $field_name Field name.
253 - * @param string $post_field
161 + * @param string $field_name Field name
254 162 *
255 163 * @return string Name attribute for $field_name
256 164 */
257 165 public function get_field_name( $field_name, $post_field = 'post_content' ) {
258 - $name = $this->option_name . '[' . $this->number . ']';
166 + $name = $this->option_name . '[' . $this->number . ']';
259 167 $name .= ( empty( $post_field ) ? '' : '[' . $post_field . ']' );
260 168 $name .= '[' . $field_name . ']';
261 169
262 170 return $name;
@@ -266,9 +174,9 @@
266 174 * Constructs id attributes for use in form() fields
267 175 *
268 176 * This function should be used in form() methods to create id attributes for fields to be saved by update()
269 177 *
270 - * @param string $field_name Field name.
178 + * @param string $field_name Field name
271 179 *
272 180 * @return string ID attribute for $field_name
273 181 */
274 182 public function get_field_id( $field_name ) {
@@ -274,23 +182,15 @@
274 182 public function get_field_id( $field_name ) {
275 183 return $field_name . '_' . $this->number;
276 184 }
277 185
278 - /**
279 - * @param int|string $number
280 - *
281 - * @return void
282 - */
186 + // Private Function. Don't worry about this.
187 +
283 188 public function _set( $number ) {
284 189 $this->number = $number;
285 190 $this->id = $this->id_base . '-' . $number;
286 191 }
287 192
288 - /**
289 - * @param false|int|string $form_id
290 - *
291 - * @return object
292 - */
293 193 public function prepare_new( $form_id = false ) {
294 194 if ( $form_id ) {
295 195 $this->form_id = $form_id;
296 196 }
@@ -319,13 +219,8 @@
319 219
320 220 return (object) $form_action;
321 221 }
322 222
323 - /**
324 - * @param int|string $form_id
325 - *
326 - * @return int|WP_Error
327 - */
328 223 public function create( $form_id ) {
329 224 $this->form_id = $form_id;
330 225
331 226 $action = $this->prepare_new();
@@ -332,14 +227,8 @@
332 227
333 228 return $this->save_settings( $action );
334 229 }
335 230
336 - /**
337 - * @param int|string $form_id
338 - * @param int|string $old_id
339 - *
340 - * @return void
341 - */
342 231 public function duplicate_form_actions( $form_id, $old_id ) {
343 232 if ( $form_id == $old_id ) {
344 233 // don't duplicate the actions if this is a template getting updated
345 234 return;
@@ -348,9 +237,8 @@
348 237 $this->form_id = $old_id;
349 238 $actions = $this->get_all( $old_id );
350 239
351 240 $this->form_id = $form_id;
352 -
353 241 foreach ( $actions as $action ) {
354 242 $this->duplicate_one( $action, $form_id );
355 243 unset( $action );
356 244 }
@@ -355,20 +243,17 @@
355 243 unset( $action );
356 244 }
357 245 }
358 246
359 - /**
360 - * Check if imported action should be created or updated.
247 + /* Check if imported action should be created or updated
361 248 *
362 249 * @since 2.0
363 250 *
364 251 * @param array $action
365 - * @param array $forms
366 - *
367 - * @return int $post_id
252 + * @return integer $post_id
368 253 */
369 254 public function maybe_create_action( $action, $forms ) {
370 - if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] === 'updated' ) {
255 + if ( isset( $action['ID'] ) && is_numeric( $action['ID'] ) && isset( $forms[ $action['menu_order'] ] ) && $forms[ $action['menu_order'] ] == 'updated' ) {
371 256 // Update action only
372 257 $action['post_content'] = FrmAppHelper::maybe_json_decode( $action['post_content'] );
373 258 $post_id = $this->save_settings( $action );
374 259 } else {
@@ -379,20 +264,13 @@
379 264
380 265 return $post_id;
381 266 }
382 267
383 - /**
384 - * @param object $action
385 - * @param int|string $form_id
386 - *
387 - * @return int|WP_Error
388 - */
389 268 public function duplicate_one( $action, $form_id ) {
390 269 global $frm_duplicate_ids;
391 270
392 271 $action->menu_order = $form_id;
393 272 $switch = $this->get_global_switch_fields();
394 -
395 273 foreach ( (array) $action->post_content as $key => $val ) {
396 274 if ( is_numeric( $val ) && isset( $frm_duplicate_ids[ $val ] ) ) {
397 275 $action->post_content[ $key ] = $frm_duplicate_ids[ $val ];
398 276 } elseif ( ! is_array( $val ) ) {
@@ -414,15 +292,8 @@
414 292
415 293 return $this->save_settings( $action );
416 294 }
417 295
418 - /**
419 - * @param array $action
420 - * @param array|string $subkey
421 - * @param mixed $val
422 - *
423 - * @return array
424 - */
425 296 private function duplicate_array_walk( $action, $subkey, $val ) {
426 297 global $frm_duplicate_ids;
427 298
428 299 if ( is_array( $subkey ) ) {
@@ -441,12 +312,12 @@
441 312 $action[ $ck ] = $this->duplicate_array_walk( $action[ $ck ], $subkey, $cv );
442 313 } elseif ( $ck == $subkey && isset( $frm_duplicate_ids[ $cv ] ) ) {
443 314 $action[ $ck ] = $frm_duplicate_ids[ $cv ];
444 315 } elseif ( $ck == $subkey ) {
445 - $action[ $ck ] = $this->maybe_switch_field_ids( $action[ $ck ] );
316 + $action[ $ck ] = FrmFieldsHelper::switch_field_ids( $action[ $ck ] );
446 317 }
447 318 }
448 - }//end if
319 + }
449 320
450 321 return $action;
451 322 }
452 323
@@ -453,12 +324,8 @@
453 324 /**
454 325 * Deal with changed settings.
455 326 *
456 327 * Do NOT over-ride this function
457 - *
458 - * @param int|string $form_id
459 - *
460 - * @return array|null
461 328 */
462 329 public function update_callback( $form_id ) {
463 330 $this->form_id = $form_id;
464 331
@@ -468,12 +335,11 @@
468 335 if ( $this->updated ) {
469 336 return;
470 337 }
471 338
472 - // phpcs:ignore WordPress.Security.NonceVerification.Missing
473 339 if ( isset( $_POST[ $this->option_name ] ) && is_array( $_POST[ $this->option_name ] ) ) {
474 340 // Sanitizing removes scripts and <email> type of values.
475 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
341 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
476 342 $settings = wp_unslash( $_POST[ $this->option_name ] );
477 343 } else {
478 344 return;
479 345 }
@@ -482,9 +348,9 @@
482 348
483 349 foreach ( $settings as $number => $new_instance ) {
484 350 $this->_set( $number );
485 351
486 - $old_instance = $all_instances[ $number ] ?? array();
352 + $old_instance = isset( $all_instances[ $number ] ) ? $all_instances[ $number ] : array();
487 353
488 354 if ( ! isset( $new_instance['post_status'] ) ) {
489 355 $new_instance['post_status'] = 'draft';
490 356 }
@@ -499,11 +365,12 @@
499 365
500 366 $new_instance['post_type'] = FrmFormActionsController::$action_post_type;
501 367 $new_instance['post_name'] = $this->form_id . '_' . $this->id_base . '_' . $this->number;
502 368 $new_instance['menu_order'] = $this->form_id;
503 - $new_instance['post_date'] = $old_instance->post_date ?? '';
504 - $instance = $this->update( $new_instance, $old_instance );
369 + $new_instance['post_date'] = isset( $old_instance->post_date ) ? $old_instance->post_date : '';
505 370
371 + $instance = $this->update( $new_instance, $old_instance );
372 +
506 373 /**
507 374 * Filter an action's settings before saving.
508 375 *
509 376 * Returning false will effectively short-circuit the widget's ability
@@ -510,17 +377,17 @@
510 377 * to update settings.
511 378 *
512 379 * @since 2.0
513 380 *
514 - * @param array $instance The current widget instance's settings.
515 - * @param array $new_instance Array of new widget settings.
516 - * @param array $old_instance Array of old widget settings.
517 - * @param FrmFormAction $form_action FrmFormAction instance.
381 + * @param array $instance The current widget instance's settings.
382 + * @param array $new_instance Array of new widget settings.
383 + * @param array $old_instance Array of old widget settings.
384 + * @param WP_Widget $this The current widget instance.
518 385 */
519 386 $instance = apply_filters( 'frm_action_update_callback', $instance, $new_instance, $old_instance, $this );
520 387
521 388 $instance['post_content'] = apply_filters( 'frm_before_save_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this );
522 - $instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $instance['post_content'], $instance, $new_instance, $old_instance, $this );
389 + $instance['post_content'] = apply_filters( 'frm_before_save_' . $this->id_base . '_action', $new_instance['post_content'], $instance, $new_instance, $old_instance, $this );
523 390
524 391 if ( false !== $instance ) {
525 392 $all_instances[ $number ] = $instance;
526 393 }
@@ -527,9 +394,9 @@
527 394
528 395 $action_ids[] = $this->save_settings( $instance );
529 396
530 397 $this->updated = true;
531 - }//end foreach
398 + }
532 399
533 400 return $action_ids;
534 401 }
535 402
@@ -536,33 +403,21 @@
536 403 /**
537 404 * If the status of the action has changed, update it
538 405 *
539 406 * @since 3.04
540 - *
541 - * @param array $new_instance
542 - * @param array|stdClass $old_instance
543 - *
544 - * @return void
545 407 */
546 408 protected function maybe_update_status( $new_instance, $old_instance ) {
547 - if ( ! is_object( $old_instance ) || $new_instance['post_status'] === $old_instance->post_status ) {
548 - return;
409 + if ( $new_instance['post_status'] !== $old_instance->post_status ) {
410 + self::clear_cache();
411 + wp_update_post(
412 + array(
413 + 'ID' => $new_instance['ID'],
414 + 'post_status' => $new_instance['post_status'],
415 + )
416 + );
549 417 }
550 -
551 - self::clear_cache();
552 - wp_update_post(
553 - array(
554 - 'ID' => $new_instance['ID'],
555 - 'post_status' => $new_instance['post_status'],
556 - )
557 - );
558 418 }
559 419
560 - /**
561 - * @param array $settings
562 - *
563 - * @return int|WP_Error
564 - */
565 420 public function save_settings( $settings ) {
566 421 self::clear_cache();
567 422
568 423 return FrmDb::save_settings( $settings, 'frm_actions' );
@@ -567,16 +422,10 @@
567 422
568 423 return FrmDb::save_settings( $settings, 'frm_actions' );
569 424 }
570 425
571 - /**
572 - * @param int $id
573 - *
574 - * @return object|null
575 - */
576 426 public function get_single_action( $id ) {
577 427 $action = get_post( $id );
578 -
579 428 if ( $action ) {
580 429 $action = $this->prepare_action( $action );
581 430 $this->_set( $id );
582 431 }
@@ -583,42 +432,26 @@
583 432
584 433 return $action;
585 434 }
586 435
587 - /**
588 - * @param int|string $form_id
589 - *
590 - * @return array
591 - */
592 436 public function get_one( $form_id ) {
593 437 return $this->get_all( $form_id, 1 );
594 438 }
595 439
596 - /**
597 - * @param int|string $form_id
598 - * @param string $type
599 - * @param array $atts
600 - *
601 - * @return array
602 - */
603 440 public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) {
604 441 $action_controls = FrmFormActionsController::get_form_actions( $type );
605 -
606 442 if ( empty( $action_controls ) ) {
607 443 // don't continue if there are no available actions
608 444 return array();
609 445 }
610 446
611 - if ( 'all' !== $type ) {
612 - if ( is_array( $action_controls ) ) {
613 - return array();
614 - }
447 + if ( 'all' != $type ) {
615 448 return $action_controls->get_all( $form_id, $atts );
616 449 }
617 450
618 451 self::prepare_get_action( $atts );
619 452
620 - $limit = self::get_action_limit( $form_id, $atts['limit'] );
453 + $limit = apply_filters( 'frm_form_action_limit', $atts['limit'], compact( 'type', 'form_id' ) );
621 454
622 455 $args = self::action_args( $form_id, $limit );
623 456 $args['post_status'] = $atts['post_status'];
624 457 $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
@@ -627,9 +460,8 @@
627 460 return array();
628 461 }
629 462
630 463 $settings = array();
631 -
632 464 foreach ( $actions as $action ) {
633 465 // some plugins/themes are formatting the post_excerpt
634 466 $action->post_excerpt = sanitize_title( $action->post_excerpt );
635 467
@@ -652,30 +484,11 @@
652 484 return $settings;
653 485 }
654 486
655 487 /**
656 - * Get the limit for the number of actions for a single form. By default, this is 99, but
657 - * it can be modified with a code snippet.
658 - *
659 - * @since 6.17 This logic from moved from FrmFormAction::get_action_for_form.
660 - *
661 - * @param int|string $form_id
662 - * @param int|string $limit The unfiltered limit value.
663 - *
664 - * @return int The filtered limit value.
665 - */
666 - public static function get_action_limit( $form_id, $limit = 99 ) {
667 - $type = 'all';
668 - return (int) apply_filters( 'frm_form_action_limit', (int) $limit, compact( 'type', 'form_id' ) );
669 - }
670 -
671 - /**
672 488 * @since 3.04
673 - *
674 489 * @param array $args
675 490 * @param string $default_status
676 - *
677 - * @return void
678 491 */
679 492 protected static function prepare_get_action( &$args, $default_status = 'publish' ) {
680 493 if ( is_numeric( $args ) ) {
681 494 // for reverse compatibility. $limit was changed to $args
@@ -682,9 +495,8 @@
682 495 $args = array(
683 496 'limit' => $args,
684 497 );
685 498 }
686 -
687 499 $defaults = array(
688 500 'limit' => 99,
689 501 'post_status' => $default_status,
690 502 );
@@ -691,21 +503,14 @@
691 503 $args = wp_parse_args( $args, $defaults );
692 504 }
693 505
694 506 /**
695 - * @param int $action_id
696 - * @param string $type
697 - *
698 - * @return bool|object
507 + * @param int $action_id
699 508 */
700 509 public static function get_single_action_type( $action_id, $type ) {
701 510 if ( ! $type ) {
702 511 return false;
703 512 }
704 -
705 - /**
706 - * @var FrmFormAction
707 - */
708 513 $action_control = FrmFormActionsController::get_form_actions( $type );
709 514
710 515 return $action_control->get_single_action( $action_id );
711 516 }
@@ -710,31 +515,20 @@
710 515 return $action_control->get_single_action( $action_id );
711 516 }
712 517
713 518 /**
714 - * @param int $form_id
715 - * @param string $type
519 + * @param int $form_id
716 520 *
717 521 * @return bool
718 522 */
719 523 public static function form_has_action_type( $form_id, $type ) {
720 - $actions = self::get_action_for_form( $form_id, $type );
721 - return ! empty( $actions );
524 + $payment_actions = self::get_action_for_form( $form_id, $type );
525 +
526 + return ! empty( $payment_actions );
722 527 }
723 528
724 - /**
725 - * @param false|int|string $form_id
726 - * @param array $atts
727 - *
728 - * @return array
729 - */
730 529 public function get_all( $form_id = false, $atts = array() ) {
731 - if ( is_array( $atts ) && ! isset( $atts['limit'] ) && $this->action_options['limit'] > 99 ) {
732 - $atts['limit'] = $this->action_options['limit'];
733 - }
734 -
735 530 self::prepare_get_action( $atts, 'any' );
736 -
737 531 $limit = $atts['limit'];
738 532
739 533 if ( $form_id ) {
740 534 $this->form_id = $form_id;
@@ -745,10 +539,10 @@
745 539 global $frm_vars;
746 540 $frm_vars['action_type'] = $type;
747 541
748 542 add_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
749 - $query = self::action_args( $form_id, $limit );
750 - $query['post_status'] = $atts['post_status'];
543 + $query = self::action_args( $form_id, $limit );
544 + $query['post_status'] = $atts['post_status'];
751 545 $query['suppress_filters'] = false;
752 546
753 547 $actions = FrmDb::check_cache( json_encode( $query ) . '_type_' . $type, 'frm_actions', $query, 'get_posts' );
754 548 unset( $query );
@@ -759,9 +553,8 @@
759 553 return array();
760 554 }
761 555
762 556 $settings = array();
763 -
764 557 foreach ( $actions as $action ) {
765 558 if ( count( $settings ) >= $limit ) {
766 559 continue;
767 560 }
@@ -777,14 +570,8 @@
777 570
778 571 return $settings;
779 572 }
780 573
781 - /**
782 - * @param int $form_id
783 - * @param int $limit
784 - *
785 - * @return array
786 - */
787 574 public static function action_args( $form_id = 0, $limit = 99 ) {
788 575 $args = array(
789 576 'post_type' => FrmFormActionsController::$action_post_type,
790 577 'post_status' => 'publish',
@@ -799,13 +586,8 @@
799 586
800 587 return $args;
801 588 }
802 589
803 - /**
804 - * @param WP_Post $action
805 - *
806 - * @return WP_Post
807 - */
808 590 public function prepare_action( $action ) {
809 591 $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content );
810 592 $action->post_excerpt = sanitize_title( $action->post_excerpt );
811 593
@@ -815,9 +597,9 @@
815 597 $action->post_content += $default_values;
816 598
817 599 foreach ( $default_values as $k => $vals ) {
818 600 if ( is_array( $vals ) && ! empty( $vals ) ) {
819 - if ( 'event' === $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
601 + if ( 'event' == $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
820 602 continue;
821 603 }
822 604 $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
823 605 }
@@ -829,14 +611,8 @@
829 611
830 612 return $action;
831 613 }
832 614
833 - /**
834 - * @param false|int|string $form_id
835 - * @param string $type
836 - *
837 - * @return void
838 - */
839 615 public function destroy( $form_id = false, $type = 'default' ) {
840 616 global $wpdb;
841 617
842 618 $this->form_id = $form_id;
@@ -841,13 +617,11 @@
841 617
842 618 $this->form_id = $form_id;
843 619
844 620 $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
845 -
846 621 if ( $form_id ) {
847 622 $query['menu_order'] = $form_id;
848 623 }
849 -
850 624 if ( 'all' != $type ) {
851 625 $query['post_excerpt'] = $this->id_base;
852 626 }
853 627
@@ -862,25 +636,17 @@
862 636 /**
863 637 * Delete the action cache when a form action is created, deleted, or updated
864 638 *
865 639 * @since 2.0.5
866 - *
867 - * @return void
868 640 */
869 641 public static function clear_cache() {
870 642 FrmDb::cache_delete_group( 'frm_actions' );
871 643 }
872 644
873 - /**
874 - * @return array
875 - */
876 645 public function get_settings() {
877 646 return self::get_action_for_form( $this->form_id, $this->id_base );
878 647 }
879 648
880 - /**
881 - * @return array
882 - */
883 649 public function get_global_defaults() {
884 650 $defaults = $this->get_defaults();
885 651
886 652 if ( ! isset( $defaults['event'] ) ) {
@@ -896,30 +662,20 @@
896 662
897 663 return $defaults;
898 664 }
899 665
900 - /**
901 - * @return array
902 - */
903 666 public function get_global_switch_fields() {
904 667 $switch = $this->get_switch_fields();
905 668 $switch['conditions'] = array( 'hide_field' );
906 669
907 - $switch = apply_filters( 'frm_global_switch_fields', $switch );
908 -
909 670 return $switch;
910 671 }
911 672
912 673 /**
913 674 * Migrate settings from form->options into new action.
914 - *
915 - * @param object $form
916 - * @param string $update
917 - *
918 - * @return int|WP_Error
919 675 */
920 676 public function migrate_to_2( $form, $update = 'update' ) {
921 - $action = $this->prepare_new( $form->id );
677 + $action = $this->prepare_new( $form->id );
922 678 FrmAppHelper::unserialize_or_decode( $form->options );
923 679
924 680 // fill with existing options
925 681 foreach ( $action->post_content as $name => $val ) {
@@ -957,28 +713,109 @@
957 713
958 714 return $post_id;
959 715 }
960 716
961 - /**
962 - * @param WP_Post $action
963 - * @param stdClass $entry
964 - *
965 - * @return bool
966 - */
967 717 public static function action_conditions_met( $action, $entry ) {
968 718 if ( is_callable( 'FrmProFormActionsController::action_conditions_met' ) ) {
969 719 return FrmProFormActionsController::action_conditions_met( $action, $entry );
970 720 }
971 721
972 - $stop = false;
722 + // This is here for reverse compatibility.
723 + $notification = $action->post_content;
724 + $stop = false;
725 + $met = array();
726 +
727 + if ( ! isset( $notification['conditions'] ) || empty( $notification['conditions'] ) ) {
728 + return $stop;
729 + }
730 +
731 + foreach ( $notification['conditions'] as $k => $condition ) {
732 + if ( ! is_numeric( $k ) ) {
733 + continue;
734 + }
735 +
736 + if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) {
737 + continue;
738 + }
739 +
740 + self::prepare_logic_value( $condition['hide_opt'], $action, $entry );
741 +
742 + $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] );
743 +
744 + $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] );
745 +
746 + if ( $notification['conditions']['send_stop'] == 'send' ) {
747 + $stop = $stop ? false : true;
748 + }
749 +
750 + $met[ $stop ] = $stop;
751 + }
752 +
753 + if ( $notification['conditions']['any_all'] == 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) {
754 + $stop = ( $notification['conditions']['send_stop'] == 'send' );
755 + } elseif ( $notification['conditions']['any_all'] == 'any' && $notification['conditions']['send_stop'] == 'send' && isset( $met[0] ) ) {
756 + $stop = false;
757 + }
758 +
973 759 return $stop;
974 760 }
975 761
976 762 /**
977 - * @param string $class
763 + * Prepare the logic value for comparison against the entered value
978 764 *
979 - * @return array
765 + * @since 2.01.02
766 + * @deprecated 4.06.02
767 + *
768 + * @param array|string $logic_value
980 769 */
770 + private static function prepare_logic_value( &$logic_value, $action, $entry ) {
771 + if ( is_array( $logic_value ) ) {
772 + $logic_value = reset( $logic_value );
773 + }
774 +
775 + if ( $logic_value == 'current_user' ) {
776 + $logic_value = get_current_user_id();
777 + }
778 +
779 + $logic_value = apply_filters( 'frm_content', $logic_value, $action->menu_order, $entry );
780 +
781 + /**
782 + * @since 4.04.05
783 + */
784 + $logic_value = apply_filters( 'frm_action_logic_value', $logic_value );
785 + }
786 +
787 + /**
788 + * Get the value from a specific field and entry
789 + *
790 + * @since 2.01.02
791 + * @deprecated 4.06.02
792 + *
793 + * @param object $entry
794 + * @param int $field_id
795 + *
796 + * @return array|bool|mixed|string
797 + */
798 + private static function get_value_from_entry( $entry, $field_id ) {
799 + $observed_value = '';
800 +
801 + if ( isset( $entry->metas[ $field_id ] ) ) {
802 + $observed_value = $entry->metas[ $field_id ];
803 + } elseif ( $entry->post_id && FrmAppHelper::pro_is_installed() ) {
804 + $field = FrmField::getOne( $field_id );
805 + $observed_value = FrmProEntryMetaHelper::get_post_or_meta_value(
806 + $entry,
807 + $field,
808 + array(
809 + 'links' => false,
810 + 'truncate' => false,
811 + )
812 + );
813 + }
814 +
815 + return $observed_value;
816 + }
817 +
981 818 public static function default_action_opts( $class = '' ) {
982 819 return array(
983 820 'classes' => 'frm_icon_font ' . $class,
984 821 'active' => false,
@@ -985,11 +822,8 @@
985 822 'limit' => 0,
986 823 );
987 824 }
988 825
989 - /**
990 - * @return array
991 - */
992 826 public static function trigger_labels() {
993 827 $triggers = array(
994 828 'draft' => __( 'Draft is saved', 'formidable' ),
995 829 'create' => __( 'Entry is created', 'formidable' ),
@@ -998,46 +832,6 @@
998 832 'import' => __( 'Entry is imported', 'formidable' ),
999 833 );
1000 834
1001 835 return apply_filters( 'frm_action_triggers', $triggers );
1002 - }
1003 -
1004 - /**
1005 - * @return void
1006 - */
1007 - public function render_conditional_logic_call_to_action() {
1008 - ?>
1009 - <h3>
1010 - <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 ); ?>">
1011 - <?php esc_html_e( 'Use Conditional Logic', 'formidable' ); ?>
1012 - </a>
1013 - </h3>
1014 - <?php
1015 - }
1016 -
1017 - /**
1018 - * @return string
1019 - */
1020 - protected function get_upgrade_text() {
1021 - return __( 'Conditional form actions', 'formidable' );
1022 - }
1023 -
1024 - /**
1025 - * Gets form fields for form action settings.
1026 - *
1027 - * @since 6.10
1028 - *
1029 - * @param int $form_id Form ID.
1030 - *
1031 - * @return object[]
1032 - */
1033 - protected function get_form_fields( $form_id ) {
1034 - // Get form fields, include embedded and repeater child fields.
1035 - $form_fields = FrmField::get_all_for_form( $form_id, '', 'include' );
1036 - return array_filter(
1037 - $form_fields,
1038 - function ( $form_field ) {
1039 - return ! FrmField::is_no_save_field( $form_field->type );
1040 - }
1041 - );
1042 836 }
1043 837 }