PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.1
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 -208 6.255.1 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,34 @@
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 + 'mailchimp' => 'FrmDefMlcmpAction',
50 + 'api' => 'FrmDefApiAction',
51 +
52 + 'salesforce' => 'FrmDefSalesforceAction',
53 + 'activecampaign' => 'FrmDefActiveCampaignAction',
54 + 'constantcontact' => 'FrmDefConstContactAction',
55 + 'getresponse' => 'FrmDefGetResponseAction',
56 + 'hubspot' => 'FrmDefHubspotAction',
57 + 'zapier' => 'FrmDefZapierAction',
58 + 'twilio' => 'FrmDefTwilioAction',
59 + 'highrise' => 'FrmDefHighriseAction',
60 + 'mailpoet' => 'FrmDefMailpoetAction',
61 + 'aweber' => 'FrmDefAweberAction',
73 62 );
74 63
75 64 $action_classes = apply_filters( 'frm_registered_form_actions', $action_classes );
76 - $action_classes = self::maybe_unset_highrise( $action_classes );
77 65
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';
66 + include_once( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php' );
67 + include_once( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php' );
80 68
81 69 foreach ( $action_classes as $action_class ) {
82 70 self::$registered_actions->register( $action_class );
83 71 }
@@ -83,23 +71,8 @@
83 71 }
84 72 }
85 73
86 74 /**
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 75 * @since 4.0
103 76 *
104 77 * @param array $values
105 78 */
@@ -111,9 +84,9 @@
111 84 self::maybe_add_action_to_group( $action_controls, $groups );
112 85
113 86 $allowed = self::active_actions( $action_controls );
114 87
115 - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/settings.php';
88 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/settings.php' );
116 89 }
117 90
118 91 /**
119 92 * Add unknown actions to a group.
@@ -153,9 +126,9 @@
153 126 * @return array
154 127 */
155 128 public static function form_action_groups() {
156 129 $groups = array(
157 - 'misc' => array(
130 + 'misc' => array(
158 131 'name' => '',
159 132 'icon' => 'frm_icon_font frm_shuffle_icon',
160 133 'actions' => array(
161 134 'email',
@@ -160,10 +133,8 @@
160 133 'actions' => array(
161 134 'email',
162 135 'wppost',
163 136 'register',
164 - 'quiz',
165 - 'quiz_outcome',
166 137 'twilio',
167 138 ),
168 139 ),
169 140 'payment' => array(
@@ -183,15 +154,18 @@
183 154 'constantcontact',
184 155 'getresponse',
185 156 'aweber',
186 157 'mailpoet',
187 - 'convertkit',
188 158 ),
189 159 ),
190 160 'crm' => array(
191 161 'name' => __( 'CRM', 'formidable' ),
192 162 'icon' => 'frm_icon_font frm_address_card_icon',
193 - 'actions' => self::get_crm_actions(),
163 + 'actions' => array(
164 + 'salesforce',
165 + 'hubspot',
166 + 'highrise',
167 + ),
194 168 ),
195 169 );
196 170
197 171 return apply_filters( 'frm_action_groups', $groups );
@@ -197,30 +171,8 @@
197 171 return apply_filters( 'frm_action_groups', $groups );
198 172 }
199 173
200 174 /**
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 175 * Get the number of currently active form actions.
224 176 *
225 177 * @since 4.0
226 178 *
@@ -251,9 +203,9 @@
251 203
252 204 /* translators: %s: Name of form action */
253 205 $upgrade_label = sprintf( esc_html__( '%s form actions', 'formidable' ), $action_control->action_options['tooltip'] );
254 206
255 - $default_shown = array( 'wppost', 'register', 'payment', 'quiz', 'hubspot' );
207 + $default_shown = array( 'wppost', 'register', 'paypal', 'payment', 'hubspot' );
256 208 $default_shown = array_values( array_diff( $default_shown, $allowed ) );
257 209 $default_position = array_search( $action_control->id_base, $default_shown );
258 210 $allowed_count = count( $allowed );
259 211
@@ -280,15 +232,15 @@
280 232 $requires = FrmFormsHelper::get_plan_required( $upgrading );
281 233 if ( $requires && 'free' !== $requires ) {
282 234 $data['data-requires'] = $requires;
283 235 }
284 - }//end if
236 + }
285 237
286 238 // HTML to include on the icon.
287 239 $icon_atts = array();
288 - if ( $action_control->action_options['color'] !== 'var(--primary-700)' ) {
240 + if ( $action_control->action_options['color'] !== 'var(--primary-hover)' ) {
289 241 $icon_atts = array(
290 - 'style' => '--primary-700:' . $action_control->action_options['color'],
242 + 'style' => '--primary-hover:' . $action_control->action_options['color'],
291 243 );
292 244 }
293 245
294 246 include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_icon.php';
@@ -293,12 +245,8 @@
293 245
294 246 include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_icon.php';
295 247 }
296 248
297 - /**
298 - * @param string $action
299 - * @return array|FrmFormAction A single form action is returned when a specific $action value is requested.
300 - */
301 249 public static function get_form_actions( $action = 'all' ) {
302 250 $temp_actions = self::$registered_actions;
303 251 if ( empty( $temp_actions ) ) {
304 252 self::actions_init();
@@ -309,9 +257,9 @@
309 257
310 258 $actions = array();
311 259
312 260 foreach ( $temp_actions as $a ) {
313 - if ( 'all' !== $action && $a->id_base == $action ) {
261 + if ( 'all' != $action && $a->id_base == $action ) {
314 262 return $a;
315 263 }
316 264
317 265 $actions[ $a->id_base ] = $a;
@@ -339,11 +287,8 @@
339 287 'post_status' => 'all',
340 288 );
341 289 $form_actions = FrmFormAction::get_action_for_form( $form->id, 'all', $filters );
342 290
343 - /**
344 - * @var array
345 - */
346 291 $action_controls = self::get_form_actions();
347 292
348 293 $action_map = array();
349 294
@@ -350,10 +295,8 @@
350 295 foreach ( $action_controls as $key => $control ) {
351 296 $action_map[ $control->id_base ] = $key;
352 297 }
353 298
354 - self::maybe_show_limit_warning( $form->id, $form_actions );
355 -
356 299 foreach ( $form_actions as $action ) {
357 300 if ( ! isset( $action_map[ $action->post_excerpt ] ) ) {
358 301 // don't try and show settings if action no longer exists
359 302 continue;
@@ -362,48 +305,14 @@
362 305 self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values );
363 306 }
364 307 }
365 308
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 309 public static function action_control( $form_action, $form, $action_key, $action_control, $values ) {
401 310 $action_control->_set( $action_key );
402 311
403 312 $use_logging = self::should_show_log_message( $form_action->post_excerpt );
404 313
405 - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php';
314 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' );
406 315 }
407 316
408 317 public static function add_form_action() {
409 318 FrmAppHelper::permission_check( 'frm_edit_forms' );
@@ -413,11 +322,8 @@
413 322
414 323 $action_key = FrmAppHelper::get_param( 'list_id', '', 'post', 'absint' );
415 324 $action_type = FrmAppHelper::get_param( 'type', '', 'post', 'sanitize_text_field' );
416 325
417 - /**
418 - * @var FrmFormAction
419 - */
420 326 $action_control = self::get_form_actions( $action_type );
421 327 $action_control->_set( $action_key );
422 328
423 329 $form_id = FrmAppHelper::get_param( 'form_id', '', 'post', 'absint' );
@@ -427,9 +333,9 @@
427 333
428 334 $values = array();
429 335 $form = self::fields_to_values( $form_id, $values );
430 336
431 - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php';
337 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' );
432 338 wp_die();
433 339 }
434 340
435 341 public static function fill_action() {
@@ -450,9 +356,9 @@
450 356 $form = self::fields_to_values( $form_action->menu_order, $values );
451 357
452 358 $use_logging = self::should_show_log_message( $action_type );
453 359
454 - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_inside.php';
360 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_inside.php' );
455 361 wp_die();
456 362 }
457 363
458 364 /**
@@ -460,9 +366,9 @@
460 366 * @return bool
461 367 */
462 368 private static function should_show_log_message( $action_type ) {
463 369 $logging = array( 'api', 'salesforce', 'constantcontact', 'activecampaign' );
464 - return in_array( $action_type, $logging, true ) && ! function_exists( 'frm_log_autoloader' );
370 + return in_array( $action_type, $logging ) && ! function_exists( 'frm_log_autoloader' );
465 371 }
466 372
467 373 private static function fields_to_values( $form_id, array &$values ) {
468 374 $form = FrmForm::getOne( $form_id );
@@ -486,31 +392,13 @@
486 392
487 393 return $form;
488 394 }
489 395
490 - /**
491 - * @param int $form_id
492 - * @return void
493 - */
494 396 public static function update_settings( $form_id ) {
495 397 FrmAppHelper::permission_check( 'frm_edit_forms' );
496 398 $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
497 399 if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
498 - $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;
400 + wp_die( esc_html__( 'You do not have permission to do that', 'formidable' ) );
513 401 }
514 402
515 403 global $wpdb;
516 404
@@ -539,10 +427,8 @@
539 427 }
540 428 $old_actions = array_diff( $old_actions, $new_actions );
541 429
542 430 self::delete_missing_actions( $old_actions );
543 -
544 - FrmOnSubmitHelper::save_on_submit_settings( $form_id );
545 431 }
546 432
547 433 public static function delete_missing_actions( $old_actions ) {
548 434 if ( ! empty( $old_actions ) ) {
@@ -557,16 +443,9 @@
557 443 $filter_args = $args;
558 444 $filter_args['entry_id'] = $entry_id;
559 445 $filter_args['form_id'] = $form_id;
560 446
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 );
447 + $event = apply_filters( 'frm_trigger_create_action', 'create', $args );
569 448
570 449 self::trigger_actions( $event, $form_id, $entry_id, 'all', $args );
571 450 }
572 451
@@ -576,9 +455,9 @@
576 455 public static function trigger_actions( $event, $form, $entry, $type = 'all', $args = array() ) {
577 456 $action_status = array(
578 457 'post_status' => 'publish',
579 458 );
580 - $form_actions = FrmFormAction::get_action_for_form( ( is_object( $form ) ? $form->id : $form ), $type, $action_status );
459 + $form_actions = FrmFormAction::get_action_for_form( ( is_object( $form ) ? $form->id : $form ), $type, $action_status );
581 460
582 461 if ( empty( $form_actions ) ) {
583 462 return;
584 463 }
@@ -583,14 +462,11 @@
583 462 return;
584 463 }
585 464
586 465 FrmForm::maybe_get_form( $form );
587 - if ( ! is_object( $form ) ) {
588 - return;
589 - }
590 466
591 467 $link_settings = self::get_form_actions( $type );
592 - if ( 'all' !== $type ) {
468 + if ( 'all' != $type ) {
593 469 $link_settings = array( $type => $link_settings );
594 470 }
595 471
596 472 $stored_actions = array();
@@ -595,9 +471,9 @@
595 471
596 472 $stored_actions = array();
597 473 $action_priority = array();
598 474
599 - if ( in_array( $event, array( 'create', 'update' ), true ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
475 + if ( in_array( $event, array( 'create', 'update' ) ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
600 476 $this_event = 'import';
601 477 } else {
602 478 $this_event = $event;
603 479 }
@@ -603,9 +479,9 @@
603 479 }
604 480
605 481 foreach ( $form_actions as $action ) {
606 482
607 - $skip_this_action = ! in_array( $this_event, $action->post_content['event'], true ) || FrmOnSubmitAction::$slug === $action->post_excerpt;
483 + $skip_this_action = ( ! in_array( $this_event, $action->post_content['event'] ) );
608 484 $skip_this_action = apply_filters( 'frm_skip_form_action', $skip_this_action, compact( 'action', 'entry', 'form', 'event' ) );
609 485 if ( $skip_this_action ) {
610 486 continue;
611 487 }
@@ -613,13 +489,13 @@
613 489 if ( ! is_object( $entry ) ) {
614 490 $entry = FrmEntry::getOne( $entry, true );
615 491 }
616 492
617 - if ( empty( $entry ) || ( FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $entry->is_draft && 'draft' !== $event ) ) {
493 + if ( empty( $entry ) || ( $entry->is_draft && $event != 'draft' ) ) {
618 494 continue;
619 495 }
620 496
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'] );
497 + $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 498
623 499 if ( $child_entry ) {
624 500 // maybe trigger actions for sub forms
625 501 $trigger_children = apply_filters( 'frm_use_embedded_form_actions', false, compact( 'form', 'entry' ) );
@@ -638,9 +514,9 @@
638 514 $stored_actions[ $action->ID ] = $action;
639 515 $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority'];
640 516
641 517 unset( $action );
642 - }//end foreach
518 + }
643 519
644 520 if ( ! empty( $stored_actions ) ) {
645 521 asort( $action_priority );
646 522
@@ -648,42 +524,25 @@
648 524 new FrmNotification();
649 525
650 526 foreach ( $action_priority as $action_id => $priority ) {
651 527 $action = $stored_actions[ $action_id ];
528 + do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event );
529 + do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form );
652 530
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 531 // If post is created, get updated $entry object.
670 - if ( $action->post_excerpt === 'wppost' && $event === 'create' ) {
532 + if ( $action->post_excerpt == 'wppost' && $event == 'create' ) {
671 533 $entry = FrmEntry::getOne( $entry->id, true );
672 534 }
673 - }//end foreach
674 - }//end if
535 + }
536 + }
675 537 }
676 538
677 539 public static function duplicate_form_actions( $form_id, $values, $args = array() ) {
678 - if ( empty( $args['old_id'] ) ) {
540 + if ( ! isset( $args['old_id'] ) || empty( $args['old_id'] ) ) {
679 541 // Continue if we know which actions to copy.
680 542 return;
681 543 }
682 544
683 - /**
684 - * @var array
685 - */
686 545 $action_controls = self::get_form_actions();
687 546
688 547 foreach ( $action_controls as $action_control ) {
689 548 $action_control->duplicate_form_actions( $form_id, $args['old_id'] );
@@ -700,24 +559,8 @@
700 559
701 560 $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] );
702 561
703 562 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 563 }
721 564 }
722 565
723 566 class Frm_Form_Action_Factory {