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