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/controllers/FrmFormActionsController.php +9 -231 6.266.10 View file →
@@ -3,17 +3,9 @@
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 6 class FrmFormActionsController {
7 -
8 - /**
9 - * @var string
10 - */
11 7 public static $action_post_type = 'frm_form_actions';
12 -
13 - /**
14 - * @var array|null
15 - */
16 8 public static $registered_actions;
17 9
18 10 /**
19 11 * Variables saved in the post:
@@ -67,23 +59,16 @@
67 59 'constantcontact' => 'FrmDefConstContactAction',
68 60 'getresponse' => 'FrmDefGetResponseAction',
69 61 'hubspot' => 'FrmDefHubspotAction',
70 62 'zapier' => 'FrmDefZapierAction',
71 - 'n8n' => 'FrmDefN8NAction',
72 63 'twilio' => 'FrmDefTwilioAction',
73 64 'highrise' => 'FrmDefHighriseAction',
74 65 'mailpoet' => 'FrmDefMailpoetAction',
75 66 'aweber' => 'FrmDefAweberAction',
76 - 'convertkit' => 'FrmDefConvertKitAction',
77 67 'googlespreadsheet' => 'FrmDefGoogleSpreadsheetAction',
78 68 );
79 69
80 - if ( ! FrmAppHelper::show_new_feature( 'n8n' ) ) {
81 - unset( $action_classes['n8n'] );
82 - }
83 -
84 70 $action_classes = apply_filters( 'frm_registered_form_actions', $action_classes );
85 - $action_classes = self::maybe_unset_highrise( $action_classes );
86 71
87 72 include_once FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php';
88 73 include_once FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php';
89 74
@@ -92,24 +77,8 @@
92 77 }
93 78 }
94 79
95 80 /**
96 - * Remove the Highrise action if it is not registered.
97 - *
98 - * @since 6.23
99 - *
100 - * @param array $action_classes
101 - *
102 - * @return array
103 - */
104 - private static function maybe_unset_highrise( $action_classes ) {
105 - if ( 'FrmDefHighriseAction' === ( $action_classes['highrise'] ?? '' ) ) {
106 - unset( $action_classes['highrise'] );
107 - }
108 - return $action_classes;
109 - }
110 -
111 - /**
112 81 * @since 4.0
113 82 *
114 83 * @param array $values
115 84 */
@@ -128,17 +97,11 @@
128 97 /**
129 98 * Add unknown actions to a group.
130 99 *
131 100 * @since 4.0
132 - *
133 - * @param array $action_controls
134 - * @param array $groups
135 - *
136 - * @return void
137 101 */
138 102 private static function maybe_add_action_to_group( $action_controls, &$groups ) {
139 103 $grouped = array();
140 -
141 104 foreach ( $groups as $group ) {
142 105 if ( isset( $group['actions'] ) ) {
143 106 $grouped = array_merge( $grouped, $group['actions'] );
144 107 }
@@ -149,9 +112,8 @@
149 112 continue;
150 113 }
151 114
152 115 $this_group = $action->action_options['group'];
153 -
154 116 if ( ! isset( $groups[ $this_group ] ) ) {
155 117 $this_group = 'misc';
156 118 }
157 119
@@ -200,15 +162,18 @@
200 162 'constantcontact',
201 163 'getresponse',
202 164 'aweber',
203 165 'mailpoet',
204 - 'convertkit',
205 166 ),
206 167 ),
207 168 'crm' => array(
208 169 'name' => __( 'CRM', 'formidable' ),
209 170 'icon' => 'frm_icon_font frm_address_card_icon',
210 - 'actions' => self::get_crm_actions(),
171 + 'actions' => array(
172 + 'salesforce',
173 + 'hubspot',
174 + 'highrise',
175 + ),
211 176 ),
212 177 );
213 178
214 179 return apply_filters( 'frm_action_groups', $groups );
@@ -214,41 +179,16 @@
214 179 return apply_filters( 'frm_action_groups', $groups );
215 180 }
216 181
217 182 /**
218 - * Get the actions to include in the CRM section.
219 - *
220 - * @since 6.23
221 - *
222 - * @return array
223 - */
224 - private static function get_crm_actions() {
225 - $crm_actions = array(
226 - 'salesforce',
227 - 'hubspot',
228 - );
229 -
230 - // Only include Highrise when the add-on is active.
231 - // This is because Highrise is deprecated. We don't want to show it in Lite.
232 - if ( class_exists( 'FrmHrsSettings' ) ) {
233 - $crm_actions[] = 'highrise';
234 - }
235 -
236 - return $crm_actions;
237 - }
238 -
239 - /**
240 183 * Get the number of currently active form actions.
241 184 *
242 185 * @since 4.0
243 186 *
244 - * @param array $action_controls
245 - *
246 187 * @return array
247 188 */
248 189 private static function active_actions( $action_controls ) {
249 190 $allowed = array();
250 -
251 191 foreach ( $action_controls as $action_control ) {
252 192 if ( isset( $action_control->action_options['active'] ) && $action_control->action_options['active'] ) {
253 193 $allowed[] = $action_control->id_base;
254 194 }
@@ -259,9 +199,8 @@
259 199 /**
260 200 * For each add-on, add an li, class, and javascript function. If active, add an additional class.
261 201 *
262 202 * @since 4.0
263 - *
264 203 * @param object $action_control
265 204 * @param array $allowed
266 205 */
267 206 public static function show_action_icon_link( $action_control, $allowed ) {
@@ -281,9 +220,8 @@
281 220 if ( isset( $action_control->action_options['active'] ) && $action_control->action_options['active'] ) {
282 221 $classes .= ' frm_active_action';
283 222 } else {
284 223 $classes .= ' frm_inactive_action';
285 -
286 224 if ( $default_position !== false && ( $allowed_count + $default_position ) < 6 ) {
287 225 $group_class .= ' frm-default-show';
288 226 }
289 227
@@ -290,9 +228,8 @@
290 228 $data['data-upgrade'] = $upgrade_label;
291 229 $data['data-medium'] = 'settings-' . $action_control->id_base;
292 230
293 231 $upgrading = FrmAddonsController::install_link( $action_control->action_options['plugin'] );
294 -
295 232 if ( isset( $upgrading['url'] ) ) {
296 233 $data['data-oneclick'] = json_encode( $upgrading );
297 234 }
298 235
@@ -300,9 +237,8 @@
300 237 $data['data-message'] = $action_control->action_options['message'];
301 238 }
302 239
303 240 $requires = FrmFormsHelper::get_plan_required( $upgrading );
304 -
305 241 if ( $requires && 'free' !== $requires ) {
306 242 $data['data-requires'] = $requires;
307 243 }
308 244 }//end if
@@ -308,9 +244,8 @@
308 244 }//end if
309 245
310 246 // HTML to include on the icon.
311 247 $icon_atts = array();
312 -
313 248 if ( $action_control->action_options['color'] !== 'var(--primary-700)' ) {
314 249 $icon_atts = array(
315 250 'style' => '--primary-700:' . $action_control->action_options['color'],
316 251 );
@@ -320,14 +255,11 @@
320 255 }
321 256
322 257 /**
323 258 * @param string $action
324 - *
325 - * @return array|FrmFormAction A single form action is returned when a specific $action value is requested.
326 259 */
327 260 public static function get_form_actions( $action = 'all' ) {
328 261 $temp_actions = self::$registered_actions;
329 -
330 262 if ( empty( $temp_actions ) ) {
331 263 self::actions_init();
332 264 $temp_actions = self::$registered_actions->actions;
333 265 } else {
@@ -348,13 +280,8 @@
348 280 }
349 281
350 282 /**
351 283 * @since 2.0
352 - *
353 - * @param object $form
354 - * @param array $values
355 - *
356 - * @return void
357 284 */
358 285 public static function list_actions( $form, $values ) {
359 286 if ( empty( $form ) ) {
360 287 return;
@@ -371,11 +298,8 @@
371 298 'post_status' => 'all',
372 299 );
373 300 $form_actions = FrmFormAction::get_action_for_form( $form->id, 'all', $filters );
374 301
375 - /**
376 - * @var array
377 - */
378 302 $action_controls = self::get_form_actions();
379 303
380 304 $action_map = array();
381 305
@@ -382,10 +306,8 @@
382 306 foreach ( $action_controls as $key => $control ) {
383 307 $action_map[ $control->id_base ] = $key;
384 308 }
385 309
386 - self::maybe_show_limit_warning( $form->id, $form_actions );
387 -
388 310 foreach ( $form_actions as $action ) {
389 311 if ( ! isset( $action_map[ $action->post_excerpt ] ) ) {
390 312 // don't try and show settings if action no longer exists
391 313 continue;
@@ -394,54 +316,8 @@
394 316 self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values );
395 317 }
396 318 }
397 319
398 - /**
399 - * Show a warning before the form actions list if there are 99 actions, and the limit is set to 99.
400 - * If it is filtered, the warning is still shown when applicable, just using the new limit.
401 - *
402 - * @since 6.17
403 - *
404 - * @param int|string $form_id
405 - * @param array $form_actions
406 - *
407 - * @return void
408 - */
409 - private static function maybe_show_limit_warning( $form_id, $form_actions ) {
410 - $count = count( $form_actions );
411 -
412 - if ( $count < 99 ) {
413 - return;
414 - }
415 -
416 - $limit = FrmFormAction::get_action_limit( $form_id );
417 -
418 - if ( $limit < 99 || $count < $limit ) {
419 - return;
420 - }
421 -
422 - $documentation_url = 'https://formidableforms.com/knowledgebase/frm_form_action_limit/#kb-increase-limit-of-form-actions';
423 -
424 - echo '<div class="frm_warning_style">';
425 - FrmAppHelper::icon_by_class( 'frm_icon_font frm_alert_icon' );
426 - echo '&nbsp;';
427 - printf(
428 - // translators: %s: URL to documentation
429 - esc_html__( 'You have reached your form action limit. To increase this limit, you will require additional code. Visit our documentation at %s.', 'formidable' ),
430 - '<a href="' . esc_url( $documentation_url ) . '" target="_blank">' . esc_html( $documentation_url ) . '</a>'
431 - );
432 - echo '</div>';
433 - }
434 -
435 - /**
436 - * @param WP_Post $form_action
437 - * @param object $form
438 - * @param int $action_key Action ID.
439 - * @param FrmFormAction $action_control
440 - * @param array $values
441 - *
442 - * @return void
443 - */
444 320 public static function action_control( $form_action, $form, $action_key, $action_control, $values ) {
445 321 $action_control->_set( $action_key );
446 322
447 323 $use_logging = self::should_show_log_message( $form_action->post_excerpt );
@@ -457,11 +333,8 @@
457 333
458 334 $action_key = FrmAppHelper::get_param( 'list_id', '', 'post', 'absint' );
459 335 $action_type = FrmAppHelper::get_param( 'type', '', 'post', 'sanitize_text_field' );
460 336
461 - /**
462 - * @var FrmFormAction
463 - */
464 337 $action_control = self::get_form_actions( $action_type );
465 338 $action_control->_set( $action_key );
466 339
467 340 $form_id = FrmAppHelper::get_param( 'form_id', '', 'post', 'absint' );
@@ -483,9 +356,8 @@
483 356 $action_key = FrmAppHelper::get_param( 'action_id', '', 'post', 'absint' );
484 357 $action_type = FrmAppHelper::get_param( 'action_type', '', 'post', 'sanitize_text_field' );
485 358
486 359 $action_control = self::get_form_actions( $action_type );
487 -
488 360 if ( empty( $action_control ) ) {
489 361 wp_die();
490 362 }
491 363
@@ -501,11 +373,8 @@
501 373 }
502 374
503 375 /**
504 376 * @since 3.06.04
505 - *
506 - * @param string $action_type
507 - *
508 377 * @return bool
509 378 */
510 379 private static function should_show_log_message( $action_type ) {
511 380 $logging = array( 'api', 'salesforce', 'constantcontact', 'activecampaign' );
@@ -511,14 +380,8 @@
511 380 $logging = array( 'api', 'salesforce', 'constantcontact', 'activecampaign' );
512 381 return in_array( $action_type, $logging, true ) && ! function_exists( 'frm_log_autoloader' );
513 382 }
514 383
515 - /**
516 - * @param int|string $form_id
517 - * @param array $values
518 - *
519 - * @return object
520 - */
521 384 private static function fields_to_values( $form_id, array &$values ) {
522 385 $form = FrmForm::getOne( $form_id );
523 386
524 387 $values = array(
@@ -526,14 +389,12 @@
526 389 'id' => $form->id,
527 390 );
528 391
529 392 $fields = FrmField::get_all_for_form( $form->id );
530 -
531 393 foreach ( $fields as $k => $f ) {
532 394 $f = (array) $f;
533 395 $opts = (array) $f['field_options'];
534 396 $f = array_merge( $opts, $f );
535 -
536 397 if ( ! isset( $f['post_field'] ) ) {
537 398 $f['post_field'] = '';
538 399 }
539 400 $values['fields'][] = $f;
@@ -544,15 +405,13 @@
544 405 }
545 406
546 407 /**
547 408 * @param int $form_id
548 - *
549 409 * @return void
550 410 */
551 411 public static function update_settings( $form_id ) {
552 412 FrmAppHelper::permission_check( 'frm_edit_forms' );
553 413 $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
554 -
555 414 if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
556 415 $frm_settings = FrmAppHelper::get_settings();
557 416 $error_args = array(
558 417 'title' => __( 'Verification failed', 'formidable' ),
@@ -585,9 +444,8 @@
585 444 $new_actions = array();
586 445
587 446 foreach ( $registered_actions as $registered_action ) {
588 447 $action_ids = $registered_action->update_callback( $form_id );
589 -
590 448 if ( ! empty( $action_ids ) ) {
591 449 $new_actions[] = $action_ids;
592 450 }
593 451 }
@@ -595,9 +453,8 @@
595 453 // Only use array_merge if there are new actions.
596 454 if ( ! empty( $new_actions ) ) {
597 455 $new_actions = call_user_func_array( 'array_merge', $new_actions );
598 456 }
599 -
600 457 $old_actions = array_diff( $old_actions, $new_actions );
601 458
602 459 self::delete_missing_actions( $old_actions );
603 460
@@ -603,13 +460,8 @@
603 460
604 461 FrmOnSubmitHelper::save_on_submit_settings( $form_id );
605 462 }
606 463
607 - /**
608 - * @param array $old_actions
609 - *
610 - * @return void
611 - */
612 464 public static function delete_missing_actions( $old_actions ) {
613 465 if ( ! empty( $old_actions ) ) {
614 466 foreach ( $old_actions as $old_id ) {
615 467 wp_delete_post( $old_id );
@@ -617,40 +469,20 @@
617 469 FrmDb::cache_delete_group( 'frm_actions' );
618 470 }
619 471 }
620 472
621 - /**
622 - * @param int|string $entry_id
623 - * @param int|string $form_id
624 - * @param array $args
625 - *
626 - * @return void
627 - */
628 473 public static function trigger_create_actions( $entry_id, $form_id, $args = array() ) {
629 474 $filter_args = $args;
630 475 $filter_args['entry_id'] = $entry_id;
631 476 $filter_args['form_id'] = $form_id;
632 477
633 - /**
634 - * @since 2.0.23
635 - * @since 6.11.2 $filter_args is now passed instead of $args. It includes additional ID data.
636 - *
637 - * @param string $event 'create' by default. Pro may filter this value to 'draft' instead.
638 - * @param array $filter_args
639 - */
640 - $event = apply_filters( 'frm_trigger_create_action', 'create', $filter_args );
478 + $event = apply_filters( 'frm_trigger_create_action', 'create', $args );
641 479
642 480 self::trigger_actions( $event, $form_id, $entry_id, 'all', $args );
643 481 }
644 482
645 483 /**
646 - * @param string $event
647 - * @param int|object|string $form
648 - * @param int|string $entry
649 - * @param string $type
650 - * @param array $args
651 - *
652 - * @return void
484 + * @param string $event
653 485 */
654 486 public static function trigger_actions( $event, $form, $entry, $type = 'all', $args = array() ) {
655 487 $action_status = array(
656 488 'post_status' => 'publish',
@@ -662,15 +494,10 @@
662 494 }
663 495
664 496 FrmForm::maybe_get_form( $form );
665 497
666 - if ( ! is_object( $form ) ) {
667 - return;
668 - }
669 -
670 498 $link_settings = self::get_form_actions( $type );
671 -
672 - if ( 'all' !== $type ) {
499 + if ( 'all' != $type ) {
673 500 $link_settings = array( $type => $link_settings );
674 501 }
675 502
676 503 $stored_actions = array();
@@ -685,9 +512,8 @@
685 512 foreach ( $form_actions as $action ) {
686 513
687 514 $skip_this_action = ! in_array( $this_event, $action->post_content['event'], true ) || FrmOnSubmitAction::$slug === $action->post_excerpt;
688 515 $skip_this_action = apply_filters( 'frm_skip_form_action', $skip_this_action, compact( 'action', 'entry', 'form', 'event' ) );
689 -
690 516 if ( $skip_this_action ) {
691 517 continue;
692 518 }
693 519
@@ -698,14 +524,13 @@
698 524 if ( empty( $entry ) || ( FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $entry->is_draft && 'draft' !== $event ) ) {
699 525 continue;
700 526 }
701 527
702 - $child_entry = ( is_numeric( $form->parent_form_id ) && $form->parent_form_id ) || ( $entry && ( $entry->form_id != $form->id || $entry->parent_item_id ) ) || ! empty( $args['is_child'] );
528 + $child_entry = ( ( is_object( $form ) && is_numeric( $form->parent_form_id ) && $form->parent_form_id ) || ( $entry && ( $entry->form_id != $form->id || $entry->parent_item_id ) ) || ( isset( $args['is_child'] ) && $args['is_child'] ) );
703 529
704 530 if ( $child_entry ) {
705 531 // maybe trigger actions for sub forms
706 532 $trigger_children = apply_filters( 'frm_use_embedded_form_actions', false, compact( 'form', 'entry' ) );
707 -
708 533 if ( ! $trigger_children ) {
709 534 continue;
710 535 }
711 536 }
@@ -711,9 +536,8 @@
711 536 }
712 537
713 538 // Check conditional logic.
714 539 $stop = FrmFormAction::action_conditions_met( $action, $entry );
715 -
716 540 if ( $stop ) {
717 541 continue;
718 542 }
719 543
@@ -756,15 +580,8 @@
756 580 }//end foreach
757 581 }//end if
758 582 }
759 583
760 - /**
761 - * @param int|string $form_id
762 - * @param array $values
763 - * @param array $args
764 - *
765 - * @return void
766 - */
767 584 public static function duplicate_form_actions( $form_id, $values, $args = array() ) {
768 585 if ( empty( $args['old_id'] ) ) {
769 586 // Continue if we know which actions to copy.
770 587 return;
@@ -769,11 +586,8 @@
769 586 // Continue if we know which actions to copy.
770 587 return;
771 588 }
772 589
773 - /**
774 - * @var array
775 - */
776 590 $action_controls = self::get_form_actions();
777 591
778 592 foreach ( $action_controls as $action_control ) {
779 593 $action_control->duplicate_form_actions( $form_id, $args['old_id'] );
@@ -780,13 +594,8 @@
780 594 unset( $action_control );
781 595 }
782 596 }
783 597
784 - /**
785 - * @param string $where
786 - *
787 - * @return string
788 - */
789 598 public static function limit_by_type( $where ) {
790 599 global $frm_vars, $wpdb;
791 600
792 601 if ( ! isset( $frm_vars['action_type'] ) ) {
@@ -796,32 +605,11 @@
796 605 $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] );
797 606
798 607 return $where;
799 608 }
800 -
801 - /**
802 - * Prevent WPML from filtering form actions based on the active language.
803 - *
804 - * @since 6.20
805 - *
806 - * @param bool|null $null
807 - * @param string $post_type
808 - *
809 - * @return bool|null
810 - */
811 - public static function prevent_wpml_translations( $null, $post_type ) {
812 - if ( self::$action_post_type === $post_type ) {
813 - return false;
814 - }
815 - return $null;
816 - }
817 609 }
818 610
819 611 class Frm_Form_Action_Factory {
820 -
821 - /**
822 - * @var array
823 - */
824 612 public $actions = array();
825 613
826 614 public function __construct() {
827 615 add_action( 'frm_form_actions_init', array( $this, '_register_actions' ), 100 );
@@ -826,22 +614,12 @@
826 614 public function __construct() {
827 615 add_action( 'frm_form_actions_init', array( $this, '_register_actions' ), 100 );
828 616 }
829 617
830 - /**
831 - * @param string $action_class
832 - *
833 - * @return void
834 - */
835 618 public function register( $action_class ) {
836 619 $this->actions[ $action_class ] = new $action_class();
837 620 }
838 621
839 - /**
840 - * @param string $action_class
841 - *
842 - * @return void
843 - */
844 622 public function unregister( $action_class ) {
845 623 if ( isset( $this->actions[ $action_class ] ) ) {
846 624 unset( $this->actions[ $action_class ] );
847 625 }