PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.3
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.3
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 +51 -201 6.255.3 View file →
@@ -4,12 +4,8 @@
4 4 }
5 5
6 6 class FrmFormActionsController {
7 7 public static $action_post_type = 'frm_form_actions';
8 -
9 - /**
10 - * @var array|null
11 - */
12 8 public static $registered_actions;
13 9
14 10 /**
15 11 * Variables saved in the post:
@@ -42,42 +38,35 @@
42 38 self::register_actions();
43 39 do_action( 'frm_form_actions_init' );
44 40 }
45 41
46 - /**
47 - * @return void
48 - */
49 42 public static function register_actions() {
50 43 $action_classes = array(
51 - 'on_submit' => 'FrmOnSubmitAction',
52 - 'email' => 'FrmEmailAction',
53 - 'wppost' => 'FrmDefPostAction',
54 - 'register' => 'FrmDefRegAction',
55 - 'paypal' => 'FrmDefPayPalAction',
56 - 'payment' => 'FrmTransLiteAction',
57 - 'quiz' => 'FrmDefQuizAction',
58 - 'quiz_outcome' => 'FrmDefQuizOutcomeAction',
59 - 'mailchimp' => 'FrmDefMlcmpAction',
60 - 'api' => 'FrmDefApiAction',
61 - 'salesforce' => 'FrmDefSalesforceAction',
62 - 'activecampaign' => 'FrmDefActiveCampaignAction',
63 - 'constantcontact' => 'FrmDefConstContactAction',
64 - 'getresponse' => 'FrmDefGetResponseAction',
65 - 'hubspot' => 'FrmDefHubspotAction',
66 - 'zapier' => 'FrmDefZapierAction',
67 - 'twilio' => 'FrmDefTwilioAction',
68 - 'highrise' => 'FrmDefHighriseAction',
69 - 'mailpoet' => 'FrmDefMailpoetAction',
70 - 'aweber' => 'FrmDefAweberAction',
71 - 'convertkit' => 'FrmDefConvertKitAction',
72 - 'googlespreadsheet' => 'FrmDefGoogleSpreadsheetAction',
44 + 'email' => 'FrmEmailAction',
45 + 'wppost' => 'FrmDefPostAction',
46 + 'register' => 'FrmDefRegAction',
47 + 'paypal' => 'FrmDefPayPalAction',
48 + 'payment' => 'FrmDefHrsAction',
49 + 'quiz' => 'FrmDefQuizAction',
50 + 'mailchimp' => 'FrmDefMlcmpAction',
51 + 'api' => 'FrmDefApiAction',
52 +
53 + 'salesforce' => 'FrmDefSalesforceAction',
54 + 'activecampaign' => 'FrmDefActiveCampaignAction',
55 + 'constantcontact' => 'FrmDefConstContactAction',
56 + 'getresponse' => 'FrmDefGetResponseAction',
57 + 'hubspot' => 'FrmDefHubspotAction',
58 + 'zapier' => 'FrmDefZapierAction',
59 + 'twilio' => 'FrmDefTwilioAction',
60 + 'highrise' => 'FrmDefHighriseAction',
61 + 'mailpoet' => 'FrmDefMailpoetAction',
62 + 'aweber' => 'FrmDefAweberAction',
73 63 );
74 64
75 65 $action_classes = apply_filters( 'frm_registered_form_actions', $action_classes );
76 - $action_classes = self::maybe_unset_highrise( $action_classes );
77 66
78 - include_once FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php';
79 - include_once FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php';
67 + include_once( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php' );
68 + include_once( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php' );
80 69
81 70 foreach ( $action_classes as $action_class ) {
82 71 self::$registered_actions->register( $action_class );
83 72 }
@@ -83,23 +72,8 @@
83 72 }
84 73 }
85 74
86 75 /**
87 - * Remove the Highrise action if it is not registered.
88 - *
89 - * @since 6.23
90 - *
91 - * @param array $action_classes
92 - * @return array
93 - */
94 - private static function maybe_unset_highrise( $action_classes ) {
95 - if ( 'FrmDefHighriseAction' === ( $action_classes['highrise'] ?? '' ) ) {
96 - unset( $action_classes['highrise'] );
97 - }
98 - return $action_classes;
99 - }
100 -
101 - /**
102 76 * @since 4.0
103 77 *
104 78 * @param array $values
105 79 */
@@ -111,9 +85,9 @@
111 85 self::maybe_add_action_to_group( $action_controls, $groups );
112 86
113 87 $allowed = self::active_actions( $action_controls );
114 88
115 - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/settings.php';
89 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/settings.php' );
116 90 }
117 91
118 92 /**
119 93 * Add unknown actions to a group.
@@ -153,9 +127,9 @@
153 127 * @return array
154 128 */
155 129 public static function form_action_groups() {
156 130 $groups = array(
157 - 'misc' => array(
131 + 'misc' => array(
158 132 'name' => '',
159 133 'icon' => 'frm_icon_font frm_shuffle_icon',
160 134 'actions' => array(
161 135 'email',
@@ -161,9 +135,8 @@
161 135 'email',
162 136 'wppost',
163 137 'register',
164 138 'quiz',
165 - 'quiz_outcome',
166 139 'twilio',
167 140 ),
168 141 ),
169 142 'payment' => array(
@@ -183,15 +156,18 @@
183 156 'constantcontact',
184 157 'getresponse',
185 158 'aweber',
186 159 'mailpoet',
187 - 'convertkit',
188 160 ),
189 161 ),
190 162 'crm' => array(
191 163 'name' => __( 'CRM', 'formidable' ),
192 164 'icon' => 'frm_icon_font frm_address_card_icon',
193 - 'actions' => self::get_crm_actions(),
165 + 'actions' => array(
166 + 'salesforce',
167 + 'hubspot',
168 + 'highrise',
169 + ),
194 170 ),
195 171 );
196 172
197 173 return apply_filters( 'frm_action_groups', $groups );
@@ -197,30 +173,8 @@
197 173 return apply_filters( 'frm_action_groups', $groups );
198 174 }
199 175
200 176 /**
201 - * Get the actions to include in the CRM section.
202 - *
203 - * @since 6.23
204 - *
205 - * @return array
206 - */
207 - private static function get_crm_actions() {
208 - $crm_actions = array(
209 - 'salesforce',
210 - 'hubspot',
211 - );
212 -
213 - // Only include Highrise when the add-on is active.
214 - // This is because Highrise is deprecated. We don't want to show it in Lite.
215 - if ( class_exists( 'FrmHrsSettings' ) ) {
216 - $crm_actions[] = 'highrise';
217 - }
218 -
219 - return $crm_actions;
220 - }
221 -
222 - /**
223 177 * Get the number of currently active form actions.
224 178 *
225 179 * @since 4.0
226 180 *
@@ -280,15 +234,15 @@
280 234 $requires = FrmFormsHelper::get_plan_required( $upgrading );
281 235 if ( $requires && 'free' !== $requires ) {
282 236 $data['data-requires'] = $requires;
283 237 }
284 - }//end if
238 + }
285 239
286 240 // HTML to include on the icon.
287 241 $icon_atts = array();
288 - if ( $action_control->action_options['color'] !== 'var(--primary-700)' ) {
242 + if ( $action_control->action_options['color'] !== 'var(--primary-hover)' ) {
289 243 $icon_atts = array(
290 - 'style' => '--primary-700:' . $action_control->action_options['color'],
244 + 'style' => '--primary-hover:' . $action_control->action_options['color'],
291 245 );
292 246 }
293 247
294 248 include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_icon.php';
@@ -293,12 +247,8 @@
293 247
294 248 include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_icon.php';
295 249 }
296 250
297 - /**
298 - * @param string $action
299 - * @return array|FrmFormAction A single form action is returned when a specific $action value is requested.
300 - */
301 251 public static function get_form_actions( $action = 'all' ) {
302 252 $temp_actions = self::$registered_actions;
303 253 if ( empty( $temp_actions ) ) {
304 254 self::actions_init();
@@ -309,9 +259,9 @@
309 259
310 260 $actions = array();
311 261
312 262 foreach ( $temp_actions as $a ) {
313 - if ( 'all' !== $action && $a->id_base == $action ) {
263 + if ( 'all' != $action && $a->id_base == $action ) {
314 264 return $a;
315 265 }
316 266
317 267 $actions[ $a->id_base ] = $a;
@@ -339,11 +289,8 @@
339 289 'post_status' => 'all',
340 290 );
341 291 $form_actions = FrmFormAction::get_action_for_form( $form->id, 'all', $filters );
342 292
343 - /**
344 - * @var array
345 - */
346 293 $action_controls = self::get_form_actions();
347 294
348 295 $action_map = array();
349 296
@@ -350,10 +297,8 @@
350 297 foreach ( $action_controls as $key => $control ) {
351 298 $action_map[ $control->id_base ] = $key;
352 299 }
353 300
354 - self::maybe_show_limit_warning( $form->id, $form_actions );
355 -
356 301 foreach ( $form_actions as $action ) {
357 302 if ( ! isset( $action_map[ $action->post_excerpt ] ) ) {
358 303 // don't try and show settings if action no longer exists
359 304 continue;
@@ -362,48 +307,14 @@
362 307 self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values );
363 308 }
364 309 }
365 310
366 - /**
367 - * Show a warning before the form actions list if there are 99 actions, and the limit is set to 99.
368 - * If it is filtered, the warning is still shown when applicable, just using the new limit.
369 - *
370 - * @since 6.17
371 - *
372 - * @param int|string $form_id
373 - * @param array $form_actions
374 - * @return void
375 - */
376 - private static function maybe_show_limit_warning( $form_id, $form_actions ) {
377 - $count = count( $form_actions );
378 - if ( $count < 99 ) {
379 - return;
380 - }
381 -
382 - $limit = FrmFormAction::get_action_limit( $form_id );
383 - if ( $limit < 99 || $count < $limit ) {
384 - return;
385 - }
386 -
387 - $documentation_url = 'https://formidableforms.com/knowledgebase/frm_form_action_limit/#kb-increase-limit-of-form-actions';
388 -
389 - echo '<div class="frm_warning_style">';
390 - FrmAppHelper::icon_by_class( 'frm_icon_font frm_alert_icon' );
391 - echo '&nbsp;';
392 - printf(
393 - // translators: %s: URL to documentation
394 - esc_html__( 'You have reached your form action limit. To increase this limit, you will require additional code. Visit our documentation at %s.', 'formidable' ),
395 - '<a href="' . esc_url( $documentation_url ) . '" target="_blank">' . esc_html( $documentation_url ) . '</a>'
396 - );
397 - echo '</div>';
398 - }
399 -
400 311 public static function action_control( $form_action, $form, $action_key, $action_control, $values ) {
401 312 $action_control->_set( $action_key );
402 313
403 314 $use_logging = self::should_show_log_message( $form_action->post_excerpt );
404 315
405 - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php';
316 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' );
406 317 }
407 318
408 319 public static function add_form_action() {
409 320 FrmAppHelper::permission_check( 'frm_edit_forms' );
@@ -413,11 +324,8 @@
413 324
414 325 $action_key = FrmAppHelper::get_param( 'list_id', '', 'post', 'absint' );
415 326 $action_type = FrmAppHelper::get_param( 'type', '', 'post', 'sanitize_text_field' );
416 327
417 - /**
418 - * @var FrmFormAction
419 - */
420 328 $action_control = self::get_form_actions( $action_type );
421 329 $action_control->_set( $action_key );
422 330
423 331 $form_id = FrmAppHelper::get_param( 'form_id', '', 'post', 'absint' );
@@ -427,9 +335,9 @@
427 335
428 336 $values = array();
429 337 $form = self::fields_to_values( $form_id, $values );
430 338
431 - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php';
339 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' );
432 340 wp_die();
433 341 }
434 342
435 343 public static function fill_action() {
@@ -450,9 +358,9 @@
450 358 $form = self::fields_to_values( $form_action->menu_order, $values );
451 359
452 360 $use_logging = self::should_show_log_message( $action_type );
453 361
454 - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_inside.php';
362 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_inside.php' );
455 363 wp_die();
456 364 }
457 365
458 366 /**
@@ -460,9 +368,9 @@
460 368 * @return bool
461 369 */
462 370 private static function should_show_log_message( $action_type ) {
463 371 $logging = array( 'api', 'salesforce', 'constantcontact', 'activecampaign' );
464 - return in_array( $action_type, $logging, true ) && ! function_exists( 'frm_log_autoloader' );
372 + return in_array( $action_type, $logging ) && ! function_exists( 'frm_log_autoloader' );
465 373 }
466 374
467 375 private static function fields_to_values( $form_id, array &$values ) {
468 376 $form = FrmForm::getOne( $form_id );
@@ -495,22 +403,9 @@
495 403 FrmAppHelper::permission_check( 'frm_edit_forms' );
496 404 $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
497 405 if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
498 406 $frm_settings = FrmAppHelper::get_settings();
499 - $error_args = array(
500 - 'title' => __( 'Verification failed', 'formidable' ),
501 - 'body' => $frm_settings->admin_permission,
502 - 'cancel_url' => add_query_arg(
503 - array(
504 - 'page' => 'formidable',
505 - 'frm_action' => 'settings',
506 - 'id' => $form_id,
507 - ),
508 - admin_url( 'admin.php?' )
509 - ),
510 - );
511 - FrmAppController::show_error_modal( $error_args );
512 - return;
407 + wp_die( esc_html( $frm_settings->admin_permission ) );
513 408 }
514 409
515 410 global $wpdb;
516 411
@@ -539,10 +434,8 @@
539 434 }
540 435 $old_actions = array_diff( $old_actions, $new_actions );
541 436
542 437 self::delete_missing_actions( $old_actions );
543 -
544 - FrmOnSubmitHelper::save_on_submit_settings( $form_id );
545 438 }
546 439
547 440 public static function delete_missing_actions( $old_actions ) {
548 441 if ( ! empty( $old_actions ) ) {
@@ -557,16 +450,9 @@
557 450 $filter_args = $args;
558 451 $filter_args['entry_id'] = $entry_id;
559 452 $filter_args['form_id'] = $form_id;
560 453
561 - /**
562 - * @since 2.0.23
563 - * @since 6.11.2 $filter_args is now passed instead of $args. It includes additional ID data.
564 - *
565 - * @param string $event 'create' by default. Pro may filter this value to 'draft' instead.
566 - * @param array $filter_args
567 - */
568 - $event = apply_filters( 'frm_trigger_create_action', 'create', $filter_args );
454 + $event = apply_filters( 'frm_trigger_create_action', 'create', $args );
569 455
570 456 self::trigger_actions( $event, $form_id, $entry_id, 'all', $args );
571 457 }
572 458
@@ -576,9 +462,9 @@
576 462 public static function trigger_actions( $event, $form, $entry, $type = 'all', $args = array() ) {
577 463 $action_status = array(
578 464 'post_status' => 'publish',
579 465 );
580 - $form_actions = FrmFormAction::get_action_for_form( ( is_object( $form ) ? $form->id : $form ), $type, $action_status );
466 + $form_actions = FrmFormAction::get_action_for_form( ( is_object( $form ) ? $form->id : $form ), $type, $action_status );
581 467
582 468 if ( empty( $form_actions ) ) {
583 469 return;
584 470 }
@@ -583,14 +469,11 @@
583 469 return;
584 470 }
585 471
586 472 FrmForm::maybe_get_form( $form );
587 - if ( ! is_object( $form ) ) {
588 - return;
589 - }
590 473
591 474 $link_settings = self::get_form_actions( $type );
592 - if ( 'all' !== $type ) {
475 + if ( 'all' != $type ) {
593 476 $link_settings = array( $type => $link_settings );
594 477 }
595 478
596 479 $stored_actions = array();
@@ -595,9 +478,9 @@
595 478
596 479 $stored_actions = array();
597 480 $action_priority = array();
598 481
599 - if ( in_array( $event, array( 'create', 'update' ), true ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
482 + if ( in_array( $event, array( 'create', 'update' ) ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
600 483 $this_event = 'import';
601 484 } else {
602 485 $this_event = $event;
603 486 }
@@ -603,9 +486,9 @@
603 486 }
604 487
605 488 foreach ( $form_actions as $action ) {
606 489
607 - $skip_this_action = ! in_array( $this_event, $action->post_content['event'], true ) || FrmOnSubmitAction::$slug === $action->post_excerpt;
490 + $skip_this_action = ( ! in_array( $this_event, $action->post_content['event'] ) );
608 491 $skip_this_action = apply_filters( 'frm_skip_form_action', $skip_this_action, compact( 'action', 'entry', 'form', 'event' ) );
609 492 if ( $skip_this_action ) {
610 493 continue;
611 494 }
@@ -613,13 +496,13 @@
613 496 if ( ! is_object( $entry ) ) {
614 497 $entry = FrmEntry::getOne( $entry, true );
615 498 }
616 499
617 - if ( empty( $entry ) || ( FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $entry->is_draft && 'draft' !== $event ) ) {
500 + if ( empty( $entry ) || ( $entry->is_draft && $event != 'draft' ) ) {
618 501 continue;
619 502 }
620 503
621 - $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'] );
504 + $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'] ) );
622 505
623 506 if ( $child_entry ) {
624 507 // maybe trigger actions for sub forms
625 508 $trigger_children = apply_filters( 'frm_use_embedded_form_actions', false, compact( 'form', 'entry' ) );
@@ -638,9 +521,9 @@
638 521 $stored_actions[ $action->ID ] = $action;
639 522 $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority'];
640 523
641 524 unset( $action );
642 - }//end foreach
525 + }
643 526
644 527 if ( ! empty( $stored_actions ) ) {
645 528 asort( $action_priority );
646 529
@@ -648,42 +531,25 @@
648 531 new FrmNotification();
649 532
650 533 foreach ( $action_priority as $action_id => $priority ) {
651 534 $action = $stored_actions[ $action_id ];
535 + do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event );
536 + do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form );
652 537
653 - /**
654 - * Allows custom form action trigger.
655 - *
656 - * @since 6.10
657 - *
658 - * @param bool $skip Skip default trigger.
659 - * @param object $action Action object.
660 - * @param object $entry Entry object.
661 - * @param object $form Form object.
662 - * @param string $event Event ('create' or 'update').
663 - */
664 - if ( false === apply_filters( 'frm_custom_trigger_action', false, $action, $entry, $form, $event ) ) {
665 - do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event );
666 - do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form );
667 - }
668 -
669 538 // If post is created, get updated $entry object.
670 - if ( $action->post_excerpt === 'wppost' && $event === 'create' ) {
539 + if ( $action->post_excerpt == 'wppost' && $event == 'create' ) {
671 540 $entry = FrmEntry::getOne( $entry->id, true );
672 541 }
673 - }//end foreach
674 - }//end if
542 + }
543 + }
675 544 }
676 545
677 546 public static function duplicate_form_actions( $form_id, $values, $args = array() ) {
678 - if ( empty( $args['old_id'] ) ) {
547 + if ( ! isset( $args['old_id'] ) || empty( $args['old_id'] ) ) {
679 548 // Continue if we know which actions to copy.
680 549 return;
681 550 }
682 551
683 - /**
684 - * @var array
685 - */
686 552 $action_controls = self::get_form_actions();
687 553
688 554 foreach ( $action_controls as $action_control ) {
689 555 $action_control->duplicate_form_actions( $form_id, $args['old_id'] );
@@ -700,24 +566,8 @@
700 566
701 567 $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] );
702 568
703 569 return $where;
704 - }
705 -
706 - /**
707 - * Prevent WPML from filtering form actions based on the active language.
708 - *
709 - * @since 6.20
710 - *
711 - * @param bool|null $null
712 - * @param string $post_type
713 - * @return bool|null
714 - */
715 - public static function prevent_wpml_translations( $null, $post_type ) {
716 - if ( self::$action_post_type === $post_type ) {
717 - return false;
718 - }
719 - return $null;
720 570 }
721 571 }
722 572
723 573 class Frm_Form_Action_Factory {