PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7.2
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 +19 -258 6.266.7.2 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 );
@@ -318,16 +253,10 @@
318 253
319 254 include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_icon.php';
320 255 }
321 256
322 - /**
323 - * @param string $action
324 - *
325 - * @return array|FrmFormAction A single form action is returned when a specific $action value is requested.
326 - */
327 257 public static function get_form_actions( $action = 'all' ) {
328 258 $temp_actions = self::$registered_actions;
329 -
330 259 if ( empty( $temp_actions ) ) {
331 260 self::actions_init();
332 261 $temp_actions = self::$registered_actions->actions;
333 262 } else {
@@ -336,9 +265,9 @@
336 265
337 266 $actions = array();
338 267
339 268 foreach ( $temp_actions as $a ) {
340 - if ( 'all' !== $action && $a->id_base == $action ) {
269 + if ( 'all' != $action && $a->id_base == $action ) {
341 270 return $a;
342 271 }
343 272
344 273 $actions[ $a->id_base ] = $a;
@@ -348,13 +277,8 @@
348 277 }
349 278
350 279 /**
351 280 * @since 2.0
352 - *
353 - * @param object $form
354 - * @param array $values
355 - *
356 - * @return void
357 281 */
358 282 public static function list_actions( $form, $values ) {
359 283 if ( empty( $form ) ) {
360 284 return;
@@ -371,11 +295,8 @@
371 295 'post_status' => 'all',
372 296 );
373 297 $form_actions = FrmFormAction::get_action_for_form( $form->id, 'all', $filters );
374 298
375 - /**
376 - * @var array
377 - */
378 299 $action_controls = self::get_form_actions();
379 300
380 301 $action_map = array();
381 302
@@ -382,10 +303,8 @@
382 303 foreach ( $action_controls as $key => $control ) {
383 304 $action_map[ $control->id_base ] = $key;
384 305 }
385 306
386 - self::maybe_show_limit_warning( $form->id, $form_actions );
387 -
388 307 foreach ( $form_actions as $action ) {
389 308 if ( ! isset( $action_map[ $action->post_excerpt ] ) ) {
390 309 // don't try and show settings if action no longer exists
391 310 continue;
@@ -394,54 +313,8 @@
394 313 self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values );
395 314 }
396 315 }
397 316
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 317 public static function action_control( $form_action, $form, $action_key, $action_control, $values ) {
445 318 $action_control->_set( $action_key );
446 319
447 320 $use_logging = self::should_show_log_message( $form_action->post_excerpt );
@@ -457,11 +330,8 @@
457 330
458 331 $action_key = FrmAppHelper::get_param( 'list_id', '', 'post', 'absint' );
459 332 $action_type = FrmAppHelper::get_param( 'type', '', 'post', 'sanitize_text_field' );
460 333
461 - /**
462 - * @var FrmFormAction
463 - */
464 334 $action_control = self::get_form_actions( $action_type );
465 335 $action_control->_set( $action_key );
466 336
467 337 $form_id = FrmAppHelper::get_param( 'form_id', '', 'post', 'absint' );
@@ -483,9 +353,8 @@
483 353 $action_key = FrmAppHelper::get_param( 'action_id', '', 'post', 'absint' );
484 354 $action_type = FrmAppHelper::get_param( 'action_type', '', 'post', 'sanitize_text_field' );
485 355
486 356 $action_control = self::get_form_actions( $action_type );
487 -
488 357 if ( empty( $action_control ) ) {
489 358 wp_die();
490 359 }
491 360
@@ -501,24 +370,15 @@
501 370 }
502 371
503 372 /**
504 373 * @since 3.06.04
505 - *
506 - * @param string $action_type
507 - *
508 374 * @return bool
509 375 */
510 376 private static function should_show_log_message( $action_type ) {
511 377 $logging = array( 'api', 'salesforce', 'constantcontact', 'activecampaign' );
512 - return in_array( $action_type, $logging, true ) && ! function_exists( 'frm_log_autoloader' );
378 + return in_array( $action_type, $logging ) && ! function_exists( 'frm_log_autoloader' );
513 379 }
514 380
515 - /**
516 - * @param int|string $form_id
517 - * @param array $values
518 - *
519 - * @return object
520 - */
521 381 private static function fields_to_values( $form_id, array &$values ) {
522 382 $form = FrmForm::getOne( $form_id );
523 383
524 384 $values = array(
@@ -526,14 +386,12 @@
526 386 'id' => $form->id,
527 387 );
528 388
529 389 $fields = FrmField::get_all_for_form( $form->id );
530 -
531 390 foreach ( $fields as $k => $f ) {
532 391 $f = (array) $f;
533 392 $opts = (array) $f['field_options'];
534 393 $f = array_merge( $opts, $f );
535 -
536 394 if ( ! isset( $f['post_field'] ) ) {
537 395 $f['post_field'] = '';
538 396 }
539 397 $values['fields'][] = $f;
@@ -544,21 +402,19 @@
544 402 }
545 403
546 404 /**
547 405 * @param int $form_id
548 - *
549 406 * @return void
550 407 */
551 408 public static function update_settings( $form_id ) {
552 409 FrmAppHelper::permission_check( 'frm_edit_forms' );
553 410 $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
554 -
555 411 if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
556 412 $frm_settings = FrmAppHelper::get_settings();
557 - $error_args = array(
558 - 'title' => __( 'Verification failed', 'formidable' ),
559 - 'body' => $frm_settings->admin_permission,
560 - 'cancel_url' => add_query_arg(
413 + $error_args = array(
414 + 'title' => __( 'Verification failed', 'formidable' ),
415 + 'body' => $frm_settings->admin_permission,
416 + 'cancel_url' => add_query_arg(
561 417 array(
562 418 'page' => 'formidable',
563 419 'frm_action' => 'settings',
564 420 'id' => $form_id,
@@ -585,9 +441,8 @@
585 441 $new_actions = array();
586 442
587 443 foreach ( $registered_actions as $registered_action ) {
588 444 $action_ids = $registered_action->update_callback( $form_id );
589 -
590 445 if ( ! empty( $action_ids ) ) {
591 446 $new_actions[] = $action_ids;
592 447 }
593 448 }
@@ -595,9 +450,8 @@
595 450 // Only use array_merge if there are new actions.
596 451 if ( ! empty( $new_actions ) ) {
597 452 $new_actions = call_user_func_array( 'array_merge', $new_actions );
598 453 }
599 -
600 454 $old_actions = array_diff( $old_actions, $new_actions );
601 455
602 456 self::delete_missing_actions( $old_actions );
603 457
@@ -603,13 +457,8 @@
603 457
604 458 FrmOnSubmitHelper::save_on_submit_settings( $form_id );
605 459 }
606 460
607 - /**
608 - * @param array $old_actions
609 - *
610 - * @return void
611 - */
612 461 public static function delete_missing_actions( $old_actions ) {
613 462 if ( ! empty( $old_actions ) ) {
614 463 foreach ( $old_actions as $old_id ) {
615 464 wp_delete_post( $old_id );
@@ -617,40 +466,20 @@
617 466 FrmDb::cache_delete_group( 'frm_actions' );
618 467 }
619 468 }
620 469
621 - /**
622 - * @param int|string $entry_id
623 - * @param int|string $form_id
624 - * @param array $args
625 - *
626 - * @return void
627 - */
628 470 public static function trigger_create_actions( $entry_id, $form_id, $args = array() ) {
629 471 $filter_args = $args;
630 472 $filter_args['entry_id'] = $entry_id;
631 473 $filter_args['form_id'] = $form_id;
632 474
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 );
475 + $event = apply_filters( 'frm_trigger_create_action', 'create', $args );
641 476
642 477 self::trigger_actions( $event, $form_id, $entry_id, 'all', $args );
643 478 }
644 479
645 480 /**
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
481 + * @param string $event
653 482 */
654 483 public static function trigger_actions( $event, $form, $entry, $type = 'all', $args = array() ) {
655 484 $action_status = array(
656 485 'post_status' => 'publish',
@@ -662,15 +491,10 @@
662 491 }
663 492
664 493 FrmForm::maybe_get_form( $form );
665 494
666 - if ( ! is_object( $form ) ) {
667 - return;
668 - }
669 -
670 495 $link_settings = self::get_form_actions( $type );
671 -
672 - if ( 'all' !== $type ) {
496 + if ( 'all' != $type ) {
673 497 $link_settings = array( $type => $link_settings );
674 498 }
675 499
676 500 $stored_actions = array();
@@ -685,9 +509,8 @@
685 509 foreach ( $form_actions as $action ) {
686 510
687 511 $skip_this_action = ! in_array( $this_event, $action->post_content['event'], true ) || FrmOnSubmitAction::$slug === $action->post_excerpt;
688 512 $skip_this_action = apply_filters( 'frm_skip_form_action', $skip_this_action, compact( 'action', 'entry', 'form', 'event' ) );
689 -
690 513 if ( $skip_this_action ) {
691 514 continue;
692 515 }
693 516
@@ -698,14 +521,13 @@
698 521 if ( empty( $entry ) || ( FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $entry->is_draft && 'draft' !== $event ) ) {
699 522 continue;
700 523 }
701 524
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'] );
525 + $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 526
704 527 if ( $child_entry ) {
705 528 // maybe trigger actions for sub forms
706 529 $trigger_children = apply_filters( 'frm_use_embedded_form_actions', false, compact( 'form', 'entry' ) );
707 -
708 530 if ( ! $trigger_children ) {
709 531 continue;
710 532 }
711 533 }
@@ -711,9 +533,8 @@
711 533 }
712 534
713 535 // Check conditional logic.
714 536 $stop = FrmFormAction::action_conditions_met( $action, $entry );
715 -
716 537 if ( $stop ) {
717 538 continue;
718 539 }
719 540
@@ -731,40 +552,19 @@
731 552 new FrmNotification();
732 553
733 554 foreach ( $action_priority as $action_id => $priority ) {
734 555 $action = $stored_actions[ $action_id ];
556 + do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event );
557 + do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form );
735 558
736 - /**
737 - * Allows custom form action trigger.
738 - *
739 - * @since 6.10
740 - *
741 - * @param bool $skip Skip default trigger.
742 - * @param object $action Action object.
743 - * @param object $entry Entry object.
744 - * @param object $form Form object.
745 - * @param string $event Event ('create' or 'update').
746 - */
747 - if ( false === apply_filters( 'frm_custom_trigger_action', false, $action, $entry, $form, $event ) ) {
748 - do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event );
749 - do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form );
750 - }
751 -
752 559 // If post is created, get updated $entry object.
753 560 if ( $action->post_excerpt === 'wppost' && $event === 'create' ) {
754 561 $entry = FrmEntry::getOne( $entry->id, true );
755 562 }
756 - }//end foreach
757 - }//end if
563 + }
564 + }
758 565 }
759 566
760 - /**
761 - * @param int|string $form_id
762 - * @param array $values
763 - * @param array $args
764 - *
765 - * @return void
766 - */
767 567 public static function duplicate_form_actions( $form_id, $values, $args = array() ) {
768 568 if ( empty( $args['old_id'] ) ) {
769 569 // Continue if we know which actions to copy.
770 570 return;
@@ -769,11 +569,8 @@
769 569 // Continue if we know which actions to copy.
770 570 return;
771 571 }
772 572
773 - /**
774 - * @var array
775 - */
776 573 $action_controls = self::get_form_actions();
777 574
778 575 foreach ( $action_controls as $action_control ) {
779 576 $action_control->duplicate_form_actions( $form_id, $args['old_id'] );
@@ -780,13 +577,8 @@
780 577 unset( $action_control );
781 578 }
782 579 }
783 580
784 - /**
785 - * @param string $where
786 - *
787 - * @return string
788 - */
789 581 public static function limit_by_type( $where ) {
790 582 global $frm_vars, $wpdb;
791 583
792 584 if ( ! isset( $frm_vars['action_type'] ) ) {
@@ -796,32 +588,11 @@
796 588 $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] );
797 589
798 590 return $where;
799 591 }
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 592 }
818 593
819 594 class Frm_Form_Action_Factory {
820 -
821 - /**
822 - * @var array
823 - */
824 595 public $actions = array();
825 596
826 597 public function __construct() {
827 598 add_action( 'frm_form_actions_init', array( $this, '_register_actions' ), 100 );
@@ -826,22 +597,12 @@
826 597 public function __construct() {
827 598 add_action( 'frm_form_actions_init', array( $this, '_register_actions' ), 100 );
828 599 }
829 600
830 - /**
831 - * @param string $action_class
832 - *
833 - * @return void
834 - */
835 601 public function register( $action_class ) {
836 602 $this->actions[ $action_class ] = new $action_class();
837 603 }
838 604
839 - /**
840 - * @param string $action_class
841 - *
842 - * @return void
843 - */
844 605 public function unregister( $action_class ) {
845 606 if ( isset( $this->actions[ $action_class ] ) ) {
846 607 unset( $this->actions[ $action_class ] );
847 608 }