| @@ -3,12 +3,8 @@ | ||
| 3 | 3 | die( 'You are not allowed to call this page directly.' ); |
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmFormActionsController { |
| 7 | - | |
| 8 | - /** | |
| 9 | - * @var string | |
| 10 | - */ | |
| 11 | 7 | public static $action_post_type = 'frm_form_actions'; |
| 12 | 8 | |
| 13 | 9 | /** |
| 14 | 10 | * @var array|null |
| @@ -67,9 +63,8 @@ | ||
| 67 | 63 | 'constantcontact' => 'FrmDefConstContactAction', |
| 68 | 64 | 'getresponse' => 'FrmDefGetResponseAction', |
| 69 | 65 | 'hubspot' => 'FrmDefHubspotAction', |
| 70 | 66 | 'zapier' => 'FrmDefZapierAction', |
| 71 | - 'n8n' => 'FrmDefN8NAction', | |
| 72 | 67 | 'twilio' => 'FrmDefTwilioAction', |
| 73 | 68 | 'highrise' => 'FrmDefHighriseAction', |
| 74 | 69 | 'mailpoet' => 'FrmDefMailpoetAction', |
| 75 | 70 | 'aweber' => 'FrmDefAweberAction', |
| @@ -76,12 +71,8 @@ | ||
| 76 | 71 | 'convertkit' => 'FrmDefConvertKitAction', |
| 77 | 72 | 'googlespreadsheet' => 'FrmDefGoogleSpreadsheetAction', |
| 78 | 73 | ); |
| 79 | 74 | |
| 80 | - if ( ! FrmAppHelper::show_new_feature( 'n8n' ) ) { | |
| 81 | - unset( $action_classes['n8n'] ); | |
| 82 | - } | |
| 83 | - | |
| 84 | 75 | $action_classes = apply_filters( 'frm_registered_form_actions', $action_classes ); |
| 85 | 76 | $action_classes = self::maybe_unset_highrise( $action_classes ); |
| 86 | 77 | |
| 87 | 78 | include_once FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php'; |
| @@ -97,9 +88,8 @@ | ||
| 97 | 88 | * |
| 98 | 89 | * @since 6.23 |
| 99 | 90 | * |
| 100 | 91 | * @param array $action_classes |
| 101 | - * | |
| 102 | 92 | * @return array |
| 103 | 93 | */ |
| 104 | 94 | private static function maybe_unset_highrise( $action_classes ) { |
| 105 | 95 | if ( 'FrmDefHighriseAction' === ( $action_classes['highrise'] ?? '' ) ) { |
| @@ -128,17 +118,11 @@ | ||
| 128 | 118 | /** |
| 129 | 119 | * Add unknown actions to a group. |
| 130 | 120 | * |
| 131 | 121 | * @since 4.0 |
| 132 | - * | |
| 133 | - * @param array $action_controls | |
| 134 | - * @param array $groups | |
| 135 | - * | |
| 136 | - * @return void | |
| 137 | 122 | */ |
| 138 | 123 | private static function maybe_add_action_to_group( $action_controls, &$groups ) { |
| 139 | 124 | $grouped = array(); |
| 140 | - | |
| 141 | 125 | foreach ( $groups as $group ) { |
| 142 | 126 | if ( isset( $group['actions'] ) ) { |
| 143 | 127 | $grouped = array_merge( $grouped, $group['actions'] ); |
| 144 | 128 | } |
| @@ -149,9 +133,8 @@ | ||
| 149 | 133 | continue; |
| 150 | 134 | } |
| 151 | 135 | |
| 152 | 136 | $this_group = $action->action_options['group']; |
| 153 | - | |
| 154 | 137 | if ( ! isset( $groups[ $this_group ] ) ) { |
| 155 | 138 | $this_group = 'misc'; |
| 156 | 139 | } |
| 157 | 140 | |
| @@ -200,9 +183,8 @@ | ||
| 200 | 183 | 'constantcontact', |
| 201 | 184 | 'getresponse', |
| 202 | 185 | 'aweber', |
| 203 | 186 | 'mailpoet', |
| 204 | - 'convertkit', | |
| 205 | 187 | ), |
| 206 | 188 | ), |
| 207 | 189 | 'crm' => array( |
| 208 | 190 | 'name' => __( 'CRM', 'formidable' ), |
| @@ -240,15 +222,12 @@ | ||
| 240 | 222 | * Get the number of currently active form actions. |
| 241 | 223 | * |
| 242 | 224 | * @since 4.0 |
| 243 | 225 | * |
| 244 | - * @param array $action_controls | |
| 245 | - * | |
| 246 | 226 | * @return array |
| 247 | 227 | */ |
| 248 | 228 | private static function active_actions( $action_controls ) { |
| 249 | 229 | $allowed = array(); |
| 250 | - | |
| 251 | 230 | foreach ( $action_controls as $action_control ) { |
| 252 | 231 | if ( isset( $action_control->action_options['active'] ) && $action_control->action_options['active'] ) { |
| 253 | 232 | $allowed[] = $action_control->id_base; |
| 254 | 233 | } |
| @@ -259,9 +238,8 @@ | ||
| 259 | 238 | /** |
| 260 | 239 | * For each add-on, add an li, class, and javascript function. If active, add an additional class. |
| 261 | 240 | * |
| 262 | 241 | * @since 4.0 |
| 263 | - * | |
| 264 | 242 | * @param object $action_control |
| 265 | 243 | * @param array $allowed |
| 266 | 244 | */ |
| 267 | 245 | public static function show_action_icon_link( $action_control, $allowed ) { |
| @@ -281,9 +259,8 @@ | ||
| 281 | 259 | if ( isset( $action_control->action_options['active'] ) && $action_control->action_options['active'] ) { |
| 282 | 260 | $classes .= ' frm_active_action'; |
| 283 | 261 | } else { |
| 284 | 262 | $classes .= ' frm_inactive_action'; |
| 285 | - | |
| 286 | 263 | if ( $default_position !== false && ( $allowed_count + $default_position ) < 6 ) { |
| 287 | 264 | $group_class .= ' frm-default-show'; |
| 288 | 265 | } |
| 289 | 266 | |
| @@ -290,9 +267,8 @@ | ||
| 290 | 267 | $data['data-upgrade'] = $upgrade_label; |
| 291 | 268 | $data['data-medium'] = 'settings-' . $action_control->id_base; |
| 292 | 269 | |
| 293 | 270 | $upgrading = FrmAddonsController::install_link( $action_control->action_options['plugin'] ); |
| 294 | - | |
| 295 | 271 | if ( isset( $upgrading['url'] ) ) { |
| 296 | 272 | $data['data-oneclick'] = json_encode( $upgrading ); |
| 297 | 273 | } |
| 298 | 274 | |
| @@ -300,9 +276,8 @@ | ||
| 300 | 276 | $data['data-message'] = $action_control->action_options['message']; |
| 301 | 277 | } |
| 302 | 278 | |
| 303 | 279 | $requires = FrmFormsHelper::get_plan_required( $upgrading ); |
| 304 | - | |
| 305 | 280 | if ( $requires && 'free' !== $requires ) { |
| 306 | 281 | $data['data-requires'] = $requires; |
| 307 | 282 | } |
| 308 | 283 | }//end if |
| @@ -308,9 +283,8 @@ | ||
| 308 | 283 | }//end if |
| 309 | 284 | |
| 310 | 285 | // HTML to include on the icon. |
| 311 | 286 | $icon_atts = array(); |
| 312 | - | |
| 313 | 287 | if ( $action_control->action_options['color'] !== 'var(--primary-700)' ) { |
| 314 | 288 | $icon_atts = array( |
| 315 | 289 | 'style' => '--primary-700:' . $action_control->action_options['color'], |
| 316 | 290 | ); |
| @@ -320,14 +294,12 @@ | ||
| 320 | 294 | } |
| 321 | 295 | |
| 322 | 296 | /** |
| 323 | 297 | * @param string $action |
| 324 | - * | |
| 325 | 298 | * @return array|FrmFormAction A single form action is returned when a specific $action value is requested. |
| 326 | 299 | */ |
| 327 | 300 | public static function get_form_actions( $action = 'all' ) { |
| 328 | 301 | $temp_actions = self::$registered_actions; |
| 329 | - | |
| 330 | 302 | if ( empty( $temp_actions ) ) { |
| 331 | 303 | self::actions_init(); |
| 332 | 304 | $temp_actions = self::$registered_actions->actions; |
| 333 | 305 | } else { |
| @@ -348,13 +320,8 @@ | ||
| 348 | 320 | } |
| 349 | 321 | |
| 350 | 322 | /** |
| 351 | 323 | * @since 2.0 |
| 352 | - * | |
| 353 | - * @param object $form | |
| 354 | - * @param array $values | |
| 355 | - * | |
| 356 | - * @return void | |
| 357 | 324 | */ |
| 358 | 325 | public static function list_actions( $form, $values ) { |
| 359 | 326 | if ( empty( $form ) ) { |
| 360 | 327 | return; |
| @@ -402,20 +369,17 @@ | ||
| 402 | 369 | * @since 6.17 |
| 403 | 370 | * |
| 404 | 371 | * @param int|string $form_id |
| 405 | 372 | * @param array $form_actions |
| 406 | - * | |
| 407 | 373 | * @return void |
| 408 | 374 | */ |
| 409 | 375 | private static function maybe_show_limit_warning( $form_id, $form_actions ) { |
| 410 | 376 | $count = count( $form_actions ); |
| 411 | - | |
| 412 | 377 | if ( $count < 99 ) { |
| 413 | 378 | return; |
| 414 | 379 | } |
| 415 | 380 | |
| 416 | 381 | $limit = FrmFormAction::get_action_limit( $form_id ); |
| 417 | - | |
| 418 | 382 | if ( $limit < 99 || $count < $limit ) { |
| 419 | 383 | return; |
| 420 | 384 | } |
| 421 | 385 | |
| @@ -431,17 +395,8 @@ | ||
| 431 | 395 | ); |
| 432 | 396 | echo '</div>'; |
| 433 | 397 | } |
| 434 | 398 | |
| 435 | - /** | |
| 436 | - * @param WP_Post $form_action | |
| 437 | - * @param object $form | |
| 438 | - * @param int $action_key Action ID. | |
| 439 | - * @param FrmFormAction $action_control | |
| 440 | - * @param array $values | |
| 441 | - * | |
| 442 | - * @return void | |
| 443 | - */ | |
| 444 | 399 | public static function action_control( $form_action, $form, $action_key, $action_control, $values ) { |
| 445 | 400 | $action_control->_set( $action_key ); |
| 446 | 401 | |
| 447 | 402 | $use_logging = self::should_show_log_message( $form_action->post_excerpt ); |
| @@ -483,9 +438,8 @@ | ||
| 483 | 438 | $action_key = FrmAppHelper::get_param( 'action_id', '', 'post', 'absint' ); |
| 484 | 439 | $action_type = FrmAppHelper::get_param( 'action_type', '', 'post', 'sanitize_text_field' ); |
| 485 | 440 | |
| 486 | 441 | $action_control = self::get_form_actions( $action_type ); |
| 487 | - | |
| 488 | 442 | if ( empty( $action_control ) ) { |
| 489 | 443 | wp_die(); |
| 490 | 444 | } |
| 491 | 445 | |
| @@ -501,11 +455,8 @@ | ||
| 501 | 455 | } |
| 502 | 456 | |
| 503 | 457 | /** |
| 504 | 458 | * @since 3.06.04 |
| 505 | - * | |
| 506 | - * @param string $action_type | |
| 507 | - * | |
| 508 | 459 | * @return bool |
| 509 | 460 | */ |
| 510 | 461 | private static function should_show_log_message( $action_type ) { |
| 511 | 462 | $logging = array( 'api', 'salesforce', 'constantcontact', 'activecampaign' ); |
| @@ -511,14 +462,8 @@ | ||
| 511 | 462 | $logging = array( 'api', 'salesforce', 'constantcontact', 'activecampaign' ); |
| 512 | 463 | return in_array( $action_type, $logging, true ) && ! function_exists( 'frm_log_autoloader' ); |
| 513 | 464 | } |
| 514 | 465 | |
| 515 | - /** | |
| 516 | - * @param int|string $form_id | |
| 517 | - * @param array $values | |
| 518 | - * | |
| 519 | - * @return object | |
| 520 | - */ | |
| 521 | 466 | private static function fields_to_values( $form_id, array &$values ) { |
| 522 | 467 | $form = FrmForm::getOne( $form_id ); |
| 523 | 468 | |
| 524 | 469 | $values = array( |
| @@ -526,14 +471,12 @@ | ||
| 526 | 471 | 'id' => $form->id, |
| 527 | 472 | ); |
| 528 | 473 | |
| 529 | 474 | $fields = FrmField::get_all_for_form( $form->id ); |
| 530 | - | |
| 531 | 475 | foreach ( $fields as $k => $f ) { |
| 532 | 476 | $f = (array) $f; |
| 533 | 477 | $opts = (array) $f['field_options']; |
| 534 | 478 | $f = array_merge( $opts, $f ); |
| 535 | - | |
| 536 | 479 | if ( ! isset( $f['post_field'] ) ) { |
| 537 | 480 | $f['post_field'] = ''; |
| 538 | 481 | } |
| 539 | 482 | $values['fields'][] = $f; |
| @@ -544,15 +487,13 @@ | ||
| 544 | 487 | } |
| 545 | 488 | |
| 546 | 489 | /** |
| 547 | 490 | * @param int $form_id |
| 548 | - * | |
| 549 | 491 | * @return void |
| 550 | 492 | */ |
| 551 | 493 | public static function update_settings( $form_id ) { |
| 552 | 494 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 553 | 495 | $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' ); |
| 554 | - | |
| 555 | 496 | if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) { |
| 556 | 497 | $frm_settings = FrmAppHelper::get_settings(); |
| 557 | 498 | $error_args = array( |
| 558 | 499 | 'title' => __( 'Verification failed', 'formidable' ), |
| @@ -585,9 +526,8 @@ | ||
| 585 | 526 | $new_actions = array(); |
| 586 | 527 | |
| 587 | 528 | foreach ( $registered_actions as $registered_action ) { |
| 588 | 529 | $action_ids = $registered_action->update_callback( $form_id ); |
| 589 | - | |
| 590 | 530 | if ( ! empty( $action_ids ) ) { |
| 591 | 531 | $new_actions[] = $action_ids; |
| 592 | 532 | } |
| 593 | 533 | } |
| @@ -595,9 +535,8 @@ | ||
| 595 | 535 | // Only use array_merge if there are new actions. |
| 596 | 536 | if ( ! empty( $new_actions ) ) { |
| 597 | 537 | $new_actions = call_user_func_array( 'array_merge', $new_actions ); |
| 598 | 538 | } |
| 599 | - | |
| 600 | 539 | $old_actions = array_diff( $old_actions, $new_actions ); |
| 601 | 540 | |
| 602 | 541 | self::delete_missing_actions( $old_actions ); |
| 603 | 542 | |
| @@ -603,13 +542,8 @@ | ||
| 603 | 542 | |
| 604 | 543 | FrmOnSubmitHelper::save_on_submit_settings( $form_id ); |
| 605 | 544 | } |
| 606 | 545 | |
| 607 | - /** | |
| 608 | - * @param array $old_actions | |
| 609 | - * | |
| 610 | - * @return void | |
| 611 | - */ | |
| 612 | 546 | public static function delete_missing_actions( $old_actions ) { |
| 613 | 547 | if ( ! empty( $old_actions ) ) { |
| 614 | 548 | foreach ( $old_actions as $old_id ) { |
| 615 | 549 | wp_delete_post( $old_id ); |
| @@ -617,15 +551,8 @@ | ||
| 617 | 551 | FrmDb::cache_delete_group( 'frm_actions' ); |
| 618 | 552 | } |
| 619 | 553 | } |
| 620 | 554 | |
| 621 | - /** | |
| 622 | - * @param int|string $entry_id | |
| 623 | - * @param int|string $form_id | |
| 624 | - * @param array $args | |
| 625 | - * | |
| 626 | - * @return void | |
| 627 | - */ | |
| 628 | 555 | public static function trigger_create_actions( $entry_id, $form_id, $args = array() ) { |
| 629 | 556 | $filter_args = $args; |
| 630 | 557 | $filter_args['entry_id'] = $entry_id; |
| 631 | 558 | $filter_args['form_id'] = $form_id; |
| @@ -642,15 +569,9 @@ | ||
| 642 | 569 | self::trigger_actions( $event, $form_id, $entry_id, 'all', $args ); |
| 643 | 570 | } |
| 644 | 571 | |
| 645 | 572 | /** |
| 646 | - * @param string $event | |
| 647 | - * @param int|object|string $form | |
| 648 | - * @param int|string $entry | |
| 649 | - * @param string $type | |
| 650 | - * @param array $args | |
| 651 | - * | |
| 652 | - * @return void | |
| 573 | + * @param string $event | |
| 653 | 574 | */ |
| 654 | 575 | public static function trigger_actions( $event, $form, $entry, $type = 'all', $args = array() ) { |
| 655 | 576 | $action_status = array( |
| 656 | 577 | 'post_status' => 'publish', |
| @@ -661,15 +582,13 @@ | ||
| 661 | 582 | return; |
| 662 | 583 | } |
| 663 | 584 | |
| 664 | 585 | FrmForm::maybe_get_form( $form ); |
| 665 | - | |
| 666 | 586 | if ( ! is_object( $form ) ) { |
| 667 | 587 | return; |
| 668 | 588 | } |
| 669 | 589 | |
| 670 | 590 | $link_settings = self::get_form_actions( $type ); |
| 671 | - | |
| 672 | 591 | if ( 'all' !== $type ) { |
| 673 | 592 | $link_settings = array( $type => $link_settings ); |
| 674 | 593 | } |
| 675 | 594 | |
| @@ -685,9 +604,8 @@ | ||
| 685 | 604 | foreach ( $form_actions as $action ) { |
| 686 | 605 | |
| 687 | 606 | $skip_this_action = ! in_array( $this_event, $action->post_content['event'], true ) || FrmOnSubmitAction::$slug === $action->post_excerpt; |
| 688 | 607 | $skip_this_action = apply_filters( 'frm_skip_form_action', $skip_this_action, compact( 'action', 'entry', 'form', 'event' ) ); |
| 689 | - | |
| 690 | 608 | if ( $skip_this_action ) { |
| 691 | 609 | continue; |
| 692 | 610 | } |
| 693 | 611 | |
| @@ -703,9 +621,8 @@ | ||
| 703 | 621 | |
| 704 | 622 | if ( $child_entry ) { |
| 705 | 623 | // maybe trigger actions for sub forms |
| 706 | 624 | $trigger_children = apply_filters( 'frm_use_embedded_form_actions', false, compact( 'form', 'entry' ) ); |
| 707 | - | |
| 708 | 625 | if ( ! $trigger_children ) { |
| 709 | 626 | continue; |
| 710 | 627 | } |
| 711 | 628 | } |
| @@ -711,9 +628,8 @@ | ||
| 711 | 628 | } |
| 712 | 629 | |
| 713 | 630 | // Check conditional logic. |
| 714 | 631 | $stop = FrmFormAction::action_conditions_met( $action, $entry ); |
| 715 | - | |
| 716 | 632 | if ( $stop ) { |
| 717 | 633 | continue; |
| 718 | 634 | } |
| 719 | 635 | |
| @@ -756,15 +672,8 @@ | ||
| 756 | 672 | }//end foreach |
| 757 | 673 | }//end if |
| 758 | 674 | } |
| 759 | 675 | |
| 760 | - /** | |
| 761 | - * @param int|string $form_id | |
| 762 | - * @param array $values | |
| 763 | - * @param array $args | |
| 764 | - * | |
| 765 | - * @return void | |
| 766 | - */ | |
| 767 | 676 | public static function duplicate_form_actions( $form_id, $values, $args = array() ) { |
| 768 | 677 | if ( empty( $args['old_id'] ) ) { |
| 769 | 678 | // Continue if we know which actions to copy. |
| 770 | 679 | return; |
| @@ -780,13 +689,8 @@ | ||
| 780 | 689 | unset( $action_control ); |
| 781 | 690 | } |
| 782 | 691 | } |
| 783 | 692 | |
| 784 | - /** | |
| 785 | - * @param string $where | |
| 786 | - * | |
| 787 | - * @return string | |
| 788 | - */ | |
| 789 | 693 | public static function limit_by_type( $where ) { |
| 790 | 694 | global $frm_vars, $wpdb; |
| 791 | 695 | |
| 792 | 696 | if ( ! isset( $frm_vars['action_type'] ) ) { |
| @@ -804,9 +708,8 @@ | ||
| 804 | 708 | * @since 6.20 |
| 805 | 709 | * |
| 806 | 710 | * @param bool|null $null |
| 807 | 711 | * @param string $post_type |
| 808 | - * | |
| 809 | 712 | * @return bool|null |
| 810 | 713 | */ |
| 811 | 714 | public static function prevent_wpml_translations( $null, $post_type ) { |
| 812 | 715 | if ( self::$action_post_type === $post_type ) { |
| @@ -816,12 +719,8 @@ | ||
| 816 | 719 | } |
| 817 | 720 | } |
| 818 | 721 | |
| 819 | 722 | class Frm_Form_Action_Factory { |
| 820 | - | |
| 821 | - /** | |
| 822 | - * @var array | |
| 823 | - */ | |
| 824 | 723 | public $actions = array(); |
| 825 | 724 | |
| 826 | 725 | public function __construct() { |
| 827 | 726 | add_action( 'frm_form_actions_init', array( $this, '_register_actions' ), 100 ); |
| @@ -826,22 +725,12 @@ | ||
| 826 | 725 | public function __construct() { |
| 827 | 726 | add_action( 'frm_form_actions_init', array( $this, '_register_actions' ), 100 ); |
| 828 | 727 | } |
| 829 | 728 | |
| 830 | - /** | |
| 831 | - * @param string $action_class | |
| 832 | - * | |
| 833 | - * @return void | |
| 834 | - */ | |
| 835 | 729 | public function register( $action_class ) { |
| 836 | 730 | $this->actions[ $action_class ] = new $action_class(); |
| 837 | 731 | } |
| 838 | 732 | |
| 839 | - /** | |
| 840 | - * @param string $action_class | |
| 841 | - * | |
| 842 | - * @return void | |
| 843 | - */ | |
| 844 | 733 | public function unregister( $action_class ) { |
| 845 | 734 | if ( isset( $this->actions[ $action_class ] ) ) { |
| 846 | 735 | unset( $this->actions[ $action_class ] ); |
| 847 | 736 | } |