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