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