PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.18
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.18
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 +193 -238 6.326.18 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.
@@ -547,9 +491,8 @@
547 491 * @since 3.04
548 492 *
549 493 * @param array $new_instance
550 494 * @param array|stdClass $old_instance
551 - *
552 495 * @return void
553 496 */
554 497 protected function maybe_update_status( $new_instance, $old_instance ) {
555 498 if ( ! is_object( $old_instance ) || $new_instance['post_status'] === $old_instance->post_status ) {
@@ -566,24 +509,18 @@
566 509 }
567 510
568 511 /**
569 512 * @param array $settings
570 - *
571 513 * @return int|WP_Error
572 514 */
573 515 public function save_settings( $settings ) {
574 516 self::clear_cache();
517 +
575 518 return FrmDb::save_settings( $settings, 'frm_actions' );
576 519 }
577 520
578 - /**
579 - * @param int $id
580 - *
581 - * @return object|null
582 - */
583 521 public function get_single_action( $id ) {
584 522 $action = get_post( $id );
585 -
586 523 if ( $action ) {
587 524 $action = $this->prepare_action( $action );
588 525 $this->_set( $id );
589 526 }
@@ -590,43 +527,27 @@
590 527
591 528 return $action;
592 529 }
593 530
594 - /**
595 - * @param int|string $form_id
596 - *
597 - * @return array
598 - */
599 531 public function get_one( $form_id ) {
600 532 return $this->get_all( $form_id, 1 );
601 533 }
602 534
603 - /**
604 - * @param int|string $form_id
605 - * @param string $type
606 - * @param array $atts
607 - *
608 - * @return array
609 - */
610 535 public static function get_action_for_form( $form_id, $type = 'all', $atts = array() ) {
611 536 $action_controls = FrmFormActionsController::get_form_actions( $type );
612 -
613 - if ( ! $action_controls ) {
614 - // Don't continue if there are no available actions
537 + if ( empty( $action_controls ) ) {
538 + // don't continue if there are no available actions
615 539 return array();
616 540 }
617 541
618 542 if ( 'all' !== $type ) {
619 - if ( is_array( $action_controls ) ) {
620 - return array();
621 - }
622 -
623 543 return $action_controls->get_all( $form_id, $atts );
624 544 }
625 545
626 546 self::prepare_get_action( $atts );
627 547
628 - $limit = self::get_action_limit( $form_id, $atts['limit'] );
548 + $limit = self::get_action_limit( $form_id, $atts['limit'] );
549 +
629 550 $args = self::action_args( $form_id, $limit );
630 551 $args['post_status'] = $atts['post_status'];
631 552 $actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
632 553
@@ -634,11 +555,10 @@
634 555 return array();
635 556 }
636 557
637 558 $settings = array();
638 -
639 559 foreach ( $actions as $action ) {
640 - // Some plugins/themes are formatting the post_excerpt
560 + // some plugins/themes are formatting the post_excerpt
641 561 $action->post_excerpt = sanitize_title( $action->post_excerpt );
642 562
643 563 if ( ! isset( $action_controls[ $action->post_excerpt ] ) ) {
644 564 continue;
@@ -651,9 +571,13 @@
651 571 break;
652 572 }
653 573 }
654 574
655 - return 1 === $limit ? reset( $settings ) : $settings;
575 + if ( 1 === $limit ) {
576 + $settings = reset( $settings );
577 + }
578 +
579 + return $settings;
656 580 }
657 581
658 582 /**
659 583 * Get the limit for the number of actions for a single form. By default, this is 99, but
@@ -666,9 +590,9 @@
666 590 *
667 591 * @return int The filtered limit value.
668 592 */
669 593 public static function get_action_limit( $form_id, $limit = 99 ) {
670 - $type = 'all';
594 + $type = 'all';
671 595 return (int) apply_filters( 'frm_form_action_limit', (int) $limit, compact( 'type', 'form_id' ) );
672 596 }
673 597
674 598 /**
@@ -673,21 +597,20 @@
673 597
674 598 /**
675 599 * @since 3.04
676 600 *
677 - * @param array|string $args
678 - * @param string $default_status
601 + * @param array $args
602 + * @param string $default_status
679 603 *
680 604 * @return void
681 605 */
682 606 protected static function prepare_get_action( &$args, $default_status = 'publish' ) {
683 607 if ( is_numeric( $args ) ) {
684 - // For reverse compatibility. $limit was changed to $args
608 + // for reverse compatibility. $limit was changed to $args
685 609 $args = array(
686 610 'limit' => $args,
687 611 );
688 612 }
689 -
690 613 $defaults = array(
691 614 'limit' => 99,
692 615 'post_status' => $default_status,
693 616 );
@@ -694,12 +617,9 @@
694 617 $args = wp_parse_args( $args, $defaults );
695 618 }
696 619
697 620 /**
698 - * @param int $action_id
699 - * @param string $type
700 - *
701 - * @return bool|object
621 + * @param int $action_id
702 622 */
703 623 public static function get_single_action_type( $action_id, $type ) {
704 624 if ( ! $type ) {
705 625 return false;
@@ -713,24 +633,18 @@
713 633 return $action_control->get_single_action( $action_id );
714 634 }
715 635
716 636 /**
717 - * @param int $form_id
718 - * @param string $type
637 + * @param int $form_id
719 638 *
720 639 * @return bool
721 640 */
722 641 public static function form_has_action_type( $form_id, $type ) {
723 - $actions = self::get_action_for_form( $form_id, $type );
724 - return ! empty( $actions );
642 + $payment_actions = self::get_action_for_form( $form_id, $type );
643 +
644 + return ! empty( $payment_actions );
725 645 }
726 646
727 - /**
728 - * @param false|int|string $form_id
729 - * @param array $atts
730 - *
731 - * @return array
732 - */
733 647 public function get_all( $form_id = false, $atts = array() ) {
734 648 if ( is_array( $atts ) && ! isset( $atts['limit'] ) && $this->action_options['limit'] > 99 ) {
735 649 $atts['limit'] = $this->action_options['limit'];
736 650 }
@@ -757,30 +671,31 @@
757 671 unset( $query );
758 672
759 673 remove_filter( 'posts_where', 'FrmFormActionsController::limit_by_type' );
760 674
761 - if ( ! $actions ) {
675 + if ( empty( $actions ) ) {
762 676 return array();
763 677 }
764 678
765 679 $settings = array();
766 -
767 680 foreach ( $actions as $action ) {
768 681 if ( count( $settings ) >= $limit ) {
769 682 continue;
770 683 }
771 684
772 - $action = $this->prepare_action( $action );
685 + $action = $this->prepare_action( $action );
686 +
773 687 $settings[ $action->ID ] = $action;
774 688 }
775 689
776 - return 1 === $limit ? reset( $settings ) : $settings;
690 + if ( 1 === $limit ) {
691 + $settings = reset( $settings );
692 + }
693 +
694 + return $settings;
777 695 }
778 696
779 697 /**
780 - * @param int|string $form_id
781 - * @param int $limit
782 - *
783 698 * @return array
784 699 */
785 700 public static function action_args( $form_id = 0, $limit = 99 ) {
786 701 $args = array(
@@ -790,9 +705,9 @@
790 705 'orderby' => 'title',
791 706 'order' => 'ASC',
792 707 );
793 708
794 - if ( $form_id && $form_id !== 'all' ) {
709 + if ( $form_id && $form_id != 'all' ) {
795 710 $args['menu_order'] = $form_id;
796 711 }
797 712
798 713 return $args;
@@ -798,11 +713,9 @@
798 713 return $args;
799 714 }
800 715
801 716 /**
802 - * @param WP_Post $action
803 - *
804 - * @return WP_Post
717 + * @param array|WP_Post $action
805 718 */
806 719 public function prepare_action( $action ) {
807 720 $action->post_content = (array) FrmAppHelper::maybe_json_decode( $action->post_content );
808 721 $action->post_excerpt = sanitize_title( $action->post_excerpt );
@@ -808,20 +721,18 @@
808 721 $action->post_excerpt = sanitize_title( $action->post_excerpt );
809 722
810 723 $default_values = $this->get_global_defaults();
811 724
812 - // Fill default values
725 + // fill default values
813 726 $action->post_content += $default_values;
814 727
815 728 foreach ( $default_values as $k => $vals ) {
816 - if ( ! is_array( $vals ) || ! $vals ) {
817 - continue;
729 + if ( is_array( $vals ) && ! empty( $vals ) ) {
730 + if ( 'event' === $k && ! $this->action_options['force_event'] && ! empty( $action->post_content[ $k ] ) ) {
731 + continue;
732 + }
733 + $action->post_content[ $k ] = wp_parse_args( $action->post_content[ $k ], $vals );
818 734 }
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 735 }
825 736
826 737 if ( ! is_array( $action->post_content['event'] ) ) {
827 738 $action->post_content['event'] = explode( ',', $action->post_content['event'] );
@@ -830,11 +741,8 @@
830 741 return $action;
831 742 }
832 743
833 744 /**
834 - * @param false|int|string $form_id
835 - * @param string $type
836 - *
837 745 * @return void
838 746 */
839 747 public function destroy( $form_id = false, $type = 'default' ) {
840 748 global $wpdb;
@@ -841,14 +749,12 @@
841 749
842 750 $this->form_id = $form_id;
843 751
844 752 $query = array( 'post_type' => FrmFormActionsController::$action_post_type );
845 -
846 753 if ( $form_id ) {
847 754 $query['menu_order'] = $form_id;
848 755 }
849 -
850 - if ( 'all' !== $type ) {
756 + if ( 'all' != $type ) {
851 757 $query['post_excerpt'] = $this->id_base;
852 758 }
853 759
854 760 $post_ids = FrmDb::get_col( $wpdb->posts, $query, 'ID' );
@@ -869,11 +775,8 @@
869 775 public static function clear_cache() {
870 776 FrmDb::cache_delete_group( 'frm_actions' );
871 777 }
872 778
873 - /**
874 - * @return array
875 - */
876 779 public function get_settings() {
877 780 return self::get_action_for_form( $this->form_id, $this->id_base );
878 781 }
879 782
@@ -896,43 +799,35 @@
896 799
897 800 return $defaults;
898 801 }
899 802
900 - /**
901 - * @return array
902 - */
903 803 public function get_global_switch_fields() {
904 804 $switch = $this->get_switch_fields();
905 805 $switch['conditions'] = array( 'hide_field' );
906 806
907 - return apply_filters( 'frm_global_switch_fields', $switch );
807 + $switch = apply_filters( 'frm_global_switch_fields', $switch );
808 +
809 + return $switch;
908 810 }
909 811
910 812 /**
911 813 * Migrate settings from form->options into new action.
912 - *
913 - * @param object $form
914 - * @param string $update
915 - *
916 - * @return int|WP_Error
917 814 */
918 815 public function migrate_to_2( $form, $update = 'update' ) {
919 816 $action = $this->prepare_new( $form->id );
920 817 FrmAppHelper::unserialize_or_decode( $form->options );
921 818
922 - // Fill with existing options
819 + // fill with existing options
923 820 foreach ( $action->post_content as $name => $val ) {
924 - if ( ! isset( $form->options[ $name ] ) ) {
925 - continue;
821 + if ( isset( $form->options[ $name ] ) ) {
822 + $action->post_content[ $name ] = $form->options[ $name ];
823 + unset( $form->options[ $name ] );
926 824 }
927 -
928 - $action->post_content[ $name ] = $form->options[ $name ];
929 - unset( $form->options[ $name ] );
930 825 }
931 826
932 827 $action = $this->migrate_values( $action, $form );
933 828
934 - // Check if action already exists
829 + // check if action already exists
935 830 $post_id = get_posts(
936 831 array(
937 832 'name' => $action->post_name,
938 833 'post_type' => FrmFormActionsController::$action_post_type,
@@ -940,41 +835,127 @@
940 835 'numberposts' => 1,
941 836 )
942 837 );
943 838
944 - if ( ! $post_id ) {
945 - // Create action now
839 + if ( empty( $post_id ) ) {
840 + // create action now
946 841 $post_id = $this->save_settings( $action );
947 842 }
948 843
949 - if ( ! $post_id || 'update' !== $update ) {
950 - return $post_id;
844 + if ( $post_id && 'update' == $update ) {
845 + global $wpdb;
846 + $form->options = maybe_serialize( $form->options );
847 +
848 + // update form options
849 + $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) );
850 + FrmForm::clear_form_cache();
951 851 }
952 852
953 - global $wpdb;
954 - $form->options = maybe_serialize( $form->options );
853 + return $post_id;
854 + }
955 855
956 - // Update form options
957 - $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => $form->options ), array( 'id' => $form->id ) );
958 - FrmForm::clear_form_cache();
856 + public static function action_conditions_met( $action, $entry ) {
857 + if ( is_callable( 'FrmProFormActionsController::action_conditions_met' ) ) {
858 + return FrmProFormActionsController::action_conditions_met( $action, $entry );
859 + }
959 860
960 - return $post_id;
861 + // This is here for reverse compatibility.
862 + $notification = $action->post_content;
863 + $stop = false;
864 + $met = array();
865 +
866 + if ( empty( $notification['conditions'] ) ) {
867 + return $stop;
868 + }
869 +
870 + foreach ( $notification['conditions'] as $k => $condition ) {
871 + if ( ! is_numeric( $k ) ) {
872 + continue;
873 + }
874 +
875 + if ( $stop && 'any' == $notification['conditions']['any_all'] && 'stop' == $notification['conditions']['send_stop'] ) {
876 + continue;
877 + }
878 +
879 + self::prepare_logic_value( $condition['hide_opt'], $action, $entry );
880 +
881 + $observed_value = self::get_value_from_entry( $entry, $condition['hide_field'] );
882 +
883 + $stop = FrmFieldsHelper::value_meets_condition( $observed_value, $condition['hide_field_cond'], $condition['hide_opt'] );
884 +
885 + if ( $notification['conditions']['send_stop'] === 'send' ) {
886 + $stop = $stop ? false : true;
887 + }
888 +
889 + $met[ $stop ] = $stop;
890 + }//end foreach
891 +
892 + if ( $notification['conditions']['any_all'] === 'all' && ! empty( $met ) && isset( $met[0] ) && isset( $met[1] ) ) {
893 + $stop = ( $notification['conditions']['send_stop'] === 'send' );
894 + } elseif ( $notification['conditions']['any_all'] === 'any' && $notification['conditions']['send_stop'] === 'send' && isset( $met[0] ) ) {
895 + $stop = false;
896 + }
897 +
898 + return $stop;
961 899 }
962 900
963 901 /**
964 - * @param WP_Post $action
965 - * @param stdClass $entry
902 + * Prepare the logic value for comparison against the entered value
966 903 *
967 - * @return bool
904 + * @since 2.01.02
905 + *
906 + * @param array|string $logic_value
907 + *
908 + * @return void
968 909 */
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 );
910 + private static function prepare_logic_value( &$logic_value, $action, $entry ) {
911 + if ( is_array( $logic_value ) ) {
912 + $logic_value = reset( $logic_value );
972 913 }
973 - return false;
914 +
915 + if ( $logic_value === 'current_user' ) {
916 + $logic_value = get_current_user_id();
917 + }
918 +
919 + $logic_value = apply_filters( 'frm_content', $logic_value, $action->menu_order, $entry );
920 +
921 + /**
922 + * @since 4.04.05
923 + */
924 + $logic_value = apply_filters( 'frm_action_logic_value', $logic_value );
974 925 }
975 926
976 927 /**
928 + * Get the value from a specific field and entry
929 + *
930 + * @since 2.01.02
931 + *
932 + * @param object $entry
933 + * @param int $field_id
934 + *
935 + * @return array|bool|mixed|string
936 + */
937 + private static function get_value_from_entry( $entry, $field_id ) {
938 + $observed_value = '';
939 +
940 + if ( isset( $entry->metas[ $field_id ] ) ) {
941 + $observed_value = $entry->metas[ $field_id ];
942 + } elseif ( $entry->post_id && FrmAppHelper::pro_is_installed() ) {
943 + $field = FrmField::getOne( $field_id );
944 + $observed_value = FrmProEntryMetaHelper::get_post_or_meta_value(
945 + $entry,
946 + $field,
947 + array(
948 + 'links' => false,
949 + 'truncate' => false,
950 + )
951 + );
952 + }
953 +
954 + return $observed_value;
955 + }
956 +
957 + /**
977 958 * @param string $class
978 959 *
979 960 * @return array
980 961 */
@@ -979,18 +960,14 @@
979 960 * @return array
980 961 */
981 962 public static function default_action_opts( $class = '' ) {
982 963 return array(
983 - 'classes' => 'frmfont ' . $class,
984 - 'active' => false,
985 - 'limit' => 0,
986 - 'description' => '',
964 + 'classes' => 'frm_icon_font ' . $class,
965 + 'active' => false,
966 + 'limit' => 0,
987 967 );
988 968 }
989 969
990 - /**
991 - * @return array
992 - */
993 970 public static function trigger_labels() {
994 971 $triggers = array(
995 972 'draft' => __( 'Draft is saved', 'formidable' ),
996 973 'create' => __( 'Entry is created', 'formidable' ),
@@ -1002,39 +979,18 @@
1002 979 return apply_filters( 'frm_action_triggers', $triggers );
1003 980 }
1004 981
1005 982 /**
1006 - * @param string $action_key The unique key for this action instance.
1007 - *
1008 983 * @return void
1009 984 */
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
985 + public function render_conditional_logic_call_to_action() {
1017 986 ?>
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>
987 + <h3>
988 + <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 ); ?>">
989 + <?php esc_html_e( 'Use Conditional Logic', 'formidable' ); ?>
990 + </a>
991 + </h3>
1035 992 <?php
1036 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1037 993 }
1038 994
1039 995 /**
1040 996 * @return string
@@ -1048,9 +1004,8 @@
1048 1004 *
1049 1005 * @since 6.10
1050 1006 *
1051 1007 * @param int $form_id Form ID.
1052 - *
1053 1008 * @return object[]
1054 1009 */
1055 1010 protected function get_form_fields( $form_id ) {
1056 1011 // Get form fields, include embedded and repeater child fields.