| @@ -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 | |
| @@ -330,8 +342,11 @@ | ||
| 330 | 342 | |
| 331 | 343 | $action_key = FrmAppHelper::get_param( 'list_id', '', 'post', 'absint' ); |
| 332 | 344 | $action_type = FrmAppHelper::get_param( 'type', '', 'post', 'sanitize_text_field' ); |
| 333 | 345 | |
| 346 | + /** | |
| 347 | + * @var FrmFormAction | |
| 348 | + */ | |
| 334 | 349 | $action_control = self::get_form_actions( $action_type ); |
| 335 | 350 | $action_control->_set( $action_key ); |
| 336 | 351 | |
| 337 | 352 | $form_id = FrmAppHelper::get_param( 'form_id', '', 'post', 'absint' ); |
| @@ -374,9 +389,9 @@ | ||
| 374 | 389 | * @return bool |
| 375 | 390 | */ |
| 376 | 391 | private static function should_show_log_message( $action_type ) { |
| 377 | 392 | $logging = array( 'api', 'salesforce', 'constantcontact', 'activecampaign' ); |
| 378 | - return in_array( $action_type, $logging ) && ! function_exists( 'frm_log_autoloader' ); | |
| 393 | + return in_array( $action_type, $logging, true ) && ! function_exists( 'frm_log_autoloader' ); | |
| 379 | 394 | } |
| 380 | 395 | |
| 381 | 396 | private static function fields_to_values( $form_id, array &$values ) { |
| 382 | 397 | $form = FrmForm::getOne( $form_id ); |
| @@ -409,9 +424,22 @@ | ||
| 409 | 424 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 410 | 425 | $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' ); |
| 411 | 426 | if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) { |
| 412 | 427 | $frm_settings = FrmAppHelper::get_settings(); |
| 413 | - wp_die( esc_html( $frm_settings->admin_permission ) ); | |
| 428 | + $error_args = array( | |
| 429 | + 'title' => __( 'Verification failed', 'formidable' ), | |
| 430 | + 'body' => $frm_settings->admin_permission, | |
| 431 | + 'cancel_url' => add_query_arg( | |
| 432 | + array( | |
| 433 | + 'page' => 'formidable', | |
| 434 | + 'frm_action' => 'settings', | |
| 435 | + 'id' => $form_id, | |
| 436 | + ), | |
| 437 | + admin_url( 'admin.php?' ) | |
| 438 | + ), | |
| 439 | + ); | |
| 440 | + FrmAppController::show_error_modal( $error_args ); | |
| 441 | + return; | |
| 414 | 442 | } |
| 415 | 443 | |
| 416 | 444 | global $wpdb; |
| 417 | 445 | |
| @@ -458,9 +486,16 @@ | ||
| 458 | 486 | $filter_args = $args; |
| 459 | 487 | $filter_args['entry_id'] = $entry_id; |
| 460 | 488 | $filter_args['form_id'] = $form_id; |
| 461 | 489 | |
| 462 | - $event = apply_filters( 'frm_trigger_create_action', 'create', $args ); | |
| 490 | + /** | |
| 491 | + * @since 2.0.23 | |
| 492 | + * @since 6.11.2 $filter_args is now passed instead of $args. It includes additional ID data. | |
| 493 | + * | |
| 494 | + * @param string $event 'create' by default. Pro may filter this value to 'draft' instead. | |
| 495 | + * @param array $filter_args | |
| 496 | + */ | |
| 497 | + $event = apply_filters( 'frm_trigger_create_action', 'create', $filter_args ); | |
| 463 | 498 | |
| 464 | 499 | self::trigger_actions( $event, $form_id, $entry_id, 'all', $args ); |
| 465 | 500 | } |
| 466 | 501 | |
| @@ -479,9 +514,9 @@ | ||
| 479 | 514 | |
| 480 | 515 | FrmForm::maybe_get_form( $form ); |
| 481 | 516 | |
| 482 | 517 | $link_settings = self::get_form_actions( $type ); |
| 483 | - if ( 'all' != $type ) { | |
| 518 | + if ( 'all' !== $type ) { | |
| 484 | 519 | $link_settings = array( $type => $link_settings ); |
| 485 | 520 | } |
| 486 | 521 | |
| 487 | 522 | $stored_actions = array(); |
| @@ -486,9 +521,9 @@ | ||
| 486 | 521 | |
| 487 | 522 | $stored_actions = array(); |
| 488 | 523 | $action_priority = array(); |
| 489 | 524 | |
| 490 | - if ( in_array( $event, array( 'create', 'update' ) ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { | |
| 525 | + if ( in_array( $event, array( 'create', 'update' ), true ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { | |
| 491 | 526 | $this_event = 'import'; |
| 492 | 527 | } else { |
| 493 | 528 | $this_event = $event; |
| 494 | 529 | } |
| @@ -529,9 +564,9 @@ | ||
| 529 | 564 | $stored_actions[ $action->ID ] = $action; |
| 530 | 565 | $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority']; |
| 531 | 566 | |
| 532 | 567 | unset( $action ); |
| 533 | - } | |
| 568 | + }//end foreach | |
| 534 | 569 | |
| 535 | 570 | if ( ! empty( $stored_actions ) ) { |
| 536 | 571 | asort( $action_priority ); |
| 537 | 572 | |
| @@ -539,25 +574,42 @@ | ||
| 539 | 574 | new FrmNotification(); |
| 540 | 575 | |
| 541 | 576 | foreach ( $action_priority as $action_id => $priority ) { |
| 542 | 577 | $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 | 578 | |
| 579 | + /** | |
| 580 | + * Allows custom form action trigger. | |
| 581 | + * | |
| 582 | + * @since 6.10 | |
| 583 | + * | |
| 584 | + * @param bool $skip Skip default trigger. | |
| 585 | + * @param object $action Action object. | |
| 586 | + * @param object $entry Entry object. | |
| 587 | + * @param object $form Form object. | |
| 588 | + * @param string $event Event ('create' or 'update'). | |
| 589 | + */ | |
| 590 | + if ( false === apply_filters( 'frm_custom_trigger_action', false, $action, $entry, $form, $event ) ) { | |
| 591 | + do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event ); | |
| 592 | + do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form ); | |
| 593 | + } | |
| 594 | + | |
| 546 | 595 | // If post is created, get updated $entry object. |
| 547 | - if ( $action->post_excerpt == 'wppost' && $event == 'create' ) { | |
| 596 | + if ( $action->post_excerpt === 'wppost' && $event === 'create' ) { | |
| 548 | 597 | $entry = FrmEntry::getOne( $entry->id, true ); |
| 549 | 598 | } |
| 550 | - } | |
| 551 | - } | |
| 599 | + }//end foreach | |
| 600 | + }//end if | |
| 552 | 601 | } |
| 553 | 602 | |
| 554 | 603 | public static function duplicate_form_actions( $form_id, $values, $args = array() ) { |
| 555 | - if ( ! isset( $args['old_id'] ) || empty( $args['old_id'] ) ) { | |
| 604 | + if ( empty( $args['old_id'] ) ) { | |
| 556 | 605 | // Continue if we know which actions to copy. |
| 557 | 606 | return; |
| 558 | 607 | } |
| 559 | 608 | |
| 609 | + /** | |
| 610 | + * @var array | |
| 611 | + */ | |
| 560 | 612 | $action_controls = self::get_form_actions(); |
| 561 | 613 | |
| 562 | 614 | foreach ( $action_controls as $action_control ) { |
| 563 | 615 | $action_control->duplicate_form_actions( $form_id, $args['old_id'] ); |