| @@ -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,12 +67,14 @@ | ||
| 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 ); |
| 76 | + $action_classes = self::maybe_unset_highrise( $action_classes ); | |
| 71 | 77 | |
| 72 | 78 | include_once FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php'; |
| 73 | 79 | include_once FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php'; |
| 74 | 80 | |
| @@ -77,8 +83,23 @@ | ||
| 77 | 83 | } |
| 78 | 84 | } |
| 79 | 85 | |
| 80 | 86 | /** |
| 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 | + /** | |
| 81 | 102 | * @since 4.0 |
| 82 | 103 | * |
| 83 | 104 | * @param array $values |
| 84 | 105 | */ |
| @@ -167,13 +188,9 @@ | ||
| 167 | 188 | ), |
| 168 | 189 | 'crm' => array( |
| 169 | 190 | 'name' => __( 'CRM', 'formidable' ), |
| 170 | 191 | 'icon' => 'frm_icon_font frm_address_card_icon', |
| 171 | - 'actions' => array( | |
| 172 | - 'salesforce', | |
| 173 | - 'hubspot', | |
| 174 | - 'highrise', | |
| 175 | - ), | |
| 192 | + 'actions' => self::get_crm_actions(), | |
| 176 | 193 | ), |
| 177 | 194 | ); |
| 178 | 195 | |
| 179 | 196 | return apply_filters( 'frm_action_groups', $groups ); |
| @@ -179,8 +196,30 @@ | ||
| 179 | 196 | return apply_filters( 'frm_action_groups', $groups ); |
| 180 | 197 | } |
| 181 | 198 | |
| 182 | 199 | /** |
| 200 | + * Get the actions to include in the CRM section. | |
| 201 | + * | |
| 202 | + * @since 6.23 | |
| 203 | + * | |
| 204 | + * @return array | |
| 205 | + */ | |
| 206 | + private static function get_crm_actions() { | |
| 207 | + $crm_actions = array( | |
| 208 | + 'salesforce', | |
| 209 | + 'hubspot', | |
| 210 | + ); | |
| 211 | + | |
| 212 | + // Only include Highrise when the add-on is active. | |
| 213 | + // This is because Highrise is deprecated. We don't want to show it in Lite. | |
| 214 | + if ( class_exists( 'FrmHrsSettings' ) ) { | |
| 215 | + $crm_actions[] = 'highrise'; | |
| 216 | + } | |
| 217 | + | |
| 218 | + return $crm_actions; | |
| 219 | + } | |
| 220 | + | |
| 221 | + /** | |
| 183 | 222 | * Get the number of currently active form actions. |
| 184 | 223 | * |
| 185 | 224 | * @since 4.0 |
| 186 | 225 | * |
| @@ -240,9 +279,9 @@ | ||
| 240 | 279 | $requires = FrmFormsHelper::get_plan_required( $upgrading ); |
| 241 | 280 | if ( $requires && 'free' !== $requires ) { |
| 242 | 281 | $data['data-requires'] = $requires; |
| 243 | 282 | } |
| 244 | - } | |
| 283 | + }//end if | |
| 245 | 284 | |
| 246 | 285 | // HTML to include on the icon. |
| 247 | 286 | $icon_atts = array(); |
| 248 | 287 | if ( $action_control->action_options['color'] !== 'var(--primary-700)' ) { |
| @@ -253,8 +292,12 @@ | ||
| 253 | 292 | |
| 254 | 293 | include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_icon.php'; |
| 255 | 294 | } |
| 256 | 295 | |
| 296 | + /** | |
| 297 | + * @param string $action | |
| 298 | + * @return array|FrmFormAction A single form action is returned when a specific $action value is requested. | |
| 299 | + */ | |
| 257 | 300 | public static function get_form_actions( $action = 'all' ) { |
| 258 | 301 | $temp_actions = self::$registered_actions; |
| 259 | 302 | if ( empty( $temp_actions ) ) { |
| 260 | 303 | self::actions_init(); |
| @@ -265,9 +308,9 @@ | ||
| 265 | 308 | |
| 266 | 309 | $actions = array(); |
| 267 | 310 | |
| 268 | 311 | foreach ( $temp_actions as $a ) { |
| 269 | - if ( 'all' != $action && $a->id_base == $action ) { | |
| 312 | + if ( 'all' !== $action && $a->id_base == $action ) { | |
| 270 | 313 | return $a; |
| 271 | 314 | } |
| 272 | 315 | |
| 273 | 316 | $actions[ $a->id_base ] = $a; |
| @@ -295,8 +338,11 @@ | ||
| 295 | 338 | 'post_status' => 'all', |
| 296 | 339 | ); |
| 297 | 340 | $form_actions = FrmFormAction::get_action_for_form( $form->id, 'all', $filters ); |
| 298 | 341 | |
| 342 | + /** | |
| 343 | + * @var array | |
| 344 | + */ | |
| 299 | 345 | $action_controls = self::get_form_actions(); |
| 300 | 346 | |
| 301 | 347 | $action_map = array(); |
| 302 | 348 | |
| @@ -303,8 +349,10 @@ | ||
| 303 | 349 | foreach ( $action_controls as $key => $control ) { |
| 304 | 350 | $action_map[ $control->id_base ] = $key; |
| 305 | 351 | } |
| 306 | 352 | |
| 353 | + self::maybe_show_limit_warning( $form->id, $form_actions ); | |
| 354 | + | |
| 307 | 355 | foreach ( $form_actions as $action ) { |
| 308 | 356 | if ( ! isset( $action_map[ $action->post_excerpt ] ) ) { |
| 309 | 357 | // don't try and show settings if action no longer exists |
| 310 | 358 | continue; |
| @@ -313,8 +361,42 @@ | ||
| 313 | 361 | self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values ); |
| 314 | 362 | } |
| 315 | 363 | } |
| 316 | 364 | |
| 365 | + /** | |
| 366 | + * Show a warning before the form actions list if there are 99 actions, and the limit is set to 99. | |
| 367 | + * If it is filtered, the warning is still shown when applicable, just using the new limit. | |
| 368 | + * | |
| 369 | + * @since 6.17 | |
| 370 | + * | |
| 371 | + * @param int|string $form_id | |
| 372 | + * @param array $form_actions | |
| 373 | + * @return void | |
| 374 | + */ | |
| 375 | + private static function maybe_show_limit_warning( $form_id, $form_actions ) { | |
| 376 | + $count = count( $form_actions ); | |
| 377 | + if ( $count < 99 ) { | |
| 378 | + return; | |
| 379 | + } | |
| 380 | + | |
| 381 | + $limit = FrmFormAction::get_action_limit( $form_id ); | |
| 382 | + if ( $limit < 99 || $count < $limit ) { | |
| 383 | + return; | |
| 384 | + } | |
| 385 | + | |
| 386 | + $documentation_url = 'https://formidableforms.com/knowledgebase/frm_form_action_limit/#kb-increase-limit-of-form-actions'; | |
| 387 | + | |
| 388 | + echo '<div class="frm_warning_style">'; | |
| 389 | + FrmAppHelper::icon_by_class( 'frm_icon_font frm_alert_icon' ); | |
| 390 | + echo ' '; | |
| 391 | + printf( | |
| 392 | + // translators: %s: URL to documentation | |
| 393 | + esc_html__( 'You have reached your form action limit. To increase this limit, you will require additional code. Visit our documentation at %s.', 'formidable' ), | |
| 394 | + '<a href="' . esc_url( $documentation_url ) . '" target="_blank">' . esc_html( $documentation_url ) . '</a>' | |
| 395 | + ); | |
| 396 | + echo '</div>'; | |
| 397 | + } | |
| 398 | + | |
| 317 | 399 | public static function action_control( $form_action, $form, $action_key, $action_control, $values ) { |
| 318 | 400 | $action_control->_set( $action_key ); |
| 319 | 401 | |
| 320 | 402 | $use_logging = self::should_show_log_message( $form_action->post_excerpt ); |
| @@ -330,8 +412,11 @@ | ||
| 330 | 412 | |
| 331 | 413 | $action_key = FrmAppHelper::get_param( 'list_id', '', 'post', 'absint' ); |
| 332 | 414 | $action_type = FrmAppHelper::get_param( 'type', '', 'post', 'sanitize_text_field' ); |
| 333 | 415 | |
| 416 | + /** | |
| 417 | + * @var FrmFormAction | |
| 418 | + */ | |
| 334 | 419 | $action_control = self::get_form_actions( $action_type ); |
| 335 | 420 | $action_control->_set( $action_key ); |
| 336 | 421 | |
| 337 | 422 | $form_id = FrmAppHelper::get_param( 'form_id', '', 'post', 'absint' ); |
| @@ -374,9 +459,9 @@ | ||
| 374 | 459 | * @return bool |
| 375 | 460 | */ |
| 376 | 461 | private static function should_show_log_message( $action_type ) { |
| 377 | 462 | $logging = array( 'api', 'salesforce', 'constantcontact', 'activecampaign' ); |
| 378 | - return in_array( $action_type, $logging ) && ! function_exists( 'frm_log_autoloader' ); | |
| 463 | + return in_array( $action_type, $logging, true ) && ! function_exists( 'frm_log_autoloader' ); | |
| 379 | 464 | } |
| 380 | 465 | |
| 381 | 466 | private static function fields_to_values( $form_id, array &$values ) { |
| 382 | 467 | $form = FrmForm::getOne( $form_id ); |
| @@ -409,9 +494,22 @@ | ||
| 409 | 494 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 410 | 495 | $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' ); |
| 411 | 496 | if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) { |
| 412 | 497 | $frm_settings = FrmAppHelper::get_settings(); |
| 413 | - wp_die( esc_html( $frm_settings->admin_permission ) ); | |
| 498 | + $error_args = array( | |
| 499 | + 'title' => __( 'Verification failed', 'formidable' ), | |
| 500 | + 'body' => $frm_settings->admin_permission, | |
| 501 | + 'cancel_url' => add_query_arg( | |
| 502 | + array( | |
| 503 | + 'page' => 'formidable', | |
| 504 | + 'frm_action' => 'settings', | |
| 505 | + 'id' => $form_id, | |
| 506 | + ), | |
| 507 | + admin_url( 'admin.php?' ) | |
| 508 | + ), | |
| 509 | + ); | |
| 510 | + FrmAppController::show_error_modal( $error_args ); | |
| 511 | + return; | |
| 414 | 512 | } |
| 415 | 513 | |
| 416 | 514 | global $wpdb; |
| 417 | 515 | |
| @@ -458,9 +556,16 @@ | ||
| 458 | 556 | $filter_args = $args; |
| 459 | 557 | $filter_args['entry_id'] = $entry_id; |
| 460 | 558 | $filter_args['form_id'] = $form_id; |
| 461 | 559 | |
| 462 | - $event = apply_filters( 'frm_trigger_create_action', 'create', $args ); | |
| 560 | + /** | |
| 561 | + * @since 2.0.23 | |
| 562 | + * @since 6.11.2 $filter_args is now passed instead of $args. It includes additional ID data. | |
| 563 | + * | |
| 564 | + * @param string $event 'create' by default. Pro may filter this value to 'draft' instead. | |
| 565 | + * @param array $filter_args | |
| 566 | + */ | |
| 567 | + $event = apply_filters( 'frm_trigger_create_action', 'create', $filter_args ); | |
| 463 | 568 | |
| 464 | 569 | self::trigger_actions( $event, $form_id, $entry_id, 'all', $args ); |
| 465 | 570 | } |
| 466 | 571 | |
| @@ -477,11 +582,14 @@ | ||
| 477 | 582 | return; |
| 478 | 583 | } |
| 479 | 584 | |
| 480 | 585 | FrmForm::maybe_get_form( $form ); |
| 586 | + if ( ! is_object( $form ) ) { | |
| 587 | + return; | |
| 588 | + } | |
| 481 | 589 | |
| 482 | 590 | $link_settings = self::get_form_actions( $type ); |
| 483 | - if ( 'all' != $type ) { | |
| 591 | + if ( 'all' !== $type ) { | |
| 484 | 592 | $link_settings = array( $type => $link_settings ); |
| 485 | 593 | } |
| 486 | 594 | |
| 487 | 595 | $stored_actions = array(); |
| @@ -486,9 +594,9 @@ | ||
| 486 | 594 | |
| 487 | 595 | $stored_actions = array(); |
| 488 | 596 | $action_priority = array(); |
| 489 | 597 | |
| 490 | - if ( in_array( $event, array( 'create', 'update' ) ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { | |
| 598 | + if ( in_array( $event, array( 'create', 'update' ), true ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { | |
| 491 | 599 | $this_event = 'import'; |
| 492 | 600 | } else { |
| 493 | 601 | $this_event = $event; |
| 494 | 602 | } |
| @@ -504,13 +612,13 @@ | ||
| 504 | 612 | if ( ! is_object( $entry ) ) { |
| 505 | 613 | $entry = FrmEntry::getOne( $entry, true ); |
| 506 | 614 | } |
| 507 | 615 | |
| 508 | - if ( empty( $entry ) || ( $entry->is_draft && $event != 'draft' ) ) { | |
| 616 | + if ( empty( $entry ) || ( FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $entry->is_draft && 'draft' !== $event ) ) { | |
| 509 | 617 | continue; |
| 510 | 618 | } |
| 511 | 619 | |
| 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'] ) ); | |
| 620 | + $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 | 621 | |
| 514 | 622 | if ( $child_entry ) { |
| 515 | 623 | // maybe trigger actions for sub forms |
| 516 | 624 | $trigger_children = apply_filters( 'frm_use_embedded_form_actions', false, compact( 'form', 'entry' ) ); |
| @@ -529,9 +637,9 @@ | ||
| 529 | 637 | $stored_actions[ $action->ID ] = $action; |
| 530 | 638 | $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority']; |
| 531 | 639 | |
| 532 | 640 | unset( $action ); |
| 533 | - } | |
| 641 | + }//end foreach | |
| 534 | 642 | |
| 535 | 643 | if ( ! empty( $stored_actions ) ) { |
| 536 | 644 | asort( $action_priority ); |
| 537 | 645 | |
| @@ -539,25 +647,42 @@ | ||
| 539 | 647 | new FrmNotification(); |
| 540 | 648 | |
| 541 | 649 | foreach ( $action_priority as $action_id => $priority ) { |
| 542 | 650 | $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 | 651 | |
| 652 | + /** | |
| 653 | + * Allows custom form action trigger. | |
| 654 | + * | |
| 655 | + * @since 6.10 | |
| 656 | + * | |
| 657 | + * @param bool $skip Skip default trigger. | |
| 658 | + * @param object $action Action object. | |
| 659 | + * @param object $entry Entry object. | |
| 660 | + * @param object $form Form object. | |
| 661 | + * @param string $event Event ('create' or 'update'). | |
| 662 | + */ | |
| 663 | + if ( false === apply_filters( 'frm_custom_trigger_action', false, $action, $entry, $form, $event ) ) { | |
| 664 | + do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event ); | |
| 665 | + do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form ); | |
| 666 | + } | |
| 667 | + | |
| 546 | 668 | // If post is created, get updated $entry object. |
| 547 | - if ( $action->post_excerpt == 'wppost' && $event == 'create' ) { | |
| 669 | + if ( $action->post_excerpt === 'wppost' && $event === 'create' ) { | |
| 548 | 670 | $entry = FrmEntry::getOne( $entry->id, true ); |
| 549 | 671 | } |
| 550 | - } | |
| 551 | - } | |
| 672 | + }//end foreach | |
| 673 | + }//end if | |
| 552 | 674 | } |
| 553 | 675 | |
| 554 | 676 | public static function duplicate_form_actions( $form_id, $values, $args = array() ) { |
| 555 | - if ( ! isset( $args['old_id'] ) || empty( $args['old_id'] ) ) { | |
| 677 | + if ( empty( $args['old_id'] ) ) { | |
| 556 | 678 | // Continue if we know which actions to copy. |
| 557 | 679 | return; |
| 558 | 680 | } |
| 559 | 681 | |
| 682 | + /** | |
| 683 | + * @var array | |
| 684 | + */ | |
| 560 | 685 | $action_controls = self::get_form_actions(); |
| 561 | 686 | |
| 562 | 687 | foreach ( $action_controls as $action_control ) { |
| 563 | 688 | $action_control->duplicate_form_actions( $form_id, $args['old_id'] ); |
| @@ -574,8 +699,24 @@ | ||
| 574 | 699 | |
| 575 | 700 | $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] ); |
| 576 | 701 | |
| 577 | 702 | return $where; |
| 703 | + } | |
| 704 | + | |
| 705 | + /** | |
| 706 | + * Prevent WPML from filtering form actions based on the active language. | |
| 707 | + * | |
| 708 | + * @since 6.20 | |
| 709 | + * | |
| 710 | + * @param bool|null $null | |
| 711 | + * @param string $post_type | |
| 712 | + * @return bool|null | |
| 713 | + */ | |
| 714 | + public static function prevent_wpml_translations( $null, $post_type ) { | |
| 715 | + if ( self::$action_post_type === $post_type ) { | |
| 716 | + return false; | |
| 717 | + } | |
| 718 | + return $null; | |
| 578 | 719 | } |
| 579 | 720 | } |
| 580 | 721 | |
| 581 | 722 | class Frm_Form_Action_Factory { |