| @@ -156,9 +156,21 @@ | ||
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | public static function update_settings() { |
| 159 | 159 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 160 | + $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' ); | |
| 160 | 161 | |
| 162 | + if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) { | |
| 163 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 164 | + $error_args = array( | |
| 165 | + 'title' => __( 'Verification failed', 'formidable' ), | |
| 166 | + 'body' => $frm_settings->admin_permission, | |
| 167 | + 'cancel_text' => __( 'Cancel', 'formidable' ), | |
| 168 | + ); | |
| 169 | + FrmAppController::show_error_modal( $error_args ); | |
| 170 | + return; | |
| 171 | + } | |
| 172 | + | |
| 161 | 173 | $id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
| 162 | 174 | |
| 163 | 175 | $errors = FrmForm::validate( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 164 | 176 | $warnings = FrmFormsHelper::check_for_warnings( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| @@ -212,8 +224,10 @@ | ||
| 212 | 224 | |
| 213 | 225 | if ( count( $errors ) > 0 ) { |
| 214 | 226 | return self::get_edit_vars( $id, $errors ); |
| 215 | 227 | } else { |
| 228 | + self::maybe_remove_draft_option_from_fields( $id ); | |
| 229 | + | |
| 216 | 230 | FrmForm::update( $id, $values ); |
| 217 | 231 | $message = __( 'Form was successfully updated.', 'formidable' ); |
| 218 | 232 | |
| 219 | 233 | if ( self::is_too_long( $values ) ) { |
| @@ -229,9 +243,37 @@ | ||
| 229 | 243 | wp_die( FrmAppHelper::kses( $message, array( 'a' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 230 | 244 | } |
| 231 | 245 | |
| 232 | 246 | return self::get_edit_vars( $id, array(), $message ); |
| 247 | + }//end if | |
| 248 | + } | |
| 249 | + | |
| 250 | + /** | |
| 251 | + * Remove the draft flag from any new fields from this current session. | |
| 252 | + * | |
| 253 | + * @since 6.8 | |
| 254 | + * | |
| 255 | + * @param int $form_id | |
| 256 | + * @return void | |
| 257 | + */ | |
| 258 | + private static function maybe_remove_draft_option_from_fields( $form_id ) { | |
| 259 | + $draft_field_ids_csv = FrmAppHelper::get_post_param( 'draft_fields', '', 'sanitize_text_field' ); | |
| 260 | + if ( ! $draft_field_ids_csv ) { | |
| 261 | + // If the draft_fields input is empty there are no new fields in the session. | |
| 262 | + return; | |
| 233 | 263 | } |
| 264 | + | |
| 265 | + $draft_field_ids = array_filter( explode( ',', $draft_field_ids_csv ), 'is_numeric' ); | |
| 266 | + if ( ! $draft_field_ids ) { | |
| 267 | + // Exit early if the draft fields input is invalid. It should be a CSV of integer values. | |
| 268 | + return; | |
| 269 | + } | |
| 270 | + | |
| 271 | + $draft_field_rows = FrmFieldsHelper::get_draft_field_results( $form_id, $draft_field_ids ); | |
| 272 | + foreach ( $draft_field_rows as $row ) { | |
| 273 | + $row->field_options['draft'] = 0; | |
| 274 | + FrmField::update( $row->id, array( 'field_options' => $row->field_options ) ); | |
| 275 | + } | |
| 234 | 276 | } |
| 235 | 277 | |
| 236 | 278 | /** |
| 237 | 279 | * Check if the value at the end of the form was included. |
| @@ -282,9 +324,10 @@ | ||
| 282 | 324 | $url = admin_url( 'admin.php?page=formidable' ); |
| 283 | 325 | $message = 'form_duplicate_error'; |
| 284 | 326 | |
| 285 | 327 | if ( $form ) { |
| 286 | - $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) ); | |
| 328 | + $new_template = FrmAppHelper::simple_get( 'new_template' ) ? '&new_template=true' : ''; | |
| 329 | + $url = admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . absint( $form ) . $new_template ); | |
| 287 | 330 | $message = 'form_duplicated'; |
| 288 | 331 | } |
| 289 | 332 | |
| 290 | 333 | $url .= '&message=' . $message; |
| @@ -309,8 +352,10 @@ | ||
| 309 | 352 | } |
| 310 | 353 | |
| 311 | 354 | /** |
| 312 | 355 | * @since 3.0 |
| 356 | + * | |
| 357 | + * @return void | |
| 313 | 358 | */ |
| 314 | 359 | public static function show_page_preview() { |
| 315 | 360 | echo self::page_preview(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 316 | 361 | } |
| @@ -360,8 +405,13 @@ | ||
| 360 | 405 | return; |
| 361 | 406 | } |
| 362 | 407 | |
| 363 | 408 | $random_page = reset( $random_page ); |
| 409 | + if ( ! is_a( $random_page, 'WP_Post' ) ) { | |
| 410 | + // The return type can also be int. | |
| 411 | + return; | |
| 412 | + } | |
| 413 | + | |
| 364 | 414 | query_posts( |
| 365 | 415 | array( |
| 366 | 416 | 'post_type' => 'page', |
| 367 | 417 | 'page_id' => $random_page->ID, |
| @@ -377,9 +427,9 @@ | ||
| 377 | 427 | * Set the WP $post global object. Used for in-theme preview when defining a page. |
| 378 | 428 | * |
| 379 | 429 | * @since 5.5.2 |
| 380 | 430 | * |
| 381 | - * @param WP_Post $post | |
| 431 | + * @param WP_Post $page The page object. | |
| 382 | 432 | * @return void |
| 383 | 433 | */ |
| 384 | 434 | private static function set_post_global( $page ) { |
| 385 | 435 | global $post; |
| @@ -397,13 +447,29 @@ | ||
| 397 | 447 | add_filter( 'is_active_sidebar', '__return_false' ); |
| 398 | 448 | FrmStylesController::enqueue_css( 'enqueue', true ); |
| 399 | 449 | |
| 400 | 450 | if ( false === get_template_part( 'page' ) ) { |
| 451 | + if ( function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) { | |
| 452 | + add_filter( 'body_class', 'FrmFormsController::preview_block_theme_body_classnames' ); | |
| 453 | + } | |
| 401 | 454 | self::fallback_when_page_template_part_is_not_supported_by_theme(); |
| 402 | 455 | } |
| 403 | 456 | } |
| 404 | 457 | |
| 405 | 458 | /** |
| 459 | + * Add padding to the body for block themes. | |
| 460 | + * | |
| 461 | + * @since 6.5.2 | |
| 462 | + * | |
| 463 | + * @param array $classes The body classes list. | |
| 464 | + * @return array | |
| 465 | + */ | |
| 466 | + public static function preview_block_theme_body_classnames( $classes ) { | |
| 467 | + $classes[] = 'has-global-padding'; | |
| 468 | + return $classes; | |
| 469 | + } | |
| 470 | + | |
| 471 | + /** | |
| 406 | 472 | * Not every theme supports get_template_part( 'page' ). |
| 407 | 473 | * When this is not supported, false is returned, and we can handle a fallback. |
| 408 | 474 | */ |
| 409 | 475 | private static function fallback_when_page_template_part_is_not_supported_by_theme() { |
| @@ -408,9 +474,10 @@ | ||
| 408 | 474 | */ |
| 409 | 475 | private static function fallback_when_page_template_part_is_not_supported_by_theme() { |
| 410 | 476 | if ( have_posts() ) { |
| 411 | 477 | the_post(); |
| 412 | - get_header( '' ); | |
| 478 | + self::get_template( 'header' ); | |
| 479 | + | |
| 413 | 480 | // add some generic class names to the container to add some natural padding to the content. |
| 414 | 481 | // .entry-content catches the WordPress TwentyTwenty theme. |
| 415 | 482 | // .container catches Customizr content. |
| 416 | 483 | echo '<div class="container entry-content">'; |
| @@ -415,13 +482,54 @@ | ||
| 415 | 482 | // .container catches Customizr content. |
| 416 | 483 | echo '<div class="container entry-content">'; |
| 417 | 484 | the_content(); |
| 418 | 485 | echo '</div>'; |
| 419 | - get_footer(); | |
| 486 | + | |
| 487 | + self::get_template( 'footer' ); | |
| 420 | 488 | } |
| 421 | 489 | } |
| 422 | 490 | |
| 423 | 491 | /** |
| 492 | + * Calls core function to get a template part if it doesn't cause deprecation warnings. Otherwise skips the deprecation function call | |
| 493 | + * and renders required html fragements calling required functions. | |
| 494 | + * | |
| 495 | + * @since 6.7.1 | |
| 496 | + * @param string $template | |
| 497 | + * @return void | |
| 498 | + */ | |
| 499 | + private static function get_template( $template ) { | |
| 500 | + if ( self::should_try_getting_template( $template ) ) { | |
| 501 | + call_user_func( 'get_' . $template ); | |
| 502 | + return; | |
| 503 | + } | |
| 504 | + | |
| 505 | + if ( 'header' === $template ) { | |
| 506 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/header.php'; | |
| 507 | + return; | |
| 508 | + } | |
| 509 | + | |
| 510 | + if ( 'footer' === $template ) { | |
| 511 | + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/preview/footer.php'; | |
| 512 | + } | |
| 513 | + } | |
| 514 | + | |
| 515 | + /** | |
| 516 | + * Returns true if calling a template function doesn't trigger deprecation warnings. | |
| 517 | + * | |
| 518 | + * @since 6.7.1 | |
| 519 | + * @param string $template | |
| 520 | + * @return bool | |
| 521 | + */ | |
| 522 | + private static function should_try_getting_template( $template ) { | |
| 523 | + $stylesheet_path = get_stylesheet_directory(); | |
| 524 | + $template_path = get_template_directory(); | |
| 525 | + $is_child_theme = $stylesheet_path !== $template_path; | |
| 526 | + $template_name = $template . '.php'; | |
| 527 | + | |
| 528 | + return file_exists( $stylesheet_path . '/' . $template_name ) || $is_child_theme && file_exists( $template_path . '/' . $template_name ); | |
| 529 | + } | |
| 530 | + | |
| 531 | + /** | |
| 424 | 532 | * Set the page title for the theme preview page |
| 425 | 533 | * |
| 426 | 534 | * @since 3.0 |
| 427 | 535 | */ |
| @@ -442,15 +550,20 @@ | ||
| 442 | 550 | return __( 'Form Preview', 'formidable' ); |
| 443 | 551 | } |
| 444 | 552 | |
| 445 | 553 | /** |
| 446 | - * Set the page content for the theme preview page | |
| 554 | + * Set the page content for the theme preview page. | |
| 447 | 555 | * |
| 448 | 556 | * @since 3.0 |
| 557 | + * | |
| 558 | + * @param string $content | |
| 559 | + * @return string | |
| 449 | 560 | */ |
| 450 | 561 | public static function preview_content( $content ) { |
| 451 | 562 | if ( in_the_loop() ) { |
| 452 | - $content = self::show_page_preview(); | |
| 563 | + self::show_page_preview(); | |
| 564 | + // Clear the content for the page we're using. | |
| 565 | + $content = ''; | |
| 453 | 566 | } |
| 454 | 567 | |
| 455 | 568 | return $content; |
| 456 | 569 | } |
| @@ -537,9 +650,9 @@ | ||
| 537 | 650 | FrmAppHelper::permission_check( $available_status[ $status ]['permission'] ); |
| 538 | 651 | |
| 539 | 652 | $params = FrmForm::list_page_params(); |
| 540 | 653 | |
| 541 | - //check nonce url | |
| 654 | + // Check nonce url. | |
| 542 | 655 | check_admin_referer( $status . '_form_' . $params['id'] ); |
| 543 | 656 | |
| 544 | 657 | $count = 0; |
| 545 | 658 | if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) { |
| @@ -620,15 +733,20 @@ | ||
| 620 | 733 | $count ++; |
| 621 | 734 | } |
| 622 | 735 | } |
| 623 | 736 | |
| 624 | - /* translators: %1$s: Number of forms */ | |
| 625 | - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 737 | + if ( $count ) { | |
| 738 | + /* translators: %1$s: Number of forms */ | |
| 739 | + return sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 740 | + } | |
| 626 | 741 | |
| 627 | - return $message; | |
| 742 | + return ''; | |
| 628 | 743 | } |
| 629 | 744 | |
| 630 | - private static function delete_all() { | |
| 745 | + /** | |
| 746 | + * @since 6.7.1 Function went from private to public. | |
| 747 | + */ | |
| 748 | + public static function delete_all() { | |
| 631 | 749 | // Check nonce url. |
| 632 | 750 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' ); |
| 633 | 751 | if ( $permission_error !== false ) { |
| 634 | 752 | self::display_forms_list( array(), '', array( $permission_error ) ); |
| @@ -635,14 +753,15 @@ | ||
| 635 | 753 | |
| 636 | 754 | return; |
| 637 | 755 | } |
| 638 | 756 | |
| 639 | - $count = FrmForm::scheduled_delete( time() ); | |
| 757 | + $count = FrmForm::scheduled_delete( time() ); | |
| 758 | + $url = remove_query_arg( array( 'delete_all' ) ); | |
| 640 | 759 | |
| 641 | - /* translators: %1$s: Number of forms */ | |
| 642 | - $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 760 | + $url .= '&message=forms_permanently_deleted&forms_deleted=' . $count; | |
| 643 | 761 | |
| 644 | - self::display_forms_list( array(), $message ); | |
| 762 | + wp_safe_redirect( $url ); | |
| 763 | + die(); | |
| 645 | 764 | } |
| 646 | 765 | |
| 647 | 766 | /** |
| 648 | 767 | * Create a new form from the modal. |
| @@ -680,9 +799,9 @@ | ||
| 680 | 799 | self::create_default_on_submit_action( $form_id ); |
| 681 | 800 | self::create_default_email_action( $form_id ); |
| 682 | 801 | |
| 683 | 802 | $response = array( |
| 684 | - 'redirect' => FrmForm::get_edit_link( $form_id ), | |
| 803 | + 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true', | |
| 685 | 804 | ); |
| 686 | 805 | |
| 687 | 806 | echo wp_json_encode( $response ); |
| 688 | 807 | wp_die(); |
| @@ -688,46 +807,13 @@ | ||
| 688 | 807 | wp_die(); |
| 689 | 808 | } |
| 690 | 809 | |
| 691 | 810 | /** |
| 692 | - * Create a custom template from a form | |
| 693 | - * | |
| 694 | - * @since 3.06 | |
| 695 | - */ | |
| 696 | - public static function build_template() { | |
| 697 | - global $wpdb; | |
| 698 | - | |
| 699 | - FrmAppHelper::permission_check( 'frm_edit_forms' ); | |
| 700 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 701 | - | |
| 702 | - $form_id = FrmAppHelper::get_param( 'xml', '', 'post', 'absint' ); | |
| 703 | - $new_form_id = FrmForm::duplicate( $form_id, 1, true ); | |
| 704 | - if ( ! $new_form_id ) { | |
| 705 | - $response = array( | |
| 706 | - 'message' => __( 'There was an error creating a template.', 'formidable' ), | |
| 707 | - ); | |
| 708 | - } else { | |
| 709 | - $new_values = self::get_modal_values(); | |
| 710 | - $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $new_form_id ) ); | |
| 711 | - if ( $query_results ) { | |
| 712 | - FrmForm::clear_form_cache(); | |
| 713 | - } | |
| 714 | - | |
| 715 | - $response = array( | |
| 716 | - 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . $new_form_id ) . '&_wpnonce=' . wp_create_nonce(), | |
| 717 | - ); | |
| 718 | - } | |
| 719 | - | |
| 720 | - echo wp_json_encode( $response ); | |
| 721 | - wp_die(); | |
| 722 | - } | |
| 723 | - | |
| 724 | - /** | |
| 725 | 811 | * Before creating a new form, get the name and description from the modal. |
| 726 | 812 | * |
| 727 | 813 | * @since 4.0 |
| 728 | 814 | */ |
| 729 | - private static function get_modal_values() { | |
| 815 | + public static function get_modal_values() { | |
| 730 | 816 | $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' ); |
| 731 | 817 | $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' ); |
| 732 | 818 | |
| 733 | 819 | return array( |
| @@ -889,14 +975,14 @@ | ||
| 889 | 975 | * @return array<string,string> |
| 890 | 976 | */ |
| 891 | 977 | public static function get_columns( $columns ) { |
| 892 | 978 | $columns['cb'] = '<input type="checkbox" />'; |
| 893 | - $columns['name'] = __( 'Form Title', 'formidable' ); | |
| 894 | - $columns['entries'] = __( 'Entries', 'formidable' ); | |
| 979 | + $columns['name'] = esc_html__( 'Form Title', 'formidable' ); | |
| 980 | + $columns['entries'] = esc_html__( 'Entries', 'formidable' ); | |
| 895 | 981 | $columns['id'] = 'ID'; |
| 896 | - $columns['form_key'] = __( 'Key', 'formidable' ); | |
| 897 | - $columns['shortcode'] = __( 'Actions', 'formidable' ); | |
| 898 | - $columns['created_at'] = __( 'Date', 'formidable' ); | |
| 982 | + $columns['form_key'] = esc_html__( 'Key', 'formidable' ); | |
| 983 | + $columns['shortcode'] = esc_html__( 'Actions', 'formidable' ); | |
| 984 | + $columns['created_at'] = esc_html__( 'Date', 'formidable' ); | |
| 899 | 985 | |
| 900 | 986 | add_screen_option( |
| 901 | 987 | 'per_page', |
| 902 | 988 | array( |
| @@ -950,147 +1036,43 @@ | ||
| 950 | 1036 | |
| 951 | 1037 | return $save; |
| 952 | 1038 | } |
| 953 | 1039 | |
| 954 | - /** | |
| 955 | - * @return bool | |
| 956 | - */ | |
| 957 | - public static function expired() { | |
| 958 | - global $frm_expired; | |
| 959 | - return $frm_expired; | |
| 960 | - } | |
| 1040 | + private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) { | |
| 1041 | + global $frm_vars; | |
| 961 | 1042 | |
| 962 | - /** | |
| 963 | - * Get data from api before rendering it so that we can flag the modal as expired | |
| 964 | - * | |
| 965 | - * @return void | |
| 966 | - */ | |
| 967 | - public static function before_list_templates() { | |
| 968 | - global $frm_templates; | |
| 969 | - global $frm_expired; | |
| 970 | - global $frm_license_type; | |
| 971 | - | |
| 972 | - $api = new FrmFormTemplateApi(); | |
| 973 | - $frm_templates = $api->get_api_info(); | |
| 974 | - $expired = false; | |
| 975 | - $license_type = ''; | |
| 976 | - if ( isset( $frm_templates['error'] ) ) { | |
| 977 | - $error = $frm_templates['error']['message']; | |
| 978 | - $error = str_replace( 'utm_medium=addons', 'utm_medium=form-templates', $error ); | |
| 979 | - $expired = 'expired' === $frm_templates['error']['code']; | |
| 980 | - $license_type = isset( $frm_templates['error']['type'] ) ? $frm_templates['error']['type'] : ''; | |
| 981 | - unset( $frm_templates['error'] ); | |
| 982 | - } | |
| 983 | - | |
| 984 | - $frm_expired = $expired; | |
| 985 | - $frm_license_type = $license_type; | |
| 986 | - } | |
| 987 | - | |
| 988 | - /** | |
| 989 | - * @return void | |
| 990 | - */ | |
| 991 | - public static function list_templates() { | |
| 992 | - global $frm_templates; | |
| 993 | - global $frm_license_type; | |
| 994 | - | |
| 995 | - $templates = $frm_templates; | |
| 996 | - $custom_templates = array(); | |
| 997 | - $templates_by_category = array(); | |
| 998 | - | |
| 999 | - self::add_user_templates( $custom_templates ); | |
| 1000 | - | |
| 1001 | - foreach ( $templates as $template ) { | |
| 1002 | - if ( ! isset( $template['categories'] ) ) { | |
| 1003 | - continue; | |
| 1004 | - } | |
| 1005 | - | |
| 1006 | - foreach ( $template['categories'] as $category ) { | |
| 1007 | - if ( ! isset( $templates_by_category[ $category ] ) ) { | |
| 1008 | - $templates_by_category[ $category ] = array(); | |
| 1009 | - } | |
| 1010 | - | |
| 1011 | - $templates_by_category[ $category ][] = $template; | |
| 1012 | - } | |
| 1013 | - } | |
| 1014 | - unset( $template ); | |
| 1015 | - | |
| 1016 | - // Subcategories that are included elsewhere. | |
| 1017 | - $redundant_cats = array( 'PayPal', 'Stripe', 'Twilio' ); | |
| 1018 | - | |
| 1019 | - $categories = array_keys( $templates_by_category ); | |
| 1020 | - $categories = array_diff( $categories, FrmFormsHelper::ignore_template_categories() ); | |
| 1021 | - $categories = array_diff( $categories, $redundant_cats ); | |
| 1022 | - sort( $categories ); | |
| 1023 | - | |
| 1024 | - array_walk( | |
| 1025 | - $custom_templates, | |
| 1026 | - function( &$template ) { | |
| 1027 | - $template['custom'] = true; | |
| 1028 | - } | |
| 1043 | + $form = FrmForm::getOne( $id ); | |
| 1044 | + $error_args = array( | |
| 1045 | + 'title' => __( 'You can\'t edit the form', 'formidable' ), | |
| 1046 | + 'body' => __( 'You are trying to edit a form that does not exist', 'formidable' ), | |
| 1047 | + 'cancel_url' => admin_url( 'admin.php?page=formidable' ), | |
| 1048 | + 'continue_url' => add_query_arg( | |
| 1049 | + array( | |
| 1050 | + 'page' => 'formidable', | |
| 1051 | + ) | |
| 1052 | + ), | |
| 1029 | 1053 | ); |
| 1030 | - | |
| 1031 | - $my_templates_translation = __( 'My Templates', 'formidable' ); | |
| 1032 | - $categories = array_merge( array( $my_templates_translation ), $categories ); | |
| 1033 | - $pricing = FrmAppHelper::admin_upgrade_link( 'form-templates' ); | |
| 1034 | - $license_type = $frm_license_type; | |
| 1035 | - $args = compact( 'pricing', 'license_type' ); | |
| 1036 | - $where = apply_filters( 'frm_forms_dropdown', array(), '' ); | |
| 1037 | - $forms = FrmForm::get_published_forms( $where ); | |
| 1038 | - $view_path = FrmAppHelper::plugin_path() . '/classes/views/frm-forms/'; | |
| 1039 | - | |
| 1040 | - $templates_by_category[ $my_templates_translation ] = $custom_templates; | |
| 1041 | - | |
| 1042 | - unset( $pricing, $license_type, $where ); | |
| 1043 | - wp_enqueue_script( 'accordion' ); // register accordion for template groups | |
| 1044 | - require $view_path . 'list-templates.php'; | |
| 1045 | - } | |
| 1046 | - | |
| 1047 | - /** | |
| 1048 | - * @since 4.03.01 | |
| 1049 | - */ | |
| 1050 | - private static function get_template_categories( $templates ) { | |
| 1051 | - $categories = array(); | |
| 1052 | - foreach ( $templates as $template ) { | |
| 1053 | - if ( isset( $template['categories'] ) ) { | |
| 1054 | - $categories = array_merge( $categories, $template['categories'] ); | |
| 1055 | - } | |
| 1054 | + if ( ! $form ) { | |
| 1055 | + FrmAppController::show_error_modal( $error_args ); | |
| 1056 | + return; | |
| 1056 | 1057 | } |
| 1057 | - $exclude_cats = FrmFormsHelper::ignore_template_categories(); | |
| 1058 | - $categories = array_unique( $categories ); | |
| 1059 | - $categories = array_diff( $categories, $exclude_cats ); | |
| 1060 | - sort( $categories ); | |
| 1061 | - return $categories; | |
| 1062 | - } | |
| 1063 | 1058 | |
| 1064 | - private static function add_user_templates( &$templates ) { | |
| 1065 | - $user_templates = array( | |
| 1066 | - 'is_template' => 1, | |
| 1067 | - 'default_template' => 0, | |
| 1068 | - ); | |
| 1069 | - $user_templates = FrmForm::getAll( $user_templates, 'name' ); | |
| 1070 | - foreach ( $user_templates as $template ) { | |
| 1071 | - $template = array( | |
| 1072 | - 'id' => $template->id, | |
| 1073 | - 'name' => $template->name, | |
| 1074 | - 'key' => $template->form_key, | |
| 1075 | - 'description' => $template->description, | |
| 1076 | - 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template->id ) ) ), | |
| 1077 | - 'released' => $template->created_at, | |
| 1078 | - 'installed' => 1, | |
| 1059 | + if ( 'trash' === $form->status ) { | |
| 1060 | + $error_args['body'] = __( 'The form you\'re trying to edit is in trash. You must restore it first before you can make changes', 'formidable' ); | |
| 1061 | + $error_args['continue_url'] = add_query_arg( | |
| 1062 | + array( | |
| 1063 | + 'page' => 'formidable', | |
| 1064 | + '_wpnonce' => wp_create_nonce( 'untrash_form_' . $id ), | |
| 1065 | + 'form_type' => 'trash', | |
| 1066 | + 'frm_action' => 'untrash', | |
| 1067 | + 'id' => $id, | |
| 1068 | + ) | |
| 1079 | 1069 | ); |
| 1080 | - array_unshift( $templates, $template ); | |
| 1081 | - unset( $template ); | |
| 1070 | + $error_args['continue_text'] = __( 'Restore form', 'formidable' ); | |
| 1071 | + FrmAppController::show_error_modal( $error_args ); | |
| 1072 | + return; | |
| 1082 | 1073 | } |
| 1083 | - } | |
| 1084 | 1074 | |
| 1085 | - private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) { | |
| 1086 | - global $frm_vars; | |
| 1087 | - | |
| 1088 | - $form = FrmForm::getOne( $id ); | |
| 1089 | - if ( ! $form ) { | |
| 1090 | - wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) ); | |
| 1091 | - } | |
| 1092 | - | |
| 1093 | 1075 | if ( $form->parent_form_id ) { |
| 1094 | 1076 | /* translators: %1$s: Start link HTML, %2$s: End link HTML */ |
| 1095 | 1077 | wp_die( sprintf( esc_html__( 'You are trying to edit a child form. Please edit from %1$shere%2$s', 'formidable' ), '<a href="' . esc_url( FrmForm::get_edit_link( $form->parent_form_id ) ) . '">', '</a>' ) ); |
| 1096 | 1078 | } |
| @@ -1133,11 +1115,11 @@ | ||
| 1133 | 1115 | $has_fields = isset( $values['fields'] ) && ! empty( $values['fields'] ); |
| 1134 | 1116 | |
| 1135 | 1117 | if ( defined( 'DOING_AJAX' ) ) { |
| 1136 | 1118 | wp_die(); |
| 1137 | - } else { | |
| 1138 | - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' ); | |
| 1139 | 1119 | } |
| 1120 | + | |
| 1121 | + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php'; | |
| 1140 | 1122 | } |
| 1141 | 1123 | |
| 1142 | 1124 | public static function update_form_builder_fields( $fields, $form ) { |
| 1143 | 1125 | foreach ( $fields as $field ) { |
| @@ -1269,8 +1251,21 @@ | ||
| 1269 | 1251 | 'screenshot' => 'chat.png', |
| 1270 | 1252 | ) |
| 1271 | 1253 | ), |
| 1272 | 1254 | ), |
| 1255 | + 'abandonment' => array( | |
| 1256 | + 'name' => __( 'Form Abandonment', 'formidable' ), | |
| 1257 | + 'icon' => 'frm_icon_font frm_abandoned_icon', | |
| 1258 | + 'html_class' => 'frm_show_upgrade_tab frm_noallow', | |
| 1259 | + 'data' => FrmAppHelper::get_upgrade_data_params( | |
| 1260 | + 'abandonment', | |
| 1261 | + array( | |
| 1262 | + 'upgrade' => __( 'Form abandonment settings', 'formidable' ), | |
| 1263 | + 'message' => __( 'Unlock the power of data capture to boost lead generation and master the art of form optimization.', 'formidable' ), | |
| 1264 | + 'screenshot' => 'abandonment.png', | |
| 1265 | + ) | |
| 1266 | + ), | |
| 1267 | + ), | |
| 1273 | 1268 | 'html' => array( |
| 1274 | 1269 | 'name' => __( 'Customize HTML', 'formidable' ), |
| 1275 | 1270 | 'class' => __CLASS__, |
| 1276 | 1271 | 'function' => 'html_settings', |
| @@ -1277,9 +1272,9 @@ | ||
| 1277 | 1272 | 'icon' => 'frm_icon_font frm_code_icon', |
| 1278 | 1273 | ), |
| 1279 | 1274 | ); |
| 1280 | 1275 | |
| 1281 | - foreach ( array( 'landing', 'chat' ) as $feature ) { | |
| 1276 | + foreach ( array( 'landing', 'chat', 'abandonment' ) as $feature ) { | |
| 1282 | 1277 | if ( ! FrmAppHelper::show_new_feature( $feature ) ) { |
| 1283 | 1278 | unset( $sections[ $feature ] ); |
| 1284 | 1279 | } |
| 1285 | 1280 | } |
| @@ -1313,9 +1308,9 @@ | ||
| 1313 | 1308 | $section['id'] = $section['anchor']; |
| 1314 | 1309 | } |
| 1315 | 1310 | |
| 1316 | 1311 | $sections[ $key ] = $section; |
| 1317 | - } | |
| 1312 | + }//end foreach | |
| 1318 | 1313 | |
| 1319 | 1314 | return $sections; |
| 1320 | 1315 | } |
| 1321 | 1316 | |
| @@ -1739,9 +1734,9 @@ | ||
| 1739 | 1734 | if ( isset( $_REQUEST['delete_all'] ) ) { |
| 1740 | 1735 | // Override the action for this page. |
| 1741 | 1736 | $action = 'delete_all'; |
| 1742 | 1737 | } |
| 1743 | - } | |
| 1738 | + }//end if | |
| 1744 | 1739 | |
| 1745 | 1740 | add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' ); |
| 1746 | 1741 | FrmAppHelper::trigger_hook_load( 'form' ); |
| 1747 | 1742 | |
| @@ -1753,9 +1748,8 @@ | ||
| 1753 | 1748 | case 'update': |
| 1754 | 1749 | case 'trash': |
| 1755 | 1750 | case 'untrash': |
| 1756 | 1751 | case 'destroy': |
| 1757 | - case 'delete_all': | |
| 1758 | 1752 | case 'settings': |
| 1759 | 1753 | case 'update_settings': |
| 1760 | 1754 | return self::$action( $vars ); |
| 1761 | 1755 | case 'lite-reports': |
| @@ -1785,14 +1779,47 @@ | ||
| 1785 | 1779 | self::display_forms_list( array(), '', array( __( 'There was a problem duplicating the form', 'formidable' ) ) ); |
| 1786 | 1780 | return; |
| 1787 | 1781 | } |
| 1788 | 1782 | |
| 1783 | + if ( 'forms_permanently_deleted' === $message ) { | |
| 1784 | + $count = FrmAppHelper::get_param( 'forms_deleted', 0, 'get', 'absint' ); | |
| 1785 | + /* translators: %1$s: Number of forms */ | |
| 1786 | + $message = sprintf( _n( '%1$s form permanently deleted.', '%1$s forms permanently deleted.', $count, 'formidable' ), $count ); | |
| 1787 | + self::display_forms_list( array(), $message, '' ); | |
| 1788 | + return; | |
| 1789 | + } | |
| 1790 | + | |
| 1789 | 1791 | self::display_forms_list(); |
| 1790 | 1792 | |
| 1791 | 1793 | return; |
| 1792 | - } | |
| 1794 | + }//end switch | |
| 1793 | 1795 | } |
| 1794 | 1796 | |
| 1797 | + /** | |
| 1798 | + * Rename a form. | |
| 1799 | + * | |
| 1800 | + * Handles the AJAX request for renaming a form. | |
| 1801 | + * | |
| 1802 | + * @since 6.7 | |
| 1803 | + * | |
| 1804 | + * @return void | |
| 1805 | + */ | |
| 1806 | + public static function rename_form() { | |
| 1807 | + // Check permission and nonce | |
| 1808 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); | |
| 1809 | + check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 1810 | + | |
| 1811 | + // Get posted data | |
| 1812 | + $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' ); | |
| 1813 | + $name = FrmAppHelper::get_post_param( 'form_name', '', 'sanitize_text_field' ); | |
| 1814 | + | |
| 1815 | + // Update the form name and form key. | |
| 1816 | + $form_key = FrmAppHelper::get_unique_key( sanitize_title( $name ), 'frm_forms', 'form_key' ); | |
| 1817 | + FrmForm::update( $form_id, compact( 'name', 'form_key' ) ); | |
| 1818 | + | |
| 1819 | + wp_send_json_success( compact( 'form_key' ) ); | |
| 1820 | + } | |
| 1821 | + | |
| 1795 | 1822 | public static function json_error( $errors ) { |
| 1796 | 1823 | $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' ); |
| 1797 | 1824 | |
| 1798 | 1825 | return $errors; |
| @@ -1831,9 +1858,11 @@ | ||
| 1831 | 1858 | |
| 1832 | 1859 | include FrmAppHelper::plugin_path() . '/classes/views/shared/reports-info.php'; |
| 1833 | 1860 | } |
| 1834 | 1861 | |
| 1835 | - /* FRONT-END FORMS */ | |
| 1862 | + /** | |
| 1863 | + * FRONT-END FORMS. | |
| 1864 | + */ | |
| 1836 | 1865 | public static function admin_bar_css() { |
| 1837 | 1866 | if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) { |
| 1838 | 1867 | return; |
| 1839 | 1868 | } |
| @@ -2021,9 +2050,10 @@ | ||
| 2021 | 2050 | */ |
| 2022 | 2051 | private static function maybe_get_form_to_show( $id ) { |
| 2023 | 2052 | $form = false; |
| 2024 | 2053 | |
| 2025 | - if ( ! empty( $id ) ) { // form id or key is set | |
| 2054 | + if ( ! empty( $id ) ) { | |
| 2055 | + // Form id or key is set. | |
| 2026 | 2056 | $form = FrmForm::getOne( $id ); |
| 2027 | 2057 | if ( ! $form || $form->parent_form_id || $form->status === 'trash' ) { |
| 2028 | 2058 | $form = false; |
| 2029 | 2059 | } |
| @@ -2095,9 +2125,9 @@ | ||
| 2095 | 2125 | 'form' => $form, |
| 2096 | 2126 | ) |
| 2097 | 2127 | ); |
| 2098 | 2128 | } |
| 2099 | - } | |
| 2129 | + }//end if | |
| 2100 | 2130 | } |
| 2101 | 2131 | |
| 2102 | 2132 | /** |
| 2103 | 2133 | * If the form was processed earlier (init), get the generated errors |
| @@ -2297,9 +2327,10 @@ | ||
| 2297 | 2327 | |
| 2298 | 2328 | $action_type = FrmOnSubmitHelper::get_action_type( $action ); |
| 2299 | 2329 | |
| 2300 | 2330 | if ( 'redirect' === $action_type ) { |
| 2301 | - if ( $has_redirect ) { // Do not process because we run the first redirect action only. | |
| 2331 | + if ( $has_redirect ) { | |
| 2332 | + // Do not process because we run the first redirect action only. | |
| 2302 | 2333 | continue; |
| 2303 | 2334 | } |
| 2304 | 2335 | } |
| 2305 | 2336 | |
| @@ -2312,9 +2343,9 @@ | ||
| 2312 | 2343 | } |
| 2313 | 2344 | |
| 2314 | 2345 | $met_actions[] = $action; |
| 2315 | 2346 | unset( $action ); |
| 2316 | - } | |
| 2347 | + }//end foreach | |
| 2317 | 2348 | |
| 2318 | 2349 | $args['event'] = $event; |
| 2319 | 2350 | |
| 2320 | 2351 | /** |
| @@ -2503,9 +2534,9 @@ | ||
| 2503 | 2534 | add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 ); |
| 2504 | 2535 | } |
| 2505 | 2536 | |
| 2506 | 2537 | $post = $old_post; |
| 2507 | - } | |
| 2538 | + }//end if | |
| 2508 | 2539 | } |
| 2509 | 2540 | |
| 2510 | 2541 | /** |
| 2511 | 2542 | * @since 3.0 |
| @@ -2526,14 +2557,16 @@ | ||
| 2526 | 2557 | $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args ); |
| 2527 | 2558 | |
| 2528 | 2559 | $doing_ajax = FrmAppHelper::doing_ajax(); |
| 2529 | 2560 | |
| 2530 | - if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { // Is AJAX submit and there is just one Redirect action runs. | |
| 2561 | + if ( ! empty( $args['ajax'] ) && $doing_ajax && empty( $args['force_delay_redirect'] ) ) { | |
| 2562 | + // Is AJAX submit and there is just one Redirect action runs. | |
| 2531 | 2563 | echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) ); |
| 2532 | 2564 | wp_die(); |
| 2533 | 2565 | } |
| 2534 | 2566 | |
| 2535 | - if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { // Not AJAX submit, no headers sent, and there is just one Redirect action runs. | |
| 2567 | + if ( ! headers_sent() && empty( $args['force_delay_redirect'] ) ) { | |
| 2568 | + // Not AJAX submit, no headers sent, and there is just one Redirect action runs. | |
| 2536 | 2569 | if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { |
| 2537 | 2570 | self::print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ); |
| 2538 | 2571 | self::$redirected_in_new_tab[ $args['form']->id ] = 1; |
| 2539 | 2572 | return; |
| @@ -2539,9 +2572,10 @@ | ||
| 2539 | 2572 | return; |
| 2540 | 2573 | } |
| 2541 | 2574 | |
| 2542 | 2575 | wp_redirect( esc_url_raw( $success_url ) ); |
| 2543 | - die(); // do not use wp_die or redirect fails | |
| 2576 | + // Do not use wp_die or redirect fails. | |
| 2577 | + die(); | |
| 2544 | 2578 | } |
| 2545 | 2579 | |
| 2546 | 2580 | // Redirect with a delay. |
| 2547 | 2581 | self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) ); |
| @@ -2549,9 +2583,9 @@ | ||
| 2549 | 2583 | |
| 2550 | 2584 | /** |
| 2551 | 2585 | * Prints open in new tab js with fallback handler. |
| 2552 | 2586 | * |
| 2553 | - * @since 6.x | |
| 2587 | + * @since 6.3.1 | |
| 2554 | 2588 | * |
| 2555 | 2589 | * @param string $success_url Success URL. |
| 2556 | 2590 | * @param array $args See {@see FrmFormsController::redirect_after_submit()}. |
| 2557 | 2591 | */ |
| @@ -2570,9 +2604,9 @@ | ||
| 2570 | 2604 | |
| 2571 | 2605 | /** |
| 2572 | 2606 | * Gets response data for redirect action when AJAX submitting. |
| 2573 | 2607 | * |
| 2574 | - * @since 6.x | |
| 2608 | + * @since 6.3.1 | |
| 2575 | 2609 | * |
| 2576 | 2610 | * @param array $args See {@see FrmFormsController::run_success_action()}. |
| 2577 | 2611 | * @return array |
| 2578 | 2612 | */ |
| @@ -2632,9 +2666,10 @@ | ||
| 2632 | 2666 | add_filter( 'frm_use_wpautop', '__return_true' ); |
| 2633 | 2667 | |
| 2634 | 2668 | echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 2635 | 2669 | echo '<script>'; |
| 2636 | - if ( empty( $args['doing_ajax'] ) ) { // Not AJAX submit, delay JS until window.load. | |
| 2670 | + if ( empty( $args['doing_ajax'] ) ) { | |
| 2671 | + // Not AJAX submit, delay JS until window.load. | |
| 2637 | 2672 | echo 'window.onload=function(){'; |
| 2638 | 2673 | } |
| 2639 | 2674 | echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 2640 | 2675 | if ( empty( $args['doing_ajax'] ) ) { |
| @@ -2647,9 +2682,9 @@ | ||
| 2647 | 2682 | * @since 3.0 |
| 2648 | 2683 | * |
| 2649 | 2684 | * @param string $success_url |
| 2650 | 2685 | * @param string $success_msg |
| 2651 | - * @param array $args | |
| 2686 | + * @param array $args | |
| 2652 | 2687 | */ |
| 2653 | 2688 | private static function get_redirect_message( $success_url, $success_msg, $args ) { |
| 2654 | 2689 | $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' . |
| 2655 | 2690 | self::get_redirect_fallback_message( $success_url, $args ) . |
| @@ -2666,9 +2701,9 @@ | ||
| 2666 | 2701 | |
| 2667 | 2702 | /** |
| 2668 | 2703 | * Gets fallback message when redirecting failed. |
| 2669 | 2704 | * |
| 2670 | - * @since 6.x | |
| 2705 | + * @since 6.3.1 | |
| 2671 | 2706 | * |
| 2672 | 2707 | * @param string $success_url Redirect URL. |
| 2673 | 2708 | * @param array $args Contains `form` object. |
| 2674 | 2709 | * @return string |
| @@ -2986,9 +3021,9 @@ | ||
| 2986 | 3021 | * Create a page with an embedded formidable Gutenberg block. |
| 2987 | 3022 | * |
| 2988 | 3023 | * @since 5.2 |
| 2989 | 3024 | * |
| 2990 | - * @return never | |
| 3025 | + * @return void | |
| 2991 | 3026 | */ |
| 2992 | 3027 | public static function create_page_with_shortcode() { |
| 2993 | 3028 | if ( ! current_user_can( 'publish_posts' ) ) { |
| 2994 | 3029 | die( 0 ); |
| @@ -3033,10 +3068,9 @@ | ||
| 3033 | 3068 | |
| 3034 | 3069 | /** |
| 3035 | 3070 | * @since 5.3 |
| 3036 | 3071 | * |
| 3037 | - * @param string $content | |
| 3038 | - * @param int $form_id | |
| 3072 | + * @param int $form_id | |
| 3039 | 3073 | * @return string |
| 3040 | 3074 | */ |
| 3041 | 3075 | private static function get_page_shortcode_content_for_form( $form_id ) { |
| 3042 | 3076 | $shortcode = '[formidable id="' . $form_id . '"]'; |
| @@ -3047,9 +3081,9 @@ | ||
| 3047 | 3081 | |
| 3048 | 3082 | /** |
| 3049 | 3083 | * Get page dropdown for AJAX request for embedding form in an existing page. |
| 3050 | 3084 | * |
| 3051 | - * @return never | |
| 3085 | + * @return void | |
| 3052 | 3086 | */ |
| 3053 | 3087 | public static function get_page_dropdown() { |
| 3054 | 3088 | if ( ! current_user_can( 'publish_posts' ) ) { |
| 3055 | 3089 | die( 0 ); |
| @@ -3121,6 +3155,46 @@ | ||
| 3121 | 3155 | * @since 3.06 |
| 3122 | 3156 | */ |
| 3123 | 3157 | public static function add_new() { |
| 3124 | 3158 | _deprecated_function( __FUNCTION__, '4.08' ); |
| 3159 | + } | |
| 3160 | + | |
| 3161 | + /** | |
| 3162 | + * Create a custom template from a form | |
| 3163 | + * | |
| 3164 | + * @since 3.06 | |
| 3165 | + * @deprecated 6.7 | |
| 3166 | + */ | |
| 3167 | + public static function build_template() { | |
| 3168 | + _deprecated_function( __METHOD__, '6.7' ); | |
| 3169 | + } | |
| 3170 | + | |
| 3171 | + /** | |
| 3172 | + * @deprecated 6.7 | |
| 3173 | + * | |
| 3174 | + * @return bool | |
| 3175 | + */ | |
| 3176 | + public static function expired() { | |
| 3177 | + _deprecated_function( __METHOD__, '6.7' ); | |
| 3178 | + return FrmAddonsController::is_license_expired(); | |
| 3179 | + } | |
| 3180 | + | |
| 3181 | + /** | |
| 3182 | + * Get data from api before rendering it so that we can flag the modal as expired | |
| 3183 | + * | |
| 3184 | + * @deprecated 6.7 | |
| 3185 | + * | |
| 3186 | + * @return void | |
| 3187 | + */ | |
| 3188 | + public static function before_list_templates() { | |
| 3189 | + _deprecated_function( __METHOD__, '6.7' ); | |
| 3190 | + } | |
| 3191 | + | |
| 3192 | + /** | |
| 3193 | + * @deprecated 6.7 | |
| 3194 | + * | |
| 3195 | + * @return void | |
| 3196 | + */ | |
| 3197 | + public static function list_templates() { | |
| 3198 | + _deprecated_function( __METHOD__, '6.7' ); | |
| 3125 | 3199 | } |
| 3126 | 3200 | } |