| @@ -4,8 +4,12 @@ | ||
| 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 | + */ | |
| 8 | 12 | public static $registered_actions; |
| 9 | 13 | |
| 10 | 14 | /** |
| 11 | 15 | * Variables saved in the post: |
| @@ -48,9 +52,9 @@ | ||
| 48 | 52 | 'email' => 'FrmEmailAction', |
| 49 | 53 | 'wppost' => 'FrmDefPostAction', |
| 50 | 54 | 'register' => 'FrmDefRegAction', |
| 51 | 55 | 'paypal' => 'FrmDefPayPalAction', |
| 52 | - 'payment' => 'FrmDefHrsAction', | |
| 56 | + 'payment' => 'FrmTransLiteAction', | |
| 53 | 57 | 'quiz' => 'FrmDefQuizAction', |
| 54 | 58 | 'quiz_outcome' => 'FrmDefQuizOutcomeAction', |
| 55 | 59 | 'mailchimp' => 'FrmDefMlcmpAction', |
| 56 | 60 | 'api' => 'FrmDefApiAction', |
| @@ -63,8 +67,9 @@ | ||
| 63 | 67 | 'twilio' => 'FrmDefTwilioAction', |
| 64 | 68 | 'highrise' => 'FrmDefHighriseAction', |
| 65 | 69 | 'mailpoet' => 'FrmDefMailpoetAction', |
| 66 | 70 | 'aweber' => 'FrmDefAweberAction', |
| 71 | + 'convertkit' => 'FrmDefConvertKitAction', | |
| 67 | 72 | 'googlespreadsheet' => 'FrmDefGoogleSpreadsheetAction', |
| 68 | 73 | ); |
| 69 | 74 | |
| 70 | 75 | $action_classes = apply_filters( 'frm_registered_form_actions', $action_classes ); |
| @@ -240,9 +245,9 @@ | ||
| 240 | 245 | $requires = FrmFormsHelper::get_plan_required( $upgrading ); |
| 241 | 246 | if ( $requires && 'free' !== $requires ) { |
| 242 | 247 | $data['data-requires'] = $requires; |
| 243 | 248 | } |
| 244 | - } | |
| 249 | + }//end if | |
| 245 | 250 | |
| 246 | 251 | // HTML to include on the icon. |
| 247 | 252 | $icon_atts = array(); |
| 248 | 253 | if ( $action_control->action_options['color'] !== 'var(--primary-700)' ) { |
| @@ -253,8 +258,12 @@ | ||
| 253 | 258 | |
| 254 | 259 | include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_icon.php'; |
| 255 | 260 | } |
| 256 | 261 | |
| 262 | + /** | |
| 263 | + * @param string $action | |
| 264 | + * @return array|FrmFormAction A single form action is returned when a specific $action value is requested. | |
| 265 | + */ | |
| 257 | 266 | public static function get_form_actions( $action = 'all' ) { |
| 258 | 267 | $temp_actions = self::$registered_actions; |
| 259 | 268 | if ( empty( $temp_actions ) ) { |
| 260 | 269 | self::actions_init(); |
| @@ -265,9 +274,9 @@ | ||
| 265 | 274 | |
| 266 | 275 | $actions = array(); |
| 267 | 276 | |
| 268 | 277 | foreach ( $temp_actions as $a ) { |
| 269 | - if ( 'all' != $action && $a->id_base == $action ) { | |
| 278 | + if ( 'all' !== $action && $a->id_base == $action ) { | |
| 270 | 279 | return $a; |
| 271 | 280 | } |
| 272 | 281 | |
| 273 | 282 | $actions[ $a->id_base ] = $a; |
| @@ -295,8 +304,11 @@ | ||
| 295 | 304 | 'post_status' => 'all', |
| 296 | 305 | ); |
| 297 | 306 | $form_actions = FrmFormAction::get_action_for_form( $form->id, 'all', $filters ); |
| 298 | 307 | |
| 308 | + /** | |
| 309 | + * @var array | |
| 310 | + */ | |
| 299 | 311 | $action_controls = self::get_form_actions(); |
| 300 | 312 | |
| 301 | 313 | $action_map = array(); |
| 302 | 314 | |
| @@ -303,8 +315,10 @@ | ||
| 303 | 315 | foreach ( $action_controls as $key => $control ) { |
| 304 | 316 | $action_map[ $control->id_base ] = $key; |
| 305 | 317 | } |
| 306 | 318 | |
| 319 | + self::maybe_show_limit_warning( $form->id, $form_actions ); | |
| 320 | + | |
| 307 | 321 | foreach ( $form_actions as $action ) { |
| 308 | 322 | if ( ! isset( $action_map[ $action->post_excerpt ] ) ) { |
| 309 | 323 | // don't try and show settings if action no longer exists |
| 310 | 324 | continue; |
| @@ -313,8 +327,42 @@ | ||
| 313 | 327 | self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values ); |
| 314 | 328 | } |
| 315 | 329 | } |
| 316 | 330 | |
| 331 | + /** | |
| 332 | + * Show a warning before the form actions list if there are 99 actions, and the limit is set to 99. | |
| 333 | + * If it is filtered, the warning is still shown when applicable, just using the new limit. | |
| 334 | + * | |
| 335 | + * @since 6.17 | |
| 336 | + * | |
| 337 | + * @param int|string $form_id | |
| 338 | + * @param array $form_actions | |
| 339 | + * @return void | |
| 340 | + */ | |
| 341 | + private static function maybe_show_limit_warning( $form_id, $form_actions ) { | |
| 342 | + $count = count( $form_actions ); | |
| 343 | + if ( $count < 99 ) { | |
| 344 | + return; | |
| 345 | + } | |
| 346 | + | |
| 347 | + $limit = FrmFormAction::get_action_limit( $form_id ); | |
| 348 | + if ( $limit < 99 || $count < $limit ) { | |
| 349 | + return; | |
| 350 | + } | |
| 351 | + | |
| 352 | + $documentation_url = 'https://formidableforms.com/knowledgebase/frm_form_action_limit/#kb-increase-limit-of-form-actions'; | |
| 353 | + | |
| 354 | + echo '<div class="frm_warning_style">'; | |
| 355 | + FrmAppHelper::icon_by_class( 'frm_icon_font frm_alert_icon' ); | |
| 356 | + echo ' '; | |
| 357 | + printf( | |
| 358 | + // translators: %s: URL to documentation | |
| 359 | + esc_html__( 'You have reached your form action limit. To increase this limit, you will require additional code. Visit our documentation at %s.', 'formidable' ), | |
| 360 | + '<a href="' . esc_url( $documentation_url ) . '" target="_blank">' . esc_html( $documentation_url ) . '</a>' | |
| 361 | + ); | |
| 362 | + echo '</div>'; | |
| 363 | + } | |
| 364 | + | |
| 317 | 365 | public static function action_control( $form_action, $form, $action_key, $action_control, $values ) { |
| 318 | 366 | $action_control->_set( $action_key ); |
| 319 | 367 | |
| 320 | 368 | $use_logging = self::should_show_log_message( $form_action->post_excerpt ); |
| @@ -330,8 +378,11 @@ | ||
| 330 | 378 | |
| 331 | 379 | $action_key = FrmAppHelper::get_param( 'list_id', '', 'post', 'absint' ); |
| 332 | 380 | $action_type = FrmAppHelper::get_param( 'type', '', 'post', 'sanitize_text_field' ); |
| 333 | 381 | |
| 382 | + /** | |
| 383 | + * @var FrmFormAction | |
| 384 | + */ | |
| 334 | 385 | $action_control = self::get_form_actions( $action_type ); |
| 335 | 386 | $action_control->_set( $action_key ); |
| 336 | 387 | |
| 337 | 388 | $form_id = FrmAppHelper::get_param( 'form_id', '', 'post', 'absint' ); |
| @@ -374,9 +425,9 @@ | ||
| 374 | 425 | * @return bool |
| 375 | 426 | */ |
| 376 | 427 | private static function should_show_log_message( $action_type ) { |
| 377 | 428 | $logging = array( 'api', 'salesforce', 'constantcontact', 'activecampaign' ); |
| 378 | - return in_array( $action_type, $logging ) && ! function_exists( 'frm_log_autoloader' ); | |
| 429 | + return in_array( $action_type, $logging, true ) && ! function_exists( 'frm_log_autoloader' ); | |
| 379 | 430 | } |
| 380 | 431 | |
| 381 | 432 | private static function fields_to_values( $form_id, array &$values ) { |
| 382 | 433 | $form = FrmForm::getOne( $form_id ); |
| @@ -409,9 +460,22 @@ | ||
| 409 | 460 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 410 | 461 | $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' ); |
| 411 | 462 | if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) { |
| 412 | 463 | $frm_settings = FrmAppHelper::get_settings(); |
| 413 | - wp_die( esc_html( $frm_settings->admin_permission ) ); | |
| 464 | + $error_args = array( | |
| 465 | + 'title' => __( 'Verification failed', 'formidable' ), | |
| 466 | + 'body' => $frm_settings->admin_permission, | |
| 467 | + 'cancel_url' => add_query_arg( | |
| 468 | + array( | |
| 469 | + 'page' => 'formidable', | |
| 470 | + 'frm_action' => 'settings', | |
| 471 | + 'id' => $form_id, | |
| 472 | + ), | |
| 473 | + admin_url( 'admin.php?' ) | |
| 474 | + ), | |
| 475 | + ); | |
| 476 | + FrmAppController::show_error_modal( $error_args ); | |
| 477 | + return; | |
| 414 | 478 | } |
| 415 | 479 | |
| 416 | 480 | global $wpdb; |
| 417 | 481 | |
| @@ -458,9 +522,16 @@ | ||
| 458 | 522 | $filter_args = $args; |
| 459 | 523 | $filter_args['entry_id'] = $entry_id; |
| 460 | 524 | $filter_args['form_id'] = $form_id; |
| 461 | 525 | |
| 462 | - $event = apply_filters( 'frm_trigger_create_action', 'create', $args ); | |
| 526 | + /** | |
| 527 | + * @since 2.0.23 | |
| 528 | + * @since 6.11.2 $filter_args is now passed instead of $args. It includes additional ID data. | |
| 529 | + * | |
| 530 | + * @param string $event 'create' by default. Pro may filter this value to 'draft' instead. | |
| 531 | + * @param array $filter_args | |
| 532 | + */ | |
| 533 | + $event = apply_filters( 'frm_trigger_create_action', 'create', $filter_args ); | |
| 463 | 534 | |
| 464 | 535 | self::trigger_actions( $event, $form_id, $entry_id, 'all', $args ); |
| 465 | 536 | } |
| 466 | 537 | |
| @@ -477,11 +548,14 @@ | ||
| 477 | 548 | return; |
| 478 | 549 | } |
| 479 | 550 | |
| 480 | 551 | FrmForm::maybe_get_form( $form ); |
| 552 | + if ( ! is_object( $form ) ) { | |
| 553 | + return; | |
| 554 | + } | |
| 481 | 555 | |
| 482 | 556 | $link_settings = self::get_form_actions( $type ); |
| 483 | - if ( 'all' != $type ) { | |
| 557 | + if ( 'all' !== $type ) { | |
| 484 | 558 | $link_settings = array( $type => $link_settings ); |
| 485 | 559 | } |
| 486 | 560 | |
| 487 | 561 | $stored_actions = array(); |
| @@ -486,9 +560,9 @@ | ||
| 486 | 560 | |
| 487 | 561 | $stored_actions = array(); |
| 488 | 562 | $action_priority = array(); |
| 489 | 563 | |
| 490 | - if ( in_array( $event, array( 'create', 'update' ) ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { | |
| 564 | + if ( in_array( $event, array( 'create', 'update' ), true ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { | |
| 491 | 565 | $this_event = 'import'; |
| 492 | 566 | } else { |
| 493 | 567 | $this_event = $event; |
| 494 | 568 | } |
| @@ -504,13 +578,13 @@ | ||
| 504 | 578 | if ( ! is_object( $entry ) ) { |
| 505 | 579 | $entry = FrmEntry::getOne( $entry, true ); |
| 506 | 580 | } |
| 507 | 581 | |
| 508 | - if ( empty( $entry ) || ( $entry->is_draft && $event != 'draft' ) ) { | |
| 582 | + if ( empty( $entry ) || ( FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $entry->is_draft && 'draft' !== $event ) ) { | |
| 509 | 583 | continue; |
| 510 | 584 | } |
| 511 | 585 | |
| 512 | - $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'] ) ); | |
| 586 | + $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'] ); | |
| 513 | 587 | |
| 514 | 588 | if ( $child_entry ) { |
| 515 | 589 | // maybe trigger actions for sub forms |
| 516 | 590 | $trigger_children = apply_filters( 'frm_use_embedded_form_actions', false, compact( 'form', 'entry' ) ); |
| @@ -529,9 +603,9 @@ | ||
| 529 | 603 | $stored_actions[ $action->ID ] = $action; |
| 530 | 604 | $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority']; |
| 531 | 605 | |
| 532 | 606 | unset( $action ); |
| 533 | - } | |
| 607 | + }//end foreach | |
| 534 | 608 | |
| 535 | 609 | if ( ! empty( $stored_actions ) ) { |
| 536 | 610 | asort( $action_priority ); |
| 537 | 611 | |
| @@ -539,25 +613,42 @@ | ||
| 539 | 613 | new FrmNotification(); |
| 540 | 614 | |
| 541 | 615 | foreach ( $action_priority as $action_id => $priority ) { |
| 542 | 616 | $action = $stored_actions[ $action_id ]; |
| 543 | - do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event ); | |
| 544 | - do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form ); | |
| 545 | 617 | |
| 618 | + /** | |
| 619 | + * Allows custom form action trigger. | |
| 620 | + * | |
| 621 | + * @since 6.10 | |
| 622 | + * | |
| 623 | + * @param bool $skip Skip default trigger. | |
| 624 | + * @param object $action Action object. | |
| 625 | + * @param object $entry Entry object. | |
| 626 | + * @param object $form Form object. | |
| 627 | + * @param string $event Event ('create' or 'update'). | |
| 628 | + */ | |
| 629 | + if ( false === apply_filters( 'frm_custom_trigger_action', false, $action, $entry, $form, $event ) ) { | |
| 630 | + do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event ); | |
| 631 | + do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form ); | |
| 632 | + } | |
| 633 | + | |
| 546 | 634 | // If post is created, get updated $entry object. |
| 547 | - if ( $action->post_excerpt == 'wppost' && $event == 'create' ) { | |
| 635 | + if ( $action->post_excerpt === 'wppost' && $event === 'create' ) { | |
| 548 | 636 | $entry = FrmEntry::getOne( $entry->id, true ); |
| 549 | 637 | } |
| 550 | - } | |
| 551 | - } | |
| 638 | + }//end foreach | |
| 639 | + }//end if | |
| 552 | 640 | } |
| 553 | 641 | |
| 554 | 642 | public static function duplicate_form_actions( $form_id, $values, $args = array() ) { |
| 555 | - if ( ! isset( $args['old_id'] ) || empty( $args['old_id'] ) ) { | |
| 643 | + if ( empty( $args['old_id'] ) ) { | |
| 556 | 644 | // Continue if we know which actions to copy. |
| 557 | 645 | return; |
| 558 | 646 | } |
| 559 | 647 | |
| 648 | + /** | |
| 649 | + * @var array | |
| 650 | + */ | |
| 560 | 651 | $action_controls = self::get_form_actions(); |
| 561 | 652 | |
| 562 | 653 | foreach ( $action_controls as $action_control ) { |
| 563 | 654 | $action_control->duplicate_form_actions( $form_id, $args['old_id'] ); |
| @@ -574,8 +665,24 @@ | ||
| 574 | 665 | |
| 575 | 666 | $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] ); |
| 576 | 667 | |
| 577 | 668 | return $where; |
| 669 | + } | |
| 670 | + | |
| 671 | + /** | |
| 672 | + * Prevent WPML from filtering form actions based on the active language. | |
| 673 | + * | |
| 674 | + * @since 6.20 | |
| 675 | + * | |
| 676 | + * @param bool|null $null | |
| 677 | + * @param string $post_type | |
| 678 | + * @return bool|null | |
| 679 | + */ | |
| 680 | + public static function prevent_wpml_translations( $null, $post_type ) { | |
| 681 | + if ( self::$action_post_type === $post_type ) { | |
| 682 | + return false; | |
| 683 | + } | |
| 684 | + return $null; | |
| 578 | 685 | } |
| 579 | 686 | } |
| 580 | 687 | |
| 581 | 688 | class Frm_Form_Action_Factory { |