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