PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.16
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.16
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 +7 -207 6.266.16 View file →
@@ -3,12 +3,8 @@
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 8
13 9 /**
14 10 * @var array|null
@@ -67,9 +63,8 @@
67 63 'constantcontact' => 'FrmDefConstContactAction',
68 64 'getresponse' => 'FrmDefGetResponseAction',
69 65 'hubspot' => 'FrmDefHubspotAction',
70 66 'zapier' => 'FrmDefZapierAction',
71 - 'n8n' => 'FrmDefN8NAction',
72 67 'twilio' => 'FrmDefTwilioAction',
73 68 'highrise' => 'FrmDefHighriseAction',
74 69 'mailpoet' => 'FrmDefMailpoetAction',
75 70 'aweber' => 'FrmDefAweberAction',
@@ -76,14 +71,9 @@
76 71 'convertkit' => 'FrmDefConvertKitAction',
77 72 'googlespreadsheet' => 'FrmDefGoogleSpreadsheetAction',
78 73 );
79 74
80 - if ( ! FrmAppHelper::show_new_feature( 'n8n' ) ) {
81 - unset( $action_classes['n8n'] );
82 - }
83 -
84 75 $action_classes = apply_filters( 'frm_registered_form_actions', $action_classes );
85 - $action_classes = self::maybe_unset_highrise( $action_classes );
86 76
87 77 include_once FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php';
88 78 include_once FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php';
89 79
@@ -92,24 +82,8 @@
92 82 }
93 83 }
94 84
95 85 /**
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 86 * @since 4.0
113 87 *
114 88 * @param array $values
115 89 */
@@ -128,17 +102,11 @@
128 102 /**
129 103 * Add unknown actions to a group.
130 104 *
131 105 * @since 4.0
132 - *
133 - * @param array $action_controls
134 - * @param array $groups
135 - *
136 - * @return void
137 106 */
138 107 private static function maybe_add_action_to_group( $action_controls, &$groups ) {
139 108 $grouped = array();
140 -
141 109 foreach ( $groups as $group ) {
142 110 if ( isset( $group['actions'] ) ) {
143 111 $grouped = array_merge( $grouped, $group['actions'] );
144 112 }
@@ -149,9 +117,8 @@
149 117 continue;
150 118 }
151 119
152 120 $this_group = $action->action_options['group'];
153 -
154 121 if ( ! isset( $groups[ $this_group ] ) ) {
155 122 $this_group = 'misc';
156 123 }
157 124
@@ -200,15 +167,18 @@
200 167 'constantcontact',
201 168 'getresponse',
202 169 'aweber',
203 170 'mailpoet',
204 - 'convertkit',
205 171 ),
206 172 ),
207 173 'crm' => array(
208 174 'name' => __( 'CRM', 'formidable' ),
209 175 'icon' => 'frm_icon_font frm_address_card_icon',
210 - 'actions' => self::get_crm_actions(),
176 + 'actions' => array(
177 + 'salesforce',
178 + 'hubspot',
179 + 'highrise',
180 + ),
211 181 ),
212 182 );
213 183
214 184 return apply_filters( 'frm_action_groups', $groups );
@@ -214,41 +184,16 @@
214 184 return apply_filters( 'frm_action_groups', $groups );
215 185 }
216 186
217 187 /**
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 188 * Get the number of currently active form actions.
241 189 *
242 190 * @since 4.0
243 191 *
244 - * @param array $action_controls
245 - *
246 192 * @return array
247 193 */
248 194 private static function active_actions( $action_controls ) {
249 195 $allowed = array();
250 -
251 196 foreach ( $action_controls as $action_control ) {
252 197 if ( isset( $action_control->action_options['active'] ) && $action_control->action_options['active'] ) {
253 198 $allowed[] = $action_control->id_base;
254 199 }
@@ -259,9 +204,8 @@
259 204 /**
260 205 * For each add-on, add an li, class, and javascript function. If active, add an additional class.
261 206 *
262 207 * @since 4.0
263 - *
264 208 * @param object $action_control
265 209 * @param array $allowed
266 210 */
267 211 public static function show_action_icon_link( $action_control, $allowed ) {
@@ -281,9 +225,8 @@
281 225 if ( isset( $action_control->action_options['active'] ) && $action_control->action_options['active'] ) {
282 226 $classes .= ' frm_active_action';
283 227 } else {
284 228 $classes .= ' frm_inactive_action';
285 -
286 229 if ( $default_position !== false && ( $allowed_count + $default_position ) < 6 ) {
287 230 $group_class .= ' frm-default-show';
288 231 }
289 232
@@ -290,9 +233,8 @@
290 233 $data['data-upgrade'] = $upgrade_label;
291 234 $data['data-medium'] = 'settings-' . $action_control->id_base;
292 235
293 236 $upgrading = FrmAddonsController::install_link( $action_control->action_options['plugin'] );
294 -
295 237 if ( isset( $upgrading['url'] ) ) {
296 238 $data['data-oneclick'] = json_encode( $upgrading );
297 239 }
298 240
@@ -300,9 +242,8 @@
300 242 $data['data-message'] = $action_control->action_options['message'];
301 243 }
302 244
303 245 $requires = FrmFormsHelper::get_plan_required( $upgrading );
304 -
305 246 if ( $requires && 'free' !== $requires ) {
306 247 $data['data-requires'] = $requires;
307 248 }
308 249 }//end if
@@ -308,9 +249,8 @@
308 249 }//end if
309 250
310 251 // HTML to include on the icon.
311 252 $icon_atts = array();
312 -
313 253 if ( $action_control->action_options['color'] !== 'var(--primary-700)' ) {
314 254 $icon_atts = array(
315 255 'style' => '--primary-700:' . $action_control->action_options['color'],
316 256 );
@@ -320,14 +260,12 @@
320 260 }
321 261
322 262 /**
323 263 * @param string $action
324 - *
325 264 * @return array|FrmFormAction A single form action is returned when a specific $action value is requested.
326 265 */
327 266 public static function get_form_actions( $action = 'all' ) {
328 267 $temp_actions = self::$registered_actions;
329 -
330 268 if ( empty( $temp_actions ) ) {
331 269 self::actions_init();
332 270 $temp_actions = self::$registered_actions->actions;
333 271 } else {
@@ -348,13 +286,8 @@
348 286 }
349 287
350 288 /**
351 289 * @since 2.0
352 - *
353 - * @param object $form
354 - * @param array $values
355 - *
356 - * @return void
357 290 */
358 291 public static function list_actions( $form, $values ) {
359 292 if ( empty( $form ) ) {
360 293 return;
@@ -382,10 +315,8 @@
382 315 foreach ( $action_controls as $key => $control ) {
383 316 $action_map[ $control->id_base ] = $key;
384 317 }
385 318
386 - self::maybe_show_limit_warning( $form->id, $form_actions );
387 -
388 319 foreach ( $form_actions as $action ) {
389 320 if ( ! isset( $action_map[ $action->post_excerpt ] ) ) {
390 321 // don't try and show settings if action no longer exists
391 322 continue;
@@ -394,54 +325,8 @@
394 325 self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values );
395 326 }
396 327 }
397 328
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 329 public static function action_control( $form_action, $form, $action_key, $action_control, $values ) {
445 330 $action_control->_set( $action_key );
446 331
447 332 $use_logging = self::should_show_log_message( $form_action->post_excerpt );
@@ -483,9 +368,8 @@
483 368 $action_key = FrmAppHelper::get_param( 'action_id', '', 'post', 'absint' );
484 369 $action_type = FrmAppHelper::get_param( 'action_type', '', 'post', 'sanitize_text_field' );
485 370
486 371 $action_control = self::get_form_actions( $action_type );
487 -
488 372 if ( empty( $action_control ) ) {
489 373 wp_die();
490 374 }
491 375
@@ -501,11 +385,8 @@
501 385 }
502 386
503 387 /**
504 388 * @since 3.06.04
505 - *
506 - * @param string $action_type
507 - *
508 389 * @return bool
509 390 */
510 391 private static function should_show_log_message( $action_type ) {
511 392 $logging = array( 'api', 'salesforce', 'constantcontact', 'activecampaign' );
@@ -511,14 +392,8 @@
511 392 $logging = array( 'api', 'salesforce', 'constantcontact', 'activecampaign' );
512 393 return in_array( $action_type, $logging, true ) && ! function_exists( 'frm_log_autoloader' );
513 394 }
514 395
515 - /**
516 - * @param int|string $form_id
517 - * @param array $values
518 - *
519 - * @return object
520 - */
521 396 private static function fields_to_values( $form_id, array &$values ) {
522 397 $form = FrmForm::getOne( $form_id );
523 398
524 399 $values = array(
@@ -526,14 +401,12 @@
526 401 'id' => $form->id,
527 402 );
528 403
529 404 $fields = FrmField::get_all_for_form( $form->id );
530 -
531 405 foreach ( $fields as $k => $f ) {
532 406 $f = (array) $f;
533 407 $opts = (array) $f['field_options'];
534 408 $f = array_merge( $opts, $f );
535 -
536 409 if ( ! isset( $f['post_field'] ) ) {
537 410 $f['post_field'] = '';
538 411 }
539 412 $values['fields'][] = $f;
@@ -544,15 +417,13 @@
544 417 }
545 418
546 419 /**
547 420 * @param int $form_id
548 - *
549 421 * @return void
550 422 */
551 423 public static function update_settings( $form_id ) {
552 424 FrmAppHelper::permission_check( 'frm_edit_forms' );
553 425 $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
554 -
555 426 if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
556 427 $frm_settings = FrmAppHelper::get_settings();
557 428 $error_args = array(
558 429 'title' => __( 'Verification failed', 'formidable' ),
@@ -585,9 +456,8 @@
585 456 $new_actions = array();
586 457
587 458 foreach ( $registered_actions as $registered_action ) {
588 459 $action_ids = $registered_action->update_callback( $form_id );
589 -
590 460 if ( ! empty( $action_ids ) ) {
591 461 $new_actions[] = $action_ids;
592 462 }
593 463 }
@@ -595,9 +465,8 @@
595 465 // Only use array_merge if there are new actions.
596 466 if ( ! empty( $new_actions ) ) {
597 467 $new_actions = call_user_func_array( 'array_merge', $new_actions );
598 468 }
599 -
600 469 $old_actions = array_diff( $old_actions, $new_actions );
601 470
602 471 self::delete_missing_actions( $old_actions );
603 472
@@ -603,13 +472,8 @@
603 472
604 473 FrmOnSubmitHelper::save_on_submit_settings( $form_id );
605 474 }
606 475
607 - /**
608 - * @param array $old_actions
609 - *
610 - * @return void
611 - */
612 476 public static function delete_missing_actions( $old_actions ) {
613 477 if ( ! empty( $old_actions ) ) {
614 478 foreach ( $old_actions as $old_id ) {
615 479 wp_delete_post( $old_id );
@@ -617,15 +481,8 @@
617 481 FrmDb::cache_delete_group( 'frm_actions' );
618 482 }
619 483 }
620 484
621 - /**
622 - * @param int|string $entry_id
623 - * @param int|string $form_id
624 - * @param array $args
625 - *
626 - * @return void
627 - */
628 485 public static function trigger_create_actions( $entry_id, $form_id, $args = array() ) {
629 486 $filter_args = $args;
630 487 $filter_args['entry_id'] = $entry_id;
631 488 $filter_args['form_id'] = $form_id;
@@ -642,15 +499,9 @@
642 499 self::trigger_actions( $event, $form_id, $entry_id, 'all', $args );
643 500 }
644 501
645 502 /**
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
503 + * @param string $event
653 504 */
654 505 public static function trigger_actions( $event, $form, $entry, $type = 'all', $args = array() ) {
655 506 $action_status = array(
656 507 'post_status' => 'publish',
@@ -662,14 +513,9 @@
662 513 }
663 514
664 515 FrmForm::maybe_get_form( $form );
665 516
666 - if ( ! is_object( $form ) ) {
667 - return;
668 - }
669 -
670 517 $link_settings = self::get_form_actions( $type );
671 -
672 518 if ( 'all' !== $type ) {
673 519 $link_settings = array( $type => $link_settings );
674 520 }
675 521
@@ -685,9 +531,8 @@
685 531 foreach ( $form_actions as $action ) {
686 532
687 533 $skip_this_action = ! in_array( $this_event, $action->post_content['event'], true ) || FrmOnSubmitAction::$slug === $action->post_excerpt;
688 534 $skip_this_action = apply_filters( 'frm_skip_form_action', $skip_this_action, compact( 'action', 'entry', 'form', 'event' ) );
689 -
690 535 if ( $skip_this_action ) {
691 536 continue;
692 537 }
693 538
@@ -698,14 +543,13 @@
698 543 if ( empty( $entry ) || ( FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $entry->is_draft && 'draft' !== $event ) ) {
699 544 continue;
700 545 }
701 546
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'] );
547 + $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 548
704 549 if ( $child_entry ) {
705 550 // maybe trigger actions for sub forms
706 551 $trigger_children = apply_filters( 'frm_use_embedded_form_actions', false, compact( 'form', 'entry' ) );
707 -
708 552 if ( ! $trigger_children ) {
709 553 continue;
710 554 }
711 555 }
@@ -711,9 +555,8 @@
711 555 }
712 556
713 557 // Check conditional logic.
714 558 $stop = FrmFormAction::action_conditions_met( $action, $entry );
715 -
716 559 if ( $stop ) {
717 560 continue;
718 561 }
719 562
@@ -756,15 +599,8 @@
756 599 }//end foreach
757 600 }//end if
758 601 }
759 602
760 - /**
761 - * @param int|string $form_id
762 - * @param array $values
763 - * @param array $args
764 - *
765 - * @return void
766 - */
767 603 public static function duplicate_form_actions( $form_id, $values, $args = array() ) {
768 604 if ( empty( $args['old_id'] ) ) {
769 605 // Continue if we know which actions to copy.
770 606 return;
@@ -780,13 +616,8 @@
780 616 unset( $action_control );
781 617 }
782 618 }
783 619
784 - /**
785 - * @param string $where
786 - *
787 - * @return string
788 - */
789 620 public static function limit_by_type( $where ) {
790 621 global $frm_vars, $wpdb;
791 622
792 623 if ( ! isset( $frm_vars['action_type'] ) ) {
@@ -796,32 +627,11 @@
796 627 $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] );
797 628
798 629 return $where;
799 630 }
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 631 }
818 632
819 633 class Frm_Form_Action_Factory {
820 -
821 - /**
822 - * @var array
823 - */
824 634 public $actions = array();
825 635
826 636 public function __construct() {
827 637 add_action( 'frm_form_actions_init', array( $this, '_register_actions' ), 100 );
@@ -826,22 +636,12 @@
826 636 public function __construct() {
827 637 add_action( 'frm_form_actions_init', array( $this, '_register_actions' ), 100 );
828 638 }
829 639
830 - /**
831 - * @param string $action_class
832 - *
833 - * @return void
834 - */
835 640 public function register( $action_class ) {
836 641 $this->actions[ $action_class ] = new $action_class();
837 642 }
838 643
839 - /**
840 - * @param string $action_class
841 - *
842 - * @return void
843 - */
844 644 public function unregister( $action_class ) {
845 645 if ( isset( $this->actions[ $action_class ] ) ) {
846 646 unset( $this->actions[ $action_class ] );
847 647 }