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