| @@ -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; |
| @@ -424,9 +474,10 @@ | ||
| 424 | 474 | */ |
| 425 | 475 | private static function fallback_when_page_template_part_is_not_supported_by_theme() { |
| 426 | 476 | if ( have_posts() ) { |
| 427 | 477 | the_post(); |
| 428 | - get_header( '' ); | |
| 478 | + self::get_template( 'header' ); | |
| 479 | + | |
| 429 | 480 | // add some generic class names to the container to add some natural padding to the content. |
| 430 | 481 | // .entry-content catches the WordPress TwentyTwenty theme. |
| 431 | 482 | // .container catches Customizr content. |
| 432 | 483 | echo '<div class="container entry-content">'; |
| @@ -431,13 +482,54 @@ | ||
| 431 | 482 | // .container catches Customizr content. |
| 432 | 483 | echo '<div class="container entry-content">'; |
| 433 | 484 | the_content(); |
| 434 | 485 | echo '</div>'; |
| 435 | - get_footer(); | |
| 486 | + | |
| 487 | + self::get_template( 'footer' ); | |
| 436 | 488 | } |
| 437 | 489 | } |
| 438 | 490 | |
| 439 | 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 | + /** | |
| 440 | 532 | * Set the page title for the theme preview page |
| 441 | 533 | * |
| 442 | 534 | * @since 3.0 |
| 443 | 535 | */ |
| @@ -458,15 +550,20 @@ | ||
| 458 | 550 | return __( 'Form Preview', 'formidable' ); |
| 459 | 551 | } |
| 460 | 552 | |
| 461 | 553 | /** |
| 462 | - * Set the page content for the theme preview page | |
| 554 | + * Set the page content for the theme preview page. | |
| 463 | 555 | * |
| 464 | 556 | * @since 3.0 |
| 557 | + * | |
| 558 | + * @param string $content | |
| 559 | + * @return string | |
| 465 | 560 | */ |
| 466 | 561 | public static function preview_content( $content ) { |
| 467 | 562 | if ( in_the_loop() ) { |
| 468 | - $content = self::show_page_preview(); | |
| 563 | + self::show_page_preview(); | |
| 564 | + // Clear the content for the page we're using. | |
| 565 | + $content = ''; | |
| 469 | 566 | } |
| 470 | 567 | |
| 471 | 568 | return $content; |
| 472 | 569 | } |
| @@ -553,9 +650,9 @@ | ||
| 553 | 650 | FrmAppHelper::permission_check( $available_status[ $status ]['permission'] ); |
| 554 | 651 | |
| 555 | 652 | $params = FrmForm::list_page_params(); |
| 556 | 653 | |
| 557 | - //check nonce url | |
| 654 | + // Check nonce url. | |
| 558 | 655 | check_admin_referer( $status . '_form_' . $params['id'] ); |
| 559 | 656 | |
| 560 | 657 | $count = 0; |
| 561 | 658 | if ( FrmForm::set_status( $params['id'], $available_status[ $status ]['new_status'] ) ) { |
| @@ -636,15 +733,20 @@ | ||
| 636 | 733 | $count ++; |
| 637 | 734 | } |
| 638 | 735 | } |
| 639 | 736 | |
| 640 | - /* translators: %1$s: Number of forms */ | |
| 641 | - $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 | + } | |
| 642 | 741 | |
| 643 | - return $message; | |
| 742 | + return ''; | |
| 644 | 743 | } |
| 645 | 744 | |
| 646 | - private static function delete_all() { | |
| 745 | + /** | |
| 746 | + * @since 6.7.1 Function went from private to public. | |
| 747 | + */ | |
| 748 | + public static function delete_all() { | |
| 647 | 749 | // Check nonce url. |
| 648 | 750 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_delete_forms', '_wpnonce', 'bulk-toplevel_page_formidable' ); |
| 649 | 751 | if ( $permission_error !== false ) { |
| 650 | 752 | self::display_forms_list( array(), '', array( $permission_error ) ); |
| @@ -651,14 +753,15 @@ | ||
| 651 | 753 | |
| 652 | 754 | return; |
| 653 | 755 | } |
| 654 | 756 | |
| 655 | - $count = FrmForm::scheduled_delete( time() ); | |
| 757 | + $count = FrmForm::scheduled_delete( time() ); | |
| 758 | + $url = remove_query_arg( array( 'delete_all' ) ); | |
| 656 | 759 | |
| 657 | - /* translators: %1$s: Number of forms */ | |
| 658 | - $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; | |
| 659 | 761 | |
| 660 | - self::display_forms_list( array(), $message ); | |
| 762 | + wp_safe_redirect( $url ); | |
| 763 | + die(); | |
| 661 | 764 | } |
| 662 | 765 | |
| 663 | 766 | /** |
| 664 | 767 | * Create a new form from the modal. |
| @@ -696,9 +799,9 @@ | ||
| 696 | 799 | self::create_default_on_submit_action( $form_id ); |
| 697 | 800 | self::create_default_email_action( $form_id ); |
| 698 | 801 | |
| 699 | 802 | $response = array( |
| 700 | - 'redirect' => FrmForm::get_edit_link( $form_id ), | |
| 803 | + 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true', | |
| 701 | 804 | ); |
| 702 | 805 | |
| 703 | 806 | echo wp_json_encode( $response ); |
| 704 | 807 | wp_die(); |
| @@ -704,46 +807,13 @@ | ||
| 704 | 807 | wp_die(); |
| 705 | 808 | } |
| 706 | 809 | |
| 707 | 810 | /** |
| 708 | - * Create a custom template from a form | |
| 709 | - * | |
| 710 | - * @since 3.06 | |
| 711 | - */ | |
| 712 | - public static function build_template() { | |
| 713 | - global $wpdb; | |
| 714 | - | |
| 715 | - FrmAppHelper::permission_check( 'frm_edit_forms' ); | |
| 716 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 717 | - | |
| 718 | - $form_id = FrmAppHelper::get_param( 'xml', '', 'post', 'absint' ); | |
| 719 | - $new_form_id = FrmForm::duplicate( $form_id, 1, true ); | |
| 720 | - if ( ! $new_form_id ) { | |
| 721 | - $response = array( | |
| 722 | - 'message' => __( 'There was an error creating a template.', 'formidable' ), | |
| 723 | - ); | |
| 724 | - } else { | |
| 725 | - $new_values = self::get_modal_values(); | |
| 726 | - $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $new_form_id ) ); | |
| 727 | - if ( $query_results ) { | |
| 728 | - FrmForm::clear_form_cache(); | |
| 729 | - } | |
| 730 | - | |
| 731 | - $response = array( | |
| 732 | - 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . $new_form_id ) . '&_wpnonce=' . wp_create_nonce(), | |
| 733 | - ); | |
| 734 | - } | |
| 735 | - | |
| 736 | - echo wp_json_encode( $response ); | |
| 737 | - wp_die(); | |
| 738 | - } | |
| 739 | - | |
| 740 | - /** | |
| 741 | 811 | * Before creating a new form, get the name and description from the modal. |
| 742 | 812 | * |
| 743 | 813 | * @since 4.0 |
| 744 | 814 | */ |
| 745 | - private static function get_modal_values() { | |
| 815 | + public static function get_modal_values() { | |
| 746 | 816 | $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' ); |
| 747 | 817 | $desc = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' ); |
| 748 | 818 | |
| 749 | 819 | return array( |
| @@ -966,147 +1036,43 @@ | ||
| 966 | 1036 | |
| 967 | 1037 | return $save; |
| 968 | 1038 | } |
| 969 | 1039 | |
| 970 | - /** | |
| 971 | - * @return bool | |
| 972 | - */ | |
| 973 | - public static function expired() { | |
| 974 | - global $frm_expired; | |
| 975 | - return $frm_expired; | |
| 976 | - } | |
| 1040 | + private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) { | |
| 1041 | + global $frm_vars; | |
| 977 | 1042 | |
| 978 | - /** | |
| 979 | - * Get data from api before rendering it so that we can flag the modal as expired | |
| 980 | - * | |
| 981 | - * @return void | |
| 982 | - */ | |
| 983 | - public static function before_list_templates() { | |
| 984 | - global $frm_templates; | |
| 985 | - global $frm_expired; | |
| 986 | - global $frm_license_type; | |
| 987 | - | |
| 988 | - $api = new FrmFormTemplateApi(); | |
| 989 | - $frm_templates = $api->get_api_info(); | |
| 990 | - $expired = false; | |
| 991 | - $license_type = ''; | |
| 992 | - if ( isset( $frm_templates['error'] ) ) { | |
| 993 | - $error = $frm_templates['error']['message']; | |
| 994 | - $error = str_replace( 'utm_medium=addons', 'utm_medium=form-templates', $error ); | |
| 995 | - $expired = 'expired' === $frm_templates['error']['code']; | |
| 996 | - $license_type = isset( $frm_templates['error']['type'] ) ? $frm_templates['error']['type'] : ''; | |
| 997 | - unset( $frm_templates['error'] ); | |
| 998 | - } | |
| 999 | - | |
| 1000 | - $frm_expired = $expired; | |
| 1001 | - $frm_license_type = $license_type; | |
| 1002 | - } | |
| 1003 | - | |
| 1004 | - /** | |
| 1005 | - * @return void | |
| 1006 | - */ | |
| 1007 | - public static function list_templates() { | |
| 1008 | - global $frm_templates; | |
| 1009 | - global $frm_license_type; | |
| 1010 | - | |
| 1011 | - $templates = $frm_templates; | |
| 1012 | - $custom_templates = array(); | |
| 1013 | - $templates_by_category = array(); | |
| 1014 | - | |
| 1015 | - self::add_user_templates( $custom_templates ); | |
| 1016 | - | |
| 1017 | - foreach ( $templates as $template ) { | |
| 1018 | - if ( ! isset( $template['categories'] ) ) { | |
| 1019 | - continue; | |
| 1020 | - } | |
| 1021 | - | |
| 1022 | - foreach ( $template['categories'] as $category ) { | |
| 1023 | - if ( ! isset( $templates_by_category[ $category ] ) ) { | |
| 1024 | - $templates_by_category[ $category ] = array(); | |
| 1025 | - } | |
| 1026 | - | |
| 1027 | - $templates_by_category[ $category ][] = $template; | |
| 1028 | - } | |
| 1029 | - } | |
| 1030 | - unset( $template ); | |
| 1031 | - | |
| 1032 | - // Subcategories that are included elsewhere. | |
| 1033 | - $redundant_cats = array( 'PayPal', 'Stripe', 'Twilio' ); | |
| 1034 | - | |
| 1035 | - $categories = array_keys( $templates_by_category ); | |
| 1036 | - $categories = array_diff( $categories, FrmFormsHelper::ignore_template_categories() ); | |
| 1037 | - $categories = array_diff( $categories, $redundant_cats ); | |
| 1038 | - sort( $categories ); | |
| 1039 | - | |
| 1040 | - array_walk( | |
| 1041 | - $custom_templates, | |
| 1042 | - function( &$template ) { | |
| 1043 | - $template['custom'] = true; | |
| 1044 | - } | |
| 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 | + ), | |
| 1045 | 1053 | ); |
| 1046 | - | |
| 1047 | - $my_templates_translation = __( 'My Templates', 'formidable' ); | |
| 1048 | - $categories = array_merge( array( $my_templates_translation ), $categories ); | |
| 1049 | - $pricing = FrmAppHelper::admin_upgrade_link( 'form-templates' ); | |
| 1050 | - $license_type = $frm_license_type; | |
| 1051 | - $args = compact( 'pricing', 'license_type' ); | |
| 1052 | - $where = apply_filters( 'frm_forms_dropdown', array(), '' ); | |
| 1053 | - $forms = FrmForm::get_published_forms( $where ); | |
| 1054 | - $view_path = FrmAppHelper::plugin_path() . '/classes/views/frm-forms/'; | |
| 1055 | - | |
| 1056 | - $templates_by_category[ $my_templates_translation ] = $custom_templates; | |
| 1057 | - | |
| 1058 | - unset( $pricing, $license_type, $where ); | |
| 1059 | - wp_enqueue_script( 'accordion' ); // register accordion for template groups | |
| 1060 | - require $view_path . 'list-templates.php'; | |
| 1061 | - } | |
| 1062 | - | |
| 1063 | - /** | |
| 1064 | - * @since 4.03.01 | |
| 1065 | - */ | |
| 1066 | - private static function get_template_categories( $templates ) { | |
| 1067 | - $categories = array(); | |
| 1068 | - foreach ( $templates as $template ) { | |
| 1069 | - if ( isset( $template['categories'] ) ) { | |
| 1070 | - $categories = array_merge( $categories, $template['categories'] ); | |
| 1071 | - } | |
| 1054 | + if ( ! $form ) { | |
| 1055 | + FrmAppController::show_error_modal( $error_args ); | |
| 1056 | + return; | |
| 1072 | 1057 | } |
| 1073 | - $exclude_cats = FrmFormsHelper::ignore_template_categories(); | |
| 1074 | - $categories = array_unique( $categories ); | |
| 1075 | - $categories = array_diff( $categories, $exclude_cats ); | |
| 1076 | - sort( $categories ); | |
| 1077 | - return $categories; | |
| 1078 | - } | |
| 1079 | 1058 | |
| 1080 | - private static function add_user_templates( &$templates ) { | |
| 1081 | - $user_templates = array( | |
| 1082 | - 'is_template' => 1, | |
| 1083 | - 'default_template' => 0, | |
| 1084 | - ); | |
| 1085 | - $user_templates = FrmForm::getAll( $user_templates, 'name' ); | |
| 1086 | - foreach ( $user_templates as $template ) { | |
| 1087 | - $template = array( | |
| 1088 | - 'id' => $template->id, | |
| 1089 | - 'name' => $template->name, | |
| 1090 | - 'key' => $template->form_key, | |
| 1091 | - 'description' => $template->description, | |
| 1092 | - 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . absint( $template->id ) ) ), | |
| 1093 | - 'released' => $template->created_at, | |
| 1094 | - '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 | + ) | |
| 1095 | 1069 | ); |
| 1096 | - array_unshift( $templates, $template ); | |
| 1097 | - unset( $template ); | |
| 1070 | + $error_args['continue_text'] = __( 'Restore form', 'formidable' ); | |
| 1071 | + FrmAppController::show_error_modal( $error_args ); | |
| 1072 | + return; | |
| 1098 | 1073 | } |
| 1099 | - } | |
| 1100 | 1074 | |
| 1101 | - private static function get_edit_vars( $id, $errors = array(), $message = '', $create_link = false ) { | |
| 1102 | - global $frm_vars; | |
| 1103 | - | |
| 1104 | - $form = FrmForm::getOne( $id ); | |
| 1105 | - if ( ! $form ) { | |
| 1106 | - wp_die( esc_html__( 'You are trying to edit a form that does not exist.', 'formidable' ) ); | |
| 1107 | - } | |
| 1108 | - | |
| 1109 | 1075 | if ( $form->parent_form_id ) { |
| 1110 | 1076 | /* translators: %1$s: Start link HTML, %2$s: End link HTML */ |
| 1111 | 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>' ) ); |
| 1112 | 1078 | } |
| @@ -1149,11 +1115,11 @@ | ||
| 1149 | 1115 | $has_fields = isset( $values['fields'] ) && ! empty( $values['fields'] ); |
| 1150 | 1116 | |
| 1151 | 1117 | if ( defined( 'DOING_AJAX' ) ) { |
| 1152 | 1118 | wp_die(); |
| 1153 | - } else { | |
| 1154 | - require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php' ); | |
| 1155 | 1119 | } |
| 1120 | + | |
| 1121 | + require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/edit.php'; | |
| 1156 | 1122 | } |
| 1157 | 1123 | |
| 1158 | 1124 | public static function update_form_builder_fields( $fields, $form ) { |
| 1159 | 1125 | foreach ( $fields as $field ) { |
| @@ -1342,9 +1308,9 @@ | ||
| 1342 | 1308 | $section['id'] = $section['anchor']; |
| 1343 | 1309 | } |
| 1344 | 1310 | |
| 1345 | 1311 | $sections[ $key ] = $section; |
| 1346 | - } | |
| 1312 | + }//end foreach | |
| 1347 | 1313 | |
| 1348 | 1314 | return $sections; |
| 1349 | 1315 | } |
| 1350 | 1316 | |
| @@ -1768,9 +1734,9 @@ | ||
| 1768 | 1734 | if ( isset( $_REQUEST['delete_all'] ) ) { |
| 1769 | 1735 | // Override the action for this page. |
| 1770 | 1736 | $action = 'delete_all'; |
| 1771 | 1737 | } |
| 1772 | - } | |
| 1738 | + }//end if | |
| 1773 | 1739 | |
| 1774 | 1740 | add_action( 'frm_load_form_hooks', 'FrmHooksController::trigger_load_form_hooks' ); |
| 1775 | 1741 | FrmAppHelper::trigger_hook_load( 'form' ); |
| 1776 | 1742 | |
| @@ -1782,9 +1748,8 @@ | ||
| 1782 | 1748 | case 'update': |
| 1783 | 1749 | case 'trash': |
| 1784 | 1750 | case 'untrash': |
| 1785 | 1751 | case 'destroy': |
| 1786 | - case 'delete_all': | |
| 1787 | 1752 | case 'settings': |
| 1788 | 1753 | case 'update_settings': |
| 1789 | 1754 | return self::$action( $vars ); |
| 1790 | 1755 | case 'lite-reports': |
| @@ -1814,14 +1779,47 @@ | ||
| 1814 | 1779 | self::display_forms_list( array(), '', array( __( 'There was a problem duplicating the form', 'formidable' ) ) ); |
| 1815 | 1780 | return; |
| 1816 | 1781 | } |
| 1817 | 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 | + | |
| 1818 | 1791 | self::display_forms_list(); |
| 1819 | 1792 | |
| 1820 | 1793 | return; |
| 1821 | - } | |
| 1794 | + }//end switch | |
| 1822 | 1795 | } |
| 1823 | 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 | + | |
| 1824 | 1822 | public static function json_error( $errors ) { |
| 1825 | 1823 | $errors['json'] = __( 'Abnormal HTML characters prevented your form from saving correctly', 'formidable' ); |
| 1826 | 1824 | |
| 1827 | 1825 | return $errors; |
| @@ -1860,9 +1858,11 @@ | ||
| 1860 | 1858 | |
| 1861 | 1859 | include FrmAppHelper::plugin_path() . '/classes/views/shared/reports-info.php'; |
| 1862 | 1860 | } |
| 1863 | 1861 | |
| 1864 | - /* FRONT-END FORMS */ | |
| 1862 | + /** | |
| 1863 | + * FRONT-END FORMS. | |
| 1864 | + */ | |
| 1865 | 1865 | public static function admin_bar_css() { |
| 1866 | 1866 | if ( is_admin() || ! current_user_can( 'frm_edit_forms' ) ) { |
| 1867 | 1867 | return; |
| 1868 | 1868 | } |
| @@ -2050,9 +2050,10 @@ | ||
| 2050 | 2050 | */ |
| 2051 | 2051 | private static function maybe_get_form_to_show( $id ) { |
| 2052 | 2052 | $form = false; |
| 2053 | 2053 | |
| 2054 | - if ( ! empty( $id ) ) { // form id or key is set | |
| 2054 | + if ( ! empty( $id ) ) { | |
| 2055 | + // Form id or key is set. | |
| 2055 | 2056 | $form = FrmForm::getOne( $id ); |
| 2056 | 2057 | if ( ! $form || $form->parent_form_id || $form->status === 'trash' ) { |
| 2057 | 2058 | $form = false; |
| 2058 | 2059 | } |
| @@ -2124,9 +2125,9 @@ | ||
| 2124 | 2125 | 'form' => $form, |
| 2125 | 2126 | ) |
| 2126 | 2127 | ); |
| 2127 | 2128 | } |
| 2128 | - } | |
| 2129 | + }//end if | |
| 2129 | 2130 | } |
| 2130 | 2131 | |
| 2131 | 2132 | /** |
| 2132 | 2133 | * If the form was processed earlier (init), get the generated errors |
| @@ -2326,9 +2327,10 @@ | ||
| 2326 | 2327 | |
| 2327 | 2328 | $action_type = FrmOnSubmitHelper::get_action_type( $action ); |
| 2328 | 2329 | |
| 2329 | 2330 | if ( 'redirect' === $action_type ) { |
| 2330 | - 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. | |
| 2331 | 2333 | continue; |
| 2332 | 2334 | } |
| 2333 | 2335 | } |
| 2334 | 2336 | |
| @@ -2341,9 +2343,9 @@ | ||
| 2341 | 2343 | } |
| 2342 | 2344 | |
| 2343 | 2345 | $met_actions[] = $action; |
| 2344 | 2346 | unset( $action ); |
| 2345 | - } | |
| 2347 | + }//end foreach | |
| 2346 | 2348 | |
| 2347 | 2349 | $args['event'] = $event; |
| 2348 | 2350 | |
| 2349 | 2351 | /** |
| @@ -2532,9 +2534,9 @@ | ||
| 2532 | 2534 | add_filter( 'the_content', 'FrmFormsController::preview_content', 9999 ); |
| 2533 | 2535 | } |
| 2534 | 2536 | |
| 2535 | 2537 | $post = $old_post; |
| 2536 | - } | |
| 2538 | + }//end if | |
| 2537 | 2539 | } |
| 2538 | 2540 | |
| 2539 | 2541 | /** |
| 2540 | 2542 | * @since 3.0 |
| @@ -2555,14 +2557,16 @@ | ||
| 2555 | 2557 | $success_url = apply_filters( 'frm_redirect_url', $success_url, $args['form'], $args ); |
| 2556 | 2558 | |
| 2557 | 2559 | $doing_ajax = FrmAppHelper::doing_ajax(); |
| 2558 | 2560 | |
| 2559 | - 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. | |
| 2560 | 2563 | echo json_encode( self::get_ajax_redirect_response_data( $args + compact( 'success_url' ) ) ); |
| 2561 | 2564 | wp_die(); |
| 2562 | 2565 | } |
| 2563 | 2566 | |
| 2564 | - 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. | |
| 2565 | 2569 | if ( ! empty( $args['form']->options['open_in_new_tab'] ) ) { |
| 2566 | 2570 | self::print_open_in_new_tab_js_with_fallback_handler( $success_url, $args ); |
| 2567 | 2571 | self::$redirected_in_new_tab[ $args['form']->id ] = 1; |
| 2568 | 2572 | return; |
| @@ -2568,9 +2572,10 @@ | ||
| 2568 | 2572 | return; |
| 2569 | 2573 | } |
| 2570 | 2574 | |
| 2571 | 2575 | wp_redirect( esc_url_raw( $success_url ) ); |
| 2572 | - die(); // do not use wp_die or redirect fails | |
| 2576 | + // Do not use wp_die or redirect fails. | |
| 2577 | + die(); | |
| 2573 | 2578 | } |
| 2574 | 2579 | |
| 2575 | 2580 | // Redirect with a delay. |
| 2576 | 2581 | self::redirect_after_submit_using_js( $args + compact( 'success_url', 'doing_ajax' ) ); |
| @@ -2661,9 +2666,10 @@ | ||
| 2661 | 2666 | add_filter( 'frm_use_wpautop', '__return_true' ); |
| 2662 | 2667 | |
| 2663 | 2668 | echo FrmAppHelper::maybe_kses( $redirect_msg ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 2664 | 2669 | echo '<script>'; |
| 2665 | - 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. | |
| 2666 | 2672 | echo 'window.onload=function(){'; |
| 2667 | 2673 | } |
| 2668 | 2674 | echo 'setTimeout(function(){' . $redirect_js . '}, ' . intval( $delay_time ) . ');'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 2669 | 2675 | if ( empty( $args['doing_ajax'] ) ) { |
| @@ -2676,9 +2682,9 @@ | ||
| 2676 | 2682 | * @since 3.0 |
| 2677 | 2683 | * |
| 2678 | 2684 | * @param string $success_url |
| 2679 | 2685 | * @param string $success_msg |
| 2680 | - * @param array $args | |
| 2686 | + * @param array $args | |
| 2681 | 2687 | */ |
| 2682 | 2688 | private static function get_redirect_message( $success_url, $success_msg, $args ) { |
| 2683 | 2689 | $redirect_msg = '<div class="' . esc_attr( FrmFormsHelper::get_form_style_class( $args['form'] ) ) . '"><div class="frm-redirect-msg" role="status">' . $success_msg . '<br/>' . |
| 2684 | 2690 | self::get_redirect_fallback_message( $success_url, $args ) . |
| @@ -3015,9 +3021,9 @@ | ||
| 3015 | 3021 | * Create a page with an embedded formidable Gutenberg block. |
| 3016 | 3022 | * |
| 3017 | 3023 | * @since 5.2 |
| 3018 | 3024 | * |
| 3019 | - * @return never | |
| 3025 | + * @return void | |
| 3020 | 3026 | */ |
| 3021 | 3027 | public static function create_page_with_shortcode() { |
| 3022 | 3028 | if ( ! current_user_can( 'publish_posts' ) ) { |
| 3023 | 3029 | die( 0 ); |
| @@ -3062,10 +3068,9 @@ | ||
| 3062 | 3068 | |
| 3063 | 3069 | /** |
| 3064 | 3070 | * @since 5.3 |
| 3065 | 3071 | * |
| 3066 | - * @param string $content | |
| 3067 | - * @param int $form_id | |
| 3072 | + * @param int $form_id | |
| 3068 | 3073 | * @return string |
| 3069 | 3074 | */ |
| 3070 | 3075 | private static function get_page_shortcode_content_for_form( $form_id ) { |
| 3071 | 3076 | $shortcode = '[formidable id="' . $form_id . '"]'; |
| @@ -3076,9 +3081,9 @@ | ||
| 3076 | 3081 | |
| 3077 | 3082 | /** |
| 3078 | 3083 | * Get page dropdown for AJAX request for embedding form in an existing page. |
| 3079 | 3084 | * |
| 3080 | - * @return never | |
| 3085 | + * @return void | |
| 3081 | 3086 | */ |
| 3082 | 3087 | public static function get_page_dropdown() { |
| 3083 | 3088 | if ( ! current_user_can( 'publish_posts' ) ) { |
| 3084 | 3089 | die( 0 ); |
| @@ -3150,6 +3155,46 @@ | ||
| 3150 | 3155 | * @since 3.06 |
| 3151 | 3156 | */ |
| 3152 | 3157 | public static function add_new() { |
| 3153 | 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' ); | |
| 3154 | 3199 | } |
| 3155 | 3200 | } |