| @@ -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: |
| @@ -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 | * |
| @@ -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,12 +409,12 @@ | ||
| 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( | |
| 413 | + $error_args = array( | |
| 414 | + 'title' => __( 'Verification failed', 'formidable' ), | |
| 415 | + 'body' => $frm_settings->admin_permission, | |
| 416 | + 'cancel_url' => add_query_arg( | |
| 503 | 417 | array( |
| 504 | 418 | 'page' => 'formidable', |
| 505 | 419 | 'frm_action' => 'settings', |
| 506 | 420 | 'id' => $form_id, |
| @@ -557,16 +471,9 @@ | ||
| 557 | 471 | $filter_args = $args; |
| 558 | 472 | $filter_args['entry_id'] = $entry_id; |
| 559 | 473 | $filter_args['form_id'] = $form_id; |
| 560 | 474 | |
| 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 ); | |
| 475 | + $event = apply_filters( 'frm_trigger_create_action', 'create', $args ); | |
| 569 | 476 | |
| 570 | 477 | self::trigger_actions( $event, $form_id, $entry_id, 'all', $args ); |
| 571 | 478 | } |
| 572 | 479 | |
| @@ -583,14 +490,11 @@ | ||
| 583 | 490 | return; |
| 584 | 491 | } |
| 585 | 492 | |
| 586 | 493 | FrmForm::maybe_get_form( $form ); |
| 587 | - if ( ! is_object( $form ) ) { | |
| 588 | - return; | |
| 589 | - } | |
| 590 | 494 | |
| 591 | 495 | $link_settings = self::get_form_actions( $type ); |
| 592 | - if ( 'all' !== $type ) { | |
| 496 | + if ( 'all' != $type ) { | |
| 593 | 497 | $link_settings = array( $type => $link_settings ); |
| 594 | 498 | } |
| 595 | 499 | |
| 596 | 500 | $stored_actions = array(); |
| @@ -617,9 +521,9 @@ | ||
| 617 | 521 | if ( empty( $entry ) || ( FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $entry->is_draft && 'draft' !== $event ) ) { |
| 618 | 522 | continue; |
| 619 | 523 | } |
| 620 | 524 | |
| 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'] ); | |
| 525 | + $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 | 526 | |
| 623 | 527 | if ( $child_entry ) { |
| 624 | 528 | // maybe trigger actions for sub forms |
| 625 | 529 | $trigger_children = apply_filters( 'frm_use_embedded_form_actions', false, compact( 'form', 'entry' ) ); |
| @@ -648,31 +552,17 @@ | ||
| 648 | 552 | new FrmNotification(); |
| 649 | 553 | |
| 650 | 554 | foreach ( $action_priority as $action_id => $priority ) { |
| 651 | 555 | $action = $stored_actions[ $action_id ]; |
| 556 | + do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event ); | |
| 557 | + do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form ); | |
| 652 | 558 | |
| 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 | 559 | // If post is created, get updated $entry object. |
| 670 | 560 | if ( $action->post_excerpt === 'wppost' && $event === 'create' ) { |
| 671 | 561 | $entry = FrmEntry::getOne( $entry->id, true ); |
| 672 | 562 | } |
| 673 | - }//end foreach | |
| 674 | - }//end if | |
| 563 | + } | |
| 564 | + } | |
| 675 | 565 | } |
| 676 | 566 | |
| 677 | 567 | public static function duplicate_form_actions( $form_id, $values, $args = array() ) { |
| 678 | 568 | if ( empty( $args['old_id'] ) ) { |
| @@ -679,11 +569,8 @@ | ||
| 679 | 569 | // Continue if we know which actions to copy. |
| 680 | 570 | return; |
| 681 | 571 | } |
| 682 | 572 | |
| 683 | - /** | |
| 684 | - * @var array | |
| 685 | - */ | |
| 686 | 573 | $action_controls = self::get_form_actions(); |
| 687 | 574 | |
| 688 | 575 | foreach ( $action_controls as $action_control ) { |
| 689 | 576 | $action_control->duplicate_form_actions( $form_id, $args['old_id'] ); |
| @@ -700,24 +587,8 @@ | ||
| 700 | 587 | |
| 701 | 588 | $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] ); |
| 702 | 589 | |
| 703 | 590 | 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 | 591 | } |
| 721 | 592 | } |
| 722 | 593 | |
| 723 | 594 | class Frm_Form_Action_Factory { |