← All changes
|
classes/controllers/FrmFormActionsController.php
+22
-164
6.25.1
→
6.2.2
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: |
| @@ -52,9 +48,9 @@ | ||
| 52 | 48 | 'email' => 'FrmEmailAction', |
| 53 | 49 | 'wppost' => 'FrmDefPostAction', |
| 54 | 50 | 'register' => 'FrmDefRegAction', |
| 55 | 51 | 'paypal' => 'FrmDefPayPalAction', |
| 56 | - 'payment' => 'FrmTransLiteAction', | |
| 52 | + 'payment' => 'FrmDefHrsAction', | |
| 57 | 53 | 'quiz' => 'FrmDefQuizAction', |
| 58 | 54 | 'quiz_outcome' => 'FrmDefQuizOutcomeAction', |
| 59 | 55 | 'mailchimp' => 'FrmDefMlcmpAction', |
| 60 | 56 | 'api' => 'FrmDefApiAction', |
| @@ -67,14 +63,12 @@ | ||
| 67 | 63 | 'twilio' => 'FrmDefTwilioAction', |
| 68 | 64 | 'highrise' => 'FrmDefHighriseAction', |
| 69 | 65 | 'mailpoet' => 'FrmDefMailpoetAction', |
| 70 | 66 | 'aweber' => 'FrmDefAweberAction', |
| 71 | - 'convertkit' => 'FrmDefConvertKitAction', | |
| 72 | 67 | 'googlespreadsheet' => 'FrmDefGoogleSpreadsheetAction', |
| 73 | 68 | ); |
| 74 | 69 | |
| 75 | 70 | $action_classes = apply_filters( 'frm_registered_form_actions', $action_classes ); |
| 76 | - $action_classes = self::maybe_unset_highrise( $action_classes ); | |
| 77 | 71 | |
| 78 | 72 | include_once FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php'; |
| 79 | 73 | include_once FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php'; |
| 80 | 74 | |
| @@ -83,23 +77,8 @@ | ||
| 83 | 77 | } |
| 84 | 78 | } |
| 85 | 79 | |
| 86 | 80 | /** |
| 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 | 81 | * @since 4.0 |
| 103 | 82 | * |
| 104 | 83 | * @param array $values |
| 105 | 84 | */ |
| @@ -183,15 +162,18 @@ | ||
| 183 | 162 | 'constantcontact', |
| 184 | 163 | 'getresponse', |
| 185 | 164 | 'aweber', |
| 186 | 165 | 'mailpoet', |
| 187 | - 'convertkit', | |
| 188 | 166 | ), |
| 189 | 167 | ), |
| 190 | 168 | 'crm' => array( |
| 191 | 169 | 'name' => __( 'CRM', 'formidable' ), |
| 192 | 170 | 'icon' => 'frm_icon_font frm_address_card_icon', |
| 193 | - 'actions' => self::get_crm_actions(), | |
| 171 | + 'actions' => array( | |
| 172 | + 'salesforce', | |
| 173 | + 'hubspot', | |
| 174 | + 'highrise', | |
| 175 | + ), | |
| 194 | 176 | ), |
| 195 | 177 | ); |
| 196 | 178 | |
| 197 | 179 | return apply_filters( 'frm_action_groups', $groups ); |
| @@ -197,30 +179,8 @@ | ||
| 197 | 179 | return apply_filters( 'frm_action_groups', $groups ); |
| 198 | 180 | } |
| 199 | 181 | |
| 200 | 182 | /** |
| 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 | 183 | * Get the number of currently active form actions. |
| 224 | 184 | * |
| 225 | 185 | * @since 4.0 |
| 226 | 186 | * |
| @@ -280,9 +240,9 @@ | ||
| 280 | 240 | $requires = FrmFormsHelper::get_plan_required( $upgrading ); |
| 281 | 241 | if ( $requires && 'free' !== $requires ) { |
| 282 | 242 | $data['data-requires'] = $requires; |
| 283 | 243 | } |
| 284 | - }//end if | |
| 244 | + } | |
| 285 | 245 | |
| 286 | 246 | // HTML to include on the icon. |
| 287 | 247 | $icon_atts = array(); |
| 288 | 248 | if ( $action_control->action_options['color'] !== 'var(--primary-700)' ) { |
| @@ -293,12 +253,8 @@ | ||
| 293 | 253 | |
| 294 | 254 | include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_icon.php'; |
| 295 | 255 | } |
| 296 | 256 | |
| 297 | - /** | |
| 298 | - * @param string $action | |
| 299 | - * @return array|FrmFormAction A single form action is returned when a specific $action value is requested. | |
| 300 | - */ | |
| 301 | 257 | public static function get_form_actions( $action = 'all' ) { |
| 302 | 258 | $temp_actions = self::$registered_actions; |
| 303 | 259 | if ( empty( $temp_actions ) ) { |
| 304 | 260 | self::actions_init(); |
| @@ -309,9 +265,9 @@ | ||
| 309 | 265 | |
| 310 | 266 | $actions = array(); |
| 311 | 267 | |
| 312 | 268 | foreach ( $temp_actions as $a ) { |
| 313 | - if ( 'all' !== $action && $a->id_base == $action ) { | |
| 269 | + if ( 'all' != $action && $a->id_base == $action ) { | |
| 314 | 270 | return $a; |
| 315 | 271 | } |
| 316 | 272 | |
| 317 | 273 | $actions[ $a->id_base ] = $a; |
| @@ -339,11 +295,8 @@ | ||
| 339 | 295 | 'post_status' => 'all', |
| 340 | 296 | ); |
| 341 | 297 | $form_actions = FrmFormAction::get_action_for_form( $form->id, 'all', $filters ); |
| 342 | 298 | |
| 343 | - /** | |
| 344 | - * @var array | |
| 345 | - */ | |
| 346 | 299 | $action_controls = self::get_form_actions(); |
| 347 | 300 | |
| 348 | 301 | $action_map = array(); |
| 349 | 302 | |
| @@ -350,10 +303,8 @@ | ||
| 350 | 303 | foreach ( $action_controls as $key => $control ) { |
| 351 | 304 | $action_map[ $control->id_base ] = $key; |
| 352 | 305 | } |
| 353 | 306 | |
| 354 | - self::maybe_show_limit_warning( $form->id, $form_actions ); | |
| 355 | - | |
| 356 | 307 | foreach ( $form_actions as $action ) { |
| 357 | 308 | if ( ! isset( $action_map[ $action->post_excerpt ] ) ) { |
| 358 | 309 | // don't try and show settings if action no longer exists |
| 359 | 310 | continue; |
| @@ -362,42 +313,8 @@ | ||
| 362 | 313 | self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values ); |
| 363 | 314 | } |
| 364 | 315 | } |
| 365 | 316 | |
| 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 ' '; | |
| 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 | 317 | public static function action_control( $form_action, $form, $action_key, $action_control, $values ) { |
| 401 | 318 | $action_control->_set( $action_key ); |
| 402 | 319 | |
| 403 | 320 | $use_logging = self::should_show_log_message( $form_action->post_excerpt ); |
| @@ -413,11 +330,8 @@ | ||
| 413 | 330 | |
| 414 | 331 | $action_key = FrmAppHelper::get_param( 'list_id', '', 'post', 'absint' ); |
| 415 | 332 | $action_type = FrmAppHelper::get_param( 'type', '', 'post', 'sanitize_text_field' ); |
| 416 | 333 | |
| 417 | - /** | |
| 418 | - * @var FrmFormAction | |
| 419 | - */ | |
| 420 | 334 | $action_control = self::get_form_actions( $action_type ); |
| 421 | 335 | $action_control->_set( $action_key ); |
| 422 | 336 | |
| 423 | 337 | $form_id = FrmAppHelper::get_param( 'form_id', '', 'post', 'absint' ); |
| @@ -460,9 +374,9 @@ | ||
| 460 | 374 | * @return bool |
| 461 | 375 | */ |
| 462 | 376 | private static function should_show_log_message( $action_type ) { |
| 463 | 377 | $logging = array( 'api', 'salesforce', 'constantcontact', 'activecampaign' ); |
| 464 | - return in_array( $action_type, $logging, true ) && ! function_exists( 'frm_log_autoloader' ); | |
| 378 | + return in_array( $action_type, $logging ) && ! function_exists( 'frm_log_autoloader' ); | |
| 465 | 379 | } |
| 466 | 380 | |
| 467 | 381 | private static function fields_to_values( $form_id, array &$values ) { |
| 468 | 382 | $form = FrmForm::getOne( $form_id ); |
| @@ -495,22 +409,9 @@ | ||
| 495 | 409 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 496 | 410 | $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' ); |
| 497 | 411 | if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) { |
| 498 | 412 | $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; | |
| 413 | + wp_die( esc_html( $frm_settings->admin_permission ) ); | |
| 513 | 414 | } |
| 514 | 415 | |
| 515 | 416 | global $wpdb; |
| 516 | 417 | |
| @@ -557,16 +458,9 @@ | ||
| 557 | 458 | $filter_args = $args; |
| 558 | 459 | $filter_args['entry_id'] = $entry_id; |
| 559 | 460 | $filter_args['form_id'] = $form_id; |
| 560 | 461 | |
| 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 ); | |
| 462 | + $event = apply_filters( 'frm_trigger_create_action', 'create', $args ); | |
| 569 | 463 | |
| 570 | 464 | self::trigger_actions( $event, $form_id, $entry_id, 'all', $args ); |
| 571 | 465 | } |
| 572 | 466 | |
| @@ -583,14 +477,11 @@ | ||
| 583 | 477 | return; |
| 584 | 478 | } |
| 585 | 479 | |
| 586 | 480 | FrmForm::maybe_get_form( $form ); |
| 587 | - if ( ! is_object( $form ) ) { | |
| 588 | - return; | |
| 589 | - } | |
| 590 | 481 | |
| 591 | 482 | $link_settings = self::get_form_actions( $type ); |
| 592 | - if ( 'all' !== $type ) { | |
| 483 | + if ( 'all' != $type ) { | |
| 593 | 484 | $link_settings = array( $type => $link_settings ); |
| 594 | 485 | } |
| 595 | 486 | |
| 596 | 487 | $stored_actions = array(); |
| @@ -595,9 +486,9 @@ | ||
| 595 | 486 | |
| 596 | 487 | $stored_actions = array(); |
| 597 | 488 | $action_priority = array(); |
| 598 | 489 | |
| 599 | - if ( in_array( $event, array( 'create', 'update' ), true ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { | |
| 490 | + if ( in_array( $event, array( 'create', 'update' ) ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { | |
| 600 | 491 | $this_event = 'import'; |
| 601 | 492 | } else { |
| 602 | 493 | $this_event = $event; |
| 603 | 494 | } |
| @@ -613,13 +504,13 @@ | ||
| 613 | 504 | if ( ! is_object( $entry ) ) { |
| 614 | 505 | $entry = FrmEntry::getOne( $entry, true ); |
| 615 | 506 | } |
| 616 | 507 | |
| 617 | - if ( empty( $entry ) || ( FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $entry->is_draft && 'draft' !== $event ) ) { | |
| 508 | + if ( empty( $entry ) || ( $entry->is_draft && $event != 'draft' ) ) { | |
| 618 | 509 | continue; |
| 619 | 510 | } |
| 620 | 511 | |
| 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'] ); | |
| 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'] ) ); | |
| 622 | 513 | |
| 623 | 514 | if ( $child_entry ) { |
| 624 | 515 | // maybe trigger actions for sub forms |
| 625 | 516 | $trigger_children = apply_filters( 'frm_use_embedded_form_actions', false, compact( 'form', 'entry' ) ); |
| @@ -638,9 +529,9 @@ | ||
| 638 | 529 | $stored_actions[ $action->ID ] = $action; |
| 639 | 530 | $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority']; |
| 640 | 531 | |
| 641 | 532 | unset( $action ); |
| 642 | - }//end foreach | |
| 533 | + } | |
| 643 | 534 | |
| 644 | 535 | if ( ! empty( $stored_actions ) ) { |
| 645 | 536 | asort( $action_priority ); |
| 646 | 537 | |
| @@ -648,42 +539,25 @@ | ||
| 648 | 539 | new FrmNotification(); |
| 649 | 540 | |
| 650 | 541 | foreach ( $action_priority as $action_id => $priority ) { |
| 651 | 542 | $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 ); | |
| 652 | 545 | |
| 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 | 546 | // If post is created, get updated $entry object. |
| 670 | - if ( $action->post_excerpt === 'wppost' && $event === 'create' ) { | |
| 547 | + if ( $action->post_excerpt == 'wppost' && $event == 'create' ) { | |
| 671 | 548 | $entry = FrmEntry::getOne( $entry->id, true ); |
| 672 | 549 | } |
| 673 | - }//end foreach | |
| 674 | - }//end if | |
| 550 | + } | |
| 551 | + } | |
| 675 | 552 | } |
| 676 | 553 | |
| 677 | 554 | public static function duplicate_form_actions( $form_id, $values, $args = array() ) { |
| 678 | - if ( empty( $args['old_id'] ) ) { | |
| 555 | + if ( ! isset( $args['old_id'] ) || empty( $args['old_id'] ) ) { | |
| 679 | 556 | // Continue if we know which actions to copy. |
| 680 | 557 | return; |
| 681 | 558 | } |
| 682 | 559 | |
| 683 | - /** | |
| 684 | - * @var array | |
| 685 | - */ | |
| 686 | 560 | $action_controls = self::get_form_actions(); |
| 687 | 561 | |
| 688 | 562 | foreach ( $action_controls as $action_control ) { |
| 689 | 563 | $action_control->duplicate_form_actions( $form_id, $args['old_id'] ); |
| @@ -700,24 +574,8 @@ | ||
| 700 | 574 | |
| 701 | 575 | $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] ); |
| 702 | 576 | |
| 703 | 577 | 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 | 578 | } |
| 721 | 579 | } |
| 722 | 580 | |
| 723 | 581 | class Frm_Form_Action_Factory { |