PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.5.3
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.5.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 +25 -170 6.255.5.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:
@@ -47,14 +43,13 @@
47 43 * @return void
48 44 */
49 45 public static function register_actions() {
50 46 $action_classes = array(
51 - 'on_submit' => 'FrmOnSubmitAction',
52 47 'email' => 'FrmEmailAction',
53 48 'wppost' => 'FrmDefPostAction',
54 49 'register' => 'FrmDefRegAction',
55 50 'paypal' => 'FrmDefPayPalAction',
56 - 'payment' => 'FrmTransLiteAction',
51 + 'payment' => 'FrmDefHrsAction',
57 52 'quiz' => 'FrmDefQuizAction',
58 53 'quiz_outcome' => 'FrmDefQuizOutcomeAction',
59 54 'mailchimp' => 'FrmDefMlcmpAction',
60 55 'api' => 'FrmDefApiAction',
@@ -67,14 +62,12 @@
67 62 'twilio' => 'FrmDefTwilioAction',
68 63 'highrise' => 'FrmDefHighriseAction',
69 64 'mailpoet' => 'FrmDefMailpoetAction',
70 65 'aweber' => 'FrmDefAweberAction',
71 - 'convertkit' => 'FrmDefConvertKitAction',
72 66 'googlespreadsheet' => 'FrmDefGoogleSpreadsheetAction',
73 67 );
74 68
75 69 $action_classes = apply_filters( 'frm_registered_form_actions', $action_classes );
76 - $action_classes = self::maybe_unset_highrise( $action_classes );
77 70
78 71 include_once FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php';
79 72 include_once FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php';
80 73
@@ -83,23 +76,8 @@
83 76 }
84 77 }
85 78
86 79 /**
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 80 * @since 4.0
103 81 *
104 82 * @param array $values
105 83 */
@@ -183,15 +161,18 @@
183 161 'constantcontact',
184 162 'getresponse',
185 163 'aweber',
186 164 'mailpoet',
187 - 'convertkit',
188 165 ),
189 166 ),
190 167 'crm' => array(
191 168 'name' => __( 'CRM', 'formidable' ),
192 169 'icon' => 'frm_icon_font frm_address_card_icon',
193 - 'actions' => self::get_crm_actions(),
170 + 'actions' => array(
171 + 'salesforce',
172 + 'hubspot',
173 + 'highrise',
174 + ),
194 175 ),
195 176 );
196 177
197 178 return apply_filters( 'frm_action_groups', $groups );
@@ -197,30 +178,8 @@
197 178 return apply_filters( 'frm_action_groups', $groups );
198 179 }
199 180
200 181 /**
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 182 * Get the number of currently active form actions.
224 183 *
225 184 * @since 4.0
226 185 *
@@ -280,15 +239,15 @@
280 239 $requires = FrmFormsHelper::get_plan_required( $upgrading );
281 240 if ( $requires && 'free' !== $requires ) {
282 241 $data['data-requires'] = $requires;
283 242 }
284 - }//end if
243 + }
285 244
286 245 // HTML to include on the icon.
287 246 $icon_atts = array();
288 - if ( $action_control->action_options['color'] !== 'var(--primary-700)' ) {
247 + if ( $action_control->action_options['color'] !== 'var(--primary-hover)' ) {
289 248 $icon_atts = array(
290 - 'style' => '--primary-700:' . $action_control->action_options['color'],
249 + 'style' => '--primary-hover:' . $action_control->action_options['color'],
291 250 );
292 251 }
293 252
294 253 include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_icon.php';
@@ -293,12 +252,8 @@
293 252
294 253 include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_icon.php';
295 254 }
296 255
297 - /**
298 - * @param string $action
299 - * @return array|FrmFormAction A single form action is returned when a specific $action value is requested.
300 - */
301 256 public static function get_form_actions( $action = 'all' ) {
302 257 $temp_actions = self::$registered_actions;
303 258 if ( empty( $temp_actions ) ) {
304 259 self::actions_init();
@@ -309,9 +264,9 @@
309 264
310 265 $actions = array();
311 266
312 267 foreach ( $temp_actions as $a ) {
313 - if ( 'all' !== $action && $a->id_base == $action ) {
268 + if ( 'all' != $action && $a->id_base == $action ) {
314 269 return $a;
315 270 }
316 271
317 272 $actions[ $a->id_base ] = $a;
@@ -339,11 +294,8 @@
339 294 'post_status' => 'all',
340 295 );
341 296 $form_actions = FrmFormAction::get_action_for_form( $form->id, 'all', $filters );
342 297
343 - /**
344 - * @var array
345 - */
346 298 $action_controls = self::get_form_actions();
347 299
348 300 $action_map = array();
349 301
@@ -350,10 +302,8 @@
350 302 foreach ( $action_controls as $key => $control ) {
351 303 $action_map[ $control->id_base ] = $key;
352 304 }
353 305
354 - self::maybe_show_limit_warning( $form->id, $form_actions );
355 -
356 306 foreach ( $form_actions as $action ) {
357 307 if ( ! isset( $action_map[ $action->post_excerpt ] ) ) {
358 308 // don't try and show settings if action no longer exists
359 309 continue;
@@ -362,42 +312,8 @@
362 312 self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values );
363 313 }
364 314 }
365 315
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 316 public static function action_control( $form_action, $form, $action_key, $action_control, $values ) {
401 317 $action_control->_set( $action_key );
402 318
403 319 $use_logging = self::should_show_log_message( $form_action->post_excerpt );
@@ -413,11 +329,8 @@
413 329
414 330 $action_key = FrmAppHelper::get_param( 'list_id', '', 'post', 'absint' );
415 331 $action_type = FrmAppHelper::get_param( 'type', '', 'post', 'sanitize_text_field' );
416 332
417 - /**
418 - * @var FrmFormAction
419 - */
420 333 $action_control = self::get_form_actions( $action_type );
421 334 $action_control->_set( $action_key );
422 335
423 336 $form_id = FrmAppHelper::get_param( 'form_id', '', 'post', 'absint' );
@@ -460,9 +373,9 @@
460 373 * @return bool
461 374 */
462 375 private static function should_show_log_message( $action_type ) {
463 376 $logging = array( 'api', 'salesforce', 'constantcontact', 'activecampaign' );
464 - return in_array( $action_type, $logging, true ) && ! function_exists( 'frm_log_autoloader' );
377 + return in_array( $action_type, $logging ) && ! function_exists( 'frm_log_autoloader' );
465 378 }
466 379
467 380 private static function fields_to_values( $form_id, array &$values ) {
468 381 $form = FrmForm::getOne( $form_id );
@@ -495,22 +408,9 @@
495 408 FrmAppHelper::permission_check( 'frm_edit_forms' );
496 409 $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
497 410 if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
498 411 $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;
412 + wp_die( esc_html( $frm_settings->admin_permission ) );
513 413 }
514 414
515 415 global $wpdb;
516 416
@@ -539,10 +439,8 @@
539 439 }
540 440 $old_actions = array_diff( $old_actions, $new_actions );
541 441
542 442 self::delete_missing_actions( $old_actions );
543 -
544 - FrmOnSubmitHelper::save_on_submit_settings( $form_id );
545 443 }
546 444
547 445 public static function delete_missing_actions( $old_actions ) {
548 446 if ( ! empty( $old_actions ) ) {
@@ -557,16 +455,9 @@
557 455 $filter_args = $args;
558 456 $filter_args['entry_id'] = $entry_id;
559 457 $filter_args['form_id'] = $form_id;
560 458
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 );
459 + $event = apply_filters( 'frm_trigger_create_action', 'create', $args );
569 460
570 461 self::trigger_actions( $event, $form_id, $entry_id, 'all', $args );
571 462 }
572 463
@@ -583,14 +474,11 @@
583 474 return;
584 475 }
585 476
586 477 FrmForm::maybe_get_form( $form );
587 - if ( ! is_object( $form ) ) {
588 - return;
589 - }
590 478
591 479 $link_settings = self::get_form_actions( $type );
592 - if ( 'all' !== $type ) {
480 + if ( 'all' != $type ) {
593 481 $link_settings = array( $type => $link_settings );
594 482 }
595 483
596 484 $stored_actions = array();
@@ -595,9 +483,9 @@
595 483
596 484 $stored_actions = array();
597 485 $action_priority = array();
598 486
599 - if ( in_array( $event, array( 'create', 'update' ), true ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
487 + if ( in_array( $event, array( 'create', 'update' ) ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
600 488 $this_event = 'import';
601 489 } else {
602 490 $this_event = $event;
603 491 }
@@ -603,9 +491,9 @@
603 491 }
604 492
605 493 foreach ( $form_actions as $action ) {
606 494
607 - $skip_this_action = ! in_array( $this_event, $action->post_content['event'], true ) || FrmOnSubmitAction::$slug === $action->post_excerpt;
495 + $skip_this_action = ( ! in_array( $this_event, $action->post_content['event'] ) );
608 496 $skip_this_action = apply_filters( 'frm_skip_form_action', $skip_this_action, compact( 'action', 'entry', 'form', 'event' ) );
609 497 if ( $skip_this_action ) {
610 498 continue;
611 499 }
@@ -613,13 +501,13 @@
613 501 if ( ! is_object( $entry ) ) {
614 502 $entry = FrmEntry::getOne( $entry, true );
615 503 }
616 504
617 - if ( empty( $entry ) || ( FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $entry->is_draft && 'draft' !== $event ) ) {
505 + if ( empty( $entry ) || ( $entry->is_draft && $event != 'draft' ) ) {
618 506 continue;
619 507 }
620 508
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'] );
509 + $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 510
623 511 if ( $child_entry ) {
624 512 // maybe trigger actions for sub forms
625 513 $trigger_children = apply_filters( 'frm_use_embedded_form_actions', false, compact( 'form', 'entry' ) );
@@ -638,9 +526,9 @@
638 526 $stored_actions[ $action->ID ] = $action;
639 527 $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority'];
640 528
641 529 unset( $action );
642 - }//end foreach
530 + }
643 531
644 532 if ( ! empty( $stored_actions ) ) {
645 533 asort( $action_priority );
646 534
@@ -648,42 +536,25 @@
648 536 new FrmNotification();
649 537
650 538 foreach ( $action_priority as $action_id => $priority ) {
651 539 $action = $stored_actions[ $action_id ];
540 + do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event );
541 + do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form );
652 542
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 543 // If post is created, get updated $entry object.
670 - if ( $action->post_excerpt === 'wppost' && $event === 'create' ) {
544 + if ( $action->post_excerpt == 'wppost' && $event == 'create' ) {
671 545 $entry = FrmEntry::getOne( $entry->id, true );
672 546 }
673 - }//end foreach
674 - }//end if
547 + }
548 + }
675 549 }
676 550
677 551 public static function duplicate_form_actions( $form_id, $values, $args = array() ) {
678 - if ( empty( $args['old_id'] ) ) {
552 + if ( ! isset( $args['old_id'] ) || empty( $args['old_id'] ) ) {
679 553 // Continue if we know which actions to copy.
680 554 return;
681 555 }
682 556
683 - /**
684 - * @var array
685 - */
686 557 $action_controls = self::get_form_actions();
687 558
688 559 foreach ( $action_controls as $action_control ) {
689 560 $action_control->duplicate_form_actions( $form_id, $args['old_id'] );
@@ -700,24 +571,8 @@
700 571
701 572 $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] );
702 573
703 574 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 575 }
721 576 }
722 577
723 578 class Frm_Form_Action_Factory {