PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.0.03
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.0.03
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 +52 -218 6.255.0.03 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', 'mailchimp' );
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
@@ -271,34 +223,21 @@
271 223 $upgrading = FrmAddonsController::install_link( $action_control->action_options['plugin'] );
272 224 if ( isset( $upgrading['url'] ) ) {
273 225 $data['data-oneclick'] = json_encode( $upgrading );
274 226 }
227 + }
275 228
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 229 // HTML to include on the icon.
287 230 $icon_atts = array();
288 - if ( $action_control->action_options['color'] !== 'var(--primary-700)' ) {
231 + if ( $action_control->action_options['color'] !== 'var(--primary-hover)' ) {
289 232 $icon_atts = array(
290 - 'style' => '--primary-700:' . $action_control->action_options['color'],
233 + 'style' => '--primary-hover:' . $action_control->action_options['color'],
291 234 );
292 235 }
293 236
294 - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_icon.php';
237 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_icon.php' );
295 238 }
296 239
297 - /**
298 - * @param string $action
299 - * @return array|FrmFormAction A single form action is returned when a specific $action value is requested.
300 - */
301 240 public static function get_form_actions( $action = 'all' ) {
302 241 $temp_actions = self::$registered_actions;
303 242 if ( empty( $temp_actions ) ) {
304 243 self::actions_init();
@@ -309,9 +248,9 @@
309 248
310 249 $actions = array();
311 250
312 251 foreach ( $temp_actions as $a ) {
313 - if ( 'all' !== $action && $a->id_base == $action ) {
252 + if ( 'all' != $action && $a->id_base == $action ) {
314 253 return $a;
315 254 }
316 255
317 256 $actions[ $a->id_base ] = $a;
@@ -339,11 +278,8 @@
339 278 'post_status' => 'all',
340 279 );
341 280 $form_actions = FrmFormAction::get_action_for_form( $form->id, 'all', $filters );
342 281
343 - /**
344 - * @var array
345 - */
346 282 $action_controls = self::get_form_actions();
347 283
348 284 $action_map = array();
349 285
@@ -350,10 +286,8 @@
350 286 foreach ( $action_controls as $key => $control ) {
351 287 $action_map[ $control->id_base ] = $key;
352 288 }
353 289
354 - self::maybe_show_limit_warning( $form->id, $form_actions );
355 -
356 290 foreach ( $form_actions as $action ) {
357 291 if ( ! isset( $action_map[ $action->post_excerpt ] ) ) {
358 292 // don't try and show settings if action no longer exists
359 293 continue;
@@ -362,48 +296,14 @@
362 296 self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values );
363 297 }
364 298 }
365 299
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 300 public static function action_control( $form_action, $form, $action_key, $action_control, $values ) {
401 301 $action_control->_set( $action_key );
402 302
403 303 $use_logging = self::should_show_log_message( $form_action->post_excerpt );
404 304
405 - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php';
305 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' );
406 306 }
407 307
408 308 public static function add_form_action() {
409 309 FrmAppHelper::permission_check( 'frm_edit_forms' );
@@ -413,11 +313,8 @@
413 313
414 314 $action_key = FrmAppHelper::get_param( 'list_id', '', 'post', 'absint' );
415 315 $action_type = FrmAppHelper::get_param( 'type', '', 'post', 'sanitize_text_field' );
416 316
417 - /**
418 - * @var FrmFormAction
419 - */
420 317 $action_control = self::get_form_actions( $action_type );
421 318 $action_control->_set( $action_key );
422 319
423 320 $form_id = FrmAppHelper::get_param( 'form_id', '', 'post', 'absint' );
@@ -427,9 +324,9 @@
427 324
428 325 $values = array();
429 326 $form = self::fields_to_values( $form_id, $values );
430 327
431 - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php';
328 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' );
432 329 wp_die();
433 330 }
434 331
435 332 public static function fill_action() {
@@ -450,9 +347,9 @@
450 347 $form = self::fields_to_values( $form_action->menu_order, $values );
451 348
452 349 $use_logging = self::should_show_log_message( $action_type );
453 350
454 - include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_inside.php';
351 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_inside.php' );
455 352 wp_die();
456 353 }
457 354
458 355 /**
@@ -460,9 +357,9 @@
460 357 * @return bool
461 358 */
462 359 private static function should_show_log_message( $action_type ) {
463 360 $logging = array( 'api', 'salesforce', 'constantcontact', 'activecampaign' );
464 - return in_array( $action_type, $logging, true ) && ! function_exists( 'frm_log_autoloader' );
361 + return in_array( $action_type, $logging ) && ! function_exists( 'frm_log_autoloader' );
465 362 }
466 363
467 364 private static function fields_to_values( $form_id, array &$values ) {
468 365 $form = FrmForm::getOne( $form_id );
@@ -486,31 +383,13 @@
486 383
487 384 return $form;
488 385 }
489 386
490 - /**
491 - * @param int $form_id
492 - * @return void
493 - */
494 387 public static function update_settings( $form_id ) {
495 388 FrmAppHelper::permission_check( 'frm_edit_forms' );
496 389 $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
497 390 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;
391 + wp_die( esc_html__( 'You do not have permission to do that', 'formidable' ) );
513 392 }
514 393
515 394 global $wpdb;
516 395
@@ -539,10 +418,8 @@
539 418 }
540 419 $old_actions = array_diff( $old_actions, $new_actions );
541 420
542 421 self::delete_missing_actions( $old_actions );
543 -
544 - FrmOnSubmitHelper::save_on_submit_settings( $form_id );
545 422 }
546 423
547 424 public static function delete_missing_actions( $old_actions ) {
548 425 if ( ! empty( $old_actions ) ) {
@@ -557,16 +434,9 @@
557 434 $filter_args = $args;
558 435 $filter_args['entry_id'] = $entry_id;
559 436 $filter_args['form_id'] = $form_id;
560 437
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 );
438 + $event = apply_filters( 'frm_trigger_create_action', 'create', $args );
569 439
570 440 self::trigger_actions( $event, $form_id, $entry_id, 'all', $args );
571 441 }
572 442
@@ -576,9 +446,9 @@
576 446 public static function trigger_actions( $event, $form, $entry, $type = 'all', $args = array() ) {
577 447 $action_status = array(
578 448 'post_status' => 'publish',
579 449 );
580 - $form_actions = FrmFormAction::get_action_for_form( ( is_object( $form ) ? $form->id : $form ), $type, $action_status );
450 + $form_actions = FrmFormAction::get_action_for_form( ( is_object( $form ) ? $form->id : $form ), $type, $action_status );
581 451
582 452 if ( empty( $form_actions ) ) {
583 453 return;
584 454 }
@@ -583,14 +453,11 @@
583 453 return;
584 454 }
585 455
586 456 FrmForm::maybe_get_form( $form );
587 - if ( ! is_object( $form ) ) {
588 - return;
589 - }
590 457
591 458 $link_settings = self::get_form_actions( $type );
592 - if ( 'all' !== $type ) {
459 + if ( 'all' != $type ) {
593 460 $link_settings = array( $type => $link_settings );
594 461 }
595 462
596 463 $stored_actions = array();
@@ -595,9 +462,9 @@
595 462
596 463 $stored_actions = array();
597 464 $action_priority = array();
598 465
599 - if ( in_array( $event, array( 'create', 'update' ), true ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
466 + if ( in_array( $event, array( 'create', 'update' ) ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
600 467 $this_event = 'import';
601 468 } else {
602 469 $this_event = $event;
603 470 }
@@ -603,9 +470,9 @@
603 470 }
604 471
605 472 foreach ( $form_actions as $action ) {
606 473
607 - $skip_this_action = ! in_array( $this_event, $action->post_content['event'], true ) || FrmOnSubmitAction::$slug === $action->post_excerpt;
474 + $skip_this_action = ( ! in_array( $this_event, $action->post_content['event'] ) );
608 475 $skip_this_action = apply_filters( 'frm_skip_form_action', $skip_this_action, compact( 'action', 'entry', 'form', 'event' ) );
609 476 if ( $skip_this_action ) {
610 477 continue;
611 478 }
@@ -613,13 +480,13 @@
613 480 if ( ! is_object( $entry ) ) {
614 481 $entry = FrmEntry::getOne( $entry, true );
615 482 }
616 483
617 - if ( empty( $entry ) || ( FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $entry->is_draft && 'draft' !== $event ) ) {
484 + if ( empty( $entry ) || ( $entry->is_draft && $event != 'draft' ) ) {
618 485 continue;
619 486 }
620 487
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'] );
488 + $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 489
623 490 if ( $child_entry ) {
624 491 // maybe trigger actions for sub forms
625 492 $trigger_children = apply_filters( 'frm_use_embedded_form_actions', false, compact( 'form', 'entry' ) );
@@ -638,9 +505,9 @@
638 505 $stored_actions[ $action->ID ] = $action;
639 506 $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority'];
640 507
641 508 unset( $action );
642 - }//end foreach
509 + }
643 510
644 511 if ( ! empty( $stored_actions ) ) {
645 512 asort( $action_priority );
646 513
@@ -648,42 +515,25 @@
648 515 new FrmNotification();
649 516
650 517 foreach ( $action_priority as $action_id => $priority ) {
651 518 $action = $stored_actions[ $action_id ];
519 + do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event );
520 + do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form );
652 521
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 522 // If post is created, get updated $entry object.
670 - if ( $action->post_excerpt === 'wppost' && $event === 'create' ) {
523 + if ( $action->post_excerpt == 'wppost' && $event == 'create' ) {
671 524 $entry = FrmEntry::getOne( $entry->id, true );
672 525 }
673 - }//end foreach
674 - }//end if
526 + }
527 + }
675 528 }
676 529
677 530 public static function duplicate_form_actions( $form_id, $values, $args = array() ) {
678 - if ( empty( $args['old_id'] ) ) {
531 + if ( ! isset( $args['old_id'] ) || empty( $args['old_id'] ) ) {
679 532 // Continue if we know which actions to copy.
680 533 return;
681 534 }
682 535
683 - /**
684 - * @var array
685 - */
686 536 $action_controls = self::get_form_actions();
687 537
688 538 foreach ( $action_controls as $action_control ) {
689 539 $action_control->duplicate_form_actions( $form_id, $args['old_id'] );
@@ -700,24 +550,8 @@
700 550
701 551 $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] );
702 552
703 553 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 554 }
721 555 }
722 556
723 557 class Frm_Form_Action_Factory {