| @@ -6,9 +6,9 @@ | ||
| 6 | 6 | class FrmForm { |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * @param array $values |
| 10 | - * @return int|bool id on success or false on failure. | |
| 10 | + * @return bool|int id on success or false on failure. | |
| 11 | 11 | */ |
| 12 | 12 | public static function create( $values ) { |
| 13 | 13 | global $wpdb; |
| 14 | 14 | |
| @@ -69,9 +69,9 @@ | ||
| 69 | 69 | return FrmAppHelper::maybe_filter_array( $options, array( 'submit_value', 'success_msg', 'before_html', 'after_html' ) ); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
| 73 | - * @return int|boolean ID on success or false on failure | |
| 73 | + * @return bool|int ID on success or false on failure | |
| 74 | 74 | */ |
| 75 | 75 | public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) { |
| 76 | 76 | global $wpdb; |
| 77 | 77 | |
| @@ -93,10 +93,10 @@ | ||
| 93 | 93 | 'is_template' => $template ? 1 : 0, |
| 94 | 94 | ); |
| 95 | 95 | |
| 96 | 96 | if ( $blog_id ) { |
| 97 | - $new_values['status'] = 'published'; | |
| 98 | - $new_options = $values->options; | |
| 97 | + $new_values['status'] = 'published'; | |
| 98 | + $new_options = $values->options; | |
| 99 | 99 | FrmAppHelper::unserialize_or_decode( $new_options ); |
| 100 | 100 | $new_options['email_to'] = get_option( 'admin_email' ); |
| 101 | 101 | $new_options['copy'] = false; |
| 102 | 102 | $new_values['options'] = $new_options; |
| @@ -126,9 +126,9 @@ | ||
| 126 | 126 | return false; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | public static function after_duplicate( $form_id, $values ) { |
| 130 | - $new_opts = $values['options']; | |
| 130 | + $new_opts = $values['options']; | |
| 131 | 131 | FrmAppHelper::unserialize_or_decode( $new_opts ); |
| 132 | 132 | $values['options'] = $new_opts; |
| 133 | 133 | |
| 134 | 134 | if ( isset( $new_opts['success_msg'] ) ) { |
| @@ -158,9 +158,9 @@ | ||
| 158 | 158 | // Keys of fields that you want to check to replace field ID. |
| 159 | 159 | $keys = array( 'default_value', 'field_options' ); |
| 160 | 160 | $sql_cols = 'fi.id'; |
| 161 | 161 | foreach ( $keys as $key ) { |
| 162 | - $sql_cols .= ( ',fi.' . $key ); | |
| 162 | + $sql_cols .= ',fi.' . $key; | |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | $fields = FrmDb::get_results( |
| 166 | 166 | "{$wpdb->prefix}frm_fields AS fi LEFT OUTER JOIN {$wpdb->prefix}frm_forms AS fr ON fi.form_id = fr.id", |
| @@ -210,9 +210,9 @@ | ||
| 210 | 210 | |
| 211 | 211 | if ( $new_val !== $value ) { |
| 212 | 212 | $new_values[ $key ] = $new_val; |
| 213 | 213 | } |
| 214 | - } | |
| 214 | + }//end foreach | |
| 215 | 215 | |
| 216 | 216 | if ( ! empty( $new_values ) ) { |
| 217 | 217 | FrmField::update( $field['id'], $new_values ); |
| 218 | 218 | } |
| @@ -218,9 +218,9 @@ | ||
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
| 222 | - * @return int|boolean | |
| 222 | + * @return bool|int | |
| 223 | 223 | */ |
| 224 | 224 | public static function update( $id, $values, $create_link = false ) { |
| 225 | 225 | global $wpdb; |
| 226 | 226 | |
| @@ -243,9 +243,9 @@ | ||
| 243 | 243 | $new_values[ $value_key ] = $value; |
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) { | |
| 247 | + if ( ! empty( $values['new_status'] ) ) { | |
| 248 | 248 | $new_values['status'] = $values['new_status']; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | if ( ! empty( $new_values ) ) { |
| @@ -276,15 +276,15 @@ | ||
| 276 | 276 | if ( ! isset( $values['options'] ) ) { |
| 277 | 277 | return $new_values; |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - $options = isset( $values['options'] ) ? (array) $values['options'] : array(); | |
| 280 | + $options = ! empty( $values['options'] ) ? (array) $values['options'] : array(); | |
| 281 | 281 | FrmFormsHelper::fill_form_options( $options, $values ); |
| 282 | 282 | |
| 283 | 283 | $options['custom_style'] = isset( $values['options']['custom_style'] ) ? $values['options']['custom_style'] : 0; |
| 284 | 284 | $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' ); |
| 285 | 285 | $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' ); |
| 286 | - $options['submit_html'] = ( isset( $values['options']['submit_html'] ) && '' !== $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' ); | |
| 286 | + $options['submit_html'] = isset( $values['options']['submit_html'] ) && '' !== $values['options']['submit_html'] ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' ); | |
| 287 | 287 | |
| 288 | 288 | /** |
| 289 | 289 | * Allows modifying form options before updating or creating. |
| 290 | 290 | * |
| @@ -348,11 +348,12 @@ | ||
| 348 | 348 | continue; |
| 349 | 349 | } |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | - //updating the form | |
| 352 | + // Updating the form. | |
| 353 | 353 | $update_options = FrmFieldsHelper::get_default_field_options_from_field( $field ); |
| 354 | - unset( $update_options['custom_html'] ); // don't check for POST html | |
| 354 | + // Don't check for POST html. | |
| 355 | + unset( $update_options['custom_html'] ); | |
| 355 | 356 | $update_options = apply_filters( 'frm_field_options_to_update', $update_options ); |
| 356 | 357 | |
| 357 | 358 | foreach ( $update_options as $opt => $default ) { |
| 358 | 359 | $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? $values['field_options'][ $opt . '_' . $field_id ] : $default; |
| @@ -376,13 +377,14 @@ | ||
| 376 | 377 | } |
| 377 | 378 | } |
| 378 | 379 | |
| 379 | 380 | self::prepare_field_update_values( $field, $values, $new_field ); |
| 381 | + self::maybe_update_max_option( $field, $values, $new_field ); | |
| 380 | 382 | |
| 381 | 383 | FrmField::update( $field_id, $new_field ); |
| 382 | 384 | |
| 383 | 385 | FrmField::delete_form_transient( $field->form_id ); |
| 384 | - } | |
| 386 | + }//end foreach | |
| 385 | 387 | self::clear_form_cache(); |
| 386 | 388 | |
| 387 | 389 | return $values; |
| 388 | 390 | } |
| @@ -387,8 +389,33 @@ | ||
| 387 | 389 | return $values; |
| 388 | 390 | } |
| 389 | 391 | |
| 390 | 392 | /** |
| 393 | + * Resets the 'max' option of a field when changing paragraph field type to other field types like text, email etc. | |
| 394 | + * | |
| 395 | + * @since 6.7 | |
| 396 | + * | |
| 397 | + * @param array $field | |
| 398 | + * @param array $values | |
| 399 | + * @param array $new_field | |
| 400 | + * @return void | |
| 401 | + */ | |
| 402 | + private static function maybe_update_max_option( $field, $values, &$new_field ) { | |
| 403 | + if ( $field->type === 'textarea' && | |
| 404 | + ! empty( $values['field_options'][ 'type_' . $field->id ] ) && | |
| 405 | + in_array( $values['field_options'][ 'type_' . $field->id ], array( 'text', 'email', 'url', 'password', 'phone' ), true ) ) { | |
| 406 | + | |
| 407 | + $new_field['field_options']['max'] = ''; | |
| 408 | + | |
| 409 | + /** | |
| 410 | + * Update posted field setting so that new 'max' option is displayed after form is saved and page reloads. | |
| 411 | + * FrmFieldsHelper::fill_default_field_opts populates field options by calling self::get_posted_field_setting. | |
| 412 | + */ | |
| 413 | + $_POST['field_options'][ 'max_' . $field->id ] = ''; | |
| 414 | + } | |
| 415 | + } | |
| 416 | + | |
| 417 | + /** | |
| 391 | 418 | * @param string $opt |
| 392 | 419 | * @param mixed $value |
| 393 | 420 | * @return void |
| 394 | 421 | */ |
| @@ -428,9 +455,10 @@ | ||
| 428 | 455 | private static function sanitize_calc( $value ) { |
| 429 | 456 | if ( false !== strpos( $value, '<' ) ) { |
| 430 | 457 | $value = self::normalize_calc_spaces( $value ); |
| 431 | 458 | } |
| 432 | - $allow = array( '<= ', ' >=' ); // Allow <= and >= | |
| 459 | + // Allow <= and >=. | |
| 460 | + $allow = array( '<= ', ' >=' ); | |
| 433 | 461 | $temp = array( '< = ', ' > =' ); |
| 434 | 462 | $value = str_replace( $allow, $temp, $value ); |
| 435 | 463 | $value = strip_tags( $value ); |
| 436 | 464 | $value = str_replace( $temp, $allow, $value ); |
| @@ -462,9 +490,9 @@ | ||
| 462 | 490 | $prev_opts = array(); |
| 463 | 491 | $fallback_html = isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ); |
| 464 | 492 | |
| 465 | 493 | $field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ? $values['field_options'][ 'custom_html_' . $field->id ] : $fallback_html; |
| 466 | - } elseif ( $field->type == 'hidden' || $field->type == 'user_id' ) { | |
| 494 | + } elseif ( $field->type === 'hidden' || $field->type === 'user_id' ) { | |
| 467 | 495 | $prev_opts = $field->field_options; |
| 468 | 496 | } |
| 469 | 497 | |
| 470 | 498 | if ( isset( $prev_opts ) ) { |
| @@ -485,9 +513,9 @@ | ||
| 485 | 513 | 'options' => '', |
| 486 | 514 | 'name' => '', |
| 487 | 515 | ); |
| 488 | 516 | foreach ( $field_cols as $col => $default ) { |
| 489 | - $default = ( $default === '' ) ? $field->{$col} : $default; | |
| 517 | + $default = $default === '' ? $field->{$col} : $default; | |
| 490 | 518 | |
| 491 | 519 | $new_field[ $col ] = isset( $values['field_options'][ $col . '_' . $field->id ] ) ? $values['field_options'][ $col . '_' . $field->id ] : $default; |
| 492 | 520 | } |
| 493 | 521 | |
| @@ -501,9 +529,9 @@ | ||
| 501 | 529 | * Get a list of all form settings that should be translated |
| 502 | 530 | * on a multilingual site. |
| 503 | 531 | * |
| 504 | 532 | * @since 3.06.01 |
| 505 | - * @param object $form - The form object | |
| 533 | + * @param object $form The form object. | |
| 506 | 534 | */ |
| 507 | 535 | public static function translatable_strings( $form ) { |
| 508 | 536 | $strings = array( |
| 509 | 537 | 'name', |
| @@ -520,11 +548,12 @@ | ||
| 520 | 548 | return apply_filters( 'frm_form_strings', $strings, $form ); |
| 521 | 549 | } |
| 522 | 550 | |
| 523 | 551 | /** |
| 552 | + * @param int $id | |
| 524 | 553 | * @param string $status |
| 525 | 554 | * |
| 526 | - * @return int|boolean | |
| 555 | + * @return bool|int | |
| 527 | 556 | */ |
| 528 | 557 | public static function set_status( $id, $status ) { |
| 529 | 558 | if ( 'trash' == $status ) { |
| 530 | 559 | return self::trash( $id ); |
| @@ -530,9 +559,9 @@ | ||
| 530 | 559 | return self::trash( $id ); |
| 531 | 560 | } |
| 532 | 561 | |
| 533 | 562 | $statuses = array( 'published', 'draft', 'trash' ); |
| 534 | - if ( ! in_array( $status, $statuses ) ) { | |
| 563 | + if ( ! in_array( $status, $statuses, true ) ) { | |
| 535 | 564 | return false; |
| 536 | 565 | } |
| 537 | 566 | |
| 538 | 567 | global $wpdb; |
| @@ -559,9 +588,9 @@ | ||
| 559 | 588 | return $query_results; |
| 560 | 589 | } |
| 561 | 590 | |
| 562 | 591 | /** |
| 563 | - * @return int|boolean | |
| 592 | + * @return bool|int | |
| 564 | 593 | */ |
| 565 | 594 | public static function trash( $id ) { |
| 566 | 595 | if ( ! EMPTY_TRASH_DAYS ) { |
| 567 | 596 | return self::destroy( $id ); |
| @@ -605,9 +634,9 @@ | ||
| 605 | 634 | return $query_results; |
| 606 | 635 | } |
| 607 | 636 | |
| 608 | 637 | /** |
| 609 | - * @return int|boolean | |
| 638 | + * @return bool|int | |
| 610 | 639 | */ |
| 611 | 640 | public static function destroy( $id ) { |
| 612 | 641 | global $wpdb; |
| 613 | 642 | |
| @@ -650,9 +679,9 @@ | ||
| 650 | 679 | */ |
| 651 | 680 | public static function scheduled_delete( $delete_timestamp = '' ) { |
| 652 | 681 | global $wpdb; |
| 653 | 682 | |
| 654 | - $trash_forms = FrmDb::get_results( $wpdb->prefix . 'frm_forms', array( 'status' => 'trash' ), 'id, options' ); | |
| 683 | + $trash_forms = FrmDb::get_results( $wpdb->prefix . 'frm_forms', array( 'status' => 'trash' ), 'id, parent_form_id, options' ); | |
| 655 | 684 | |
| 656 | 685 | if ( ! $trash_forms ) { |
| 657 | 686 | return 0; |
| 658 | 687 | } |
| @@ -665,9 +694,11 @@ | ||
| 665 | 694 | foreach ( $trash_forms as $form ) { |
| 666 | 695 | FrmAppHelper::unserialize_or_decode( $form->options ); |
| 667 | 696 | if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) { |
| 668 | 697 | self::destroy( $form->id ); |
| 669 | - $count ++; | |
| 698 | + if ( empty( $form->parent_form_id ) ) { | |
| 699 | + ++$count; | |
| 700 | + } | |
| 670 | 701 | } |
| 671 | 702 | |
| 672 | 703 | unset( $form ); |
| 673 | 704 | } |
| @@ -687,10 +718,12 @@ | ||
| 687 | 718 | } |
| 688 | 719 | |
| 689 | 720 | $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
| 690 | 721 | $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
| 691 | - $r = stripslashes( $r ); | |
| 692 | 722 | |
| 723 | + // An empty form name can result in a null value. | |
| 724 | + $r = is_null( $r ) ? '' : stripslashes( $r ); | |
| 725 | + | |
| 693 | 726 | return $r; |
| 694 | 727 | } |
| 695 | 728 | |
| 696 | 729 | /** |
| @@ -725,11 +758,10 @@ | ||
| 725 | 758 | |
| 726 | 759 | /** |
| 727 | 760 | * If $form is numeric, get the form object |
| 728 | 761 | * |
| 729 | - * @param object|int $form | |
| 730 | - * | |
| 731 | 762 | * @since 2.0.9 |
| 763 | + * @param int|object $form | |
| 732 | 764 | */ |
| 733 | 765 | public static function maybe_get_form( &$form ) { |
| 734 | 766 | if ( ! is_object( $form ) && ! is_array( $form ) && ! empty( $form ) ) { |
| 735 | 767 | $form = self::getOne( $form ); |
| @@ -736,9 +768,11 @@ | ||
| 736 | 768 | } |
| 737 | 769 | } |
| 738 | 770 | |
| 739 | 771 | /** |
| 740 | - * @return object form | |
| 772 | + * @param int|string $id | |
| 773 | + * @param false|int $blog_id | |
| 774 | + * @return stdClass|null | |
| 741 | 775 | */ |
| 742 | 776 | public static function getOne( $id, $blog_id = false ) { |
| 743 | 777 | global $wpdb; |
| 744 | 778 | |
| @@ -753,10 +787,9 @@ | ||
| 753 | 787 | if ( $cache ) { |
| 754 | 788 | if ( isset( $cache->options ) ) { |
| 755 | 789 | FrmAppHelper::unserialize_or_decode( $cache->options ); |
| 756 | 790 | } |
| 757 | - | |
| 758 | - return apply_filters( 'frm_form_object', wp_unslash( $cache ) ); | |
| 791 | + return self::prepare_form_row_data( $cache ); | |
| 759 | 792 | } |
| 760 | 793 | } |
| 761 | 794 | |
| 762 | 795 | if ( is_numeric( $id ) ) { |
| @@ -771,14 +804,40 @@ | ||
| 771 | 804 | FrmDb::set_cache( $results->id, $results, 'frm_form' ); |
| 772 | 805 | FrmAppHelper::unserialize_or_decode( $results->options ); |
| 773 | 806 | } |
| 774 | 807 | |
| 775 | - return apply_filters( 'frm_form_object', wp_unslash( $results ) ); | |
| 808 | + return self::prepare_form_row_data( $results ); | |
| 776 | 809 | } |
| 777 | 810 | |
| 778 | 811 | /** |
| 779 | - * @return object|array of objects | |
| 812 | + * Make sure that if $row is an object, that $row->options is an array and not a string. | |
| 813 | + * | |
| 814 | + * @since 6.8.3 | |
| 815 | + * | |
| 816 | + * @param stdClass|null $row The database row for a target form. | |
| 817 | + * @return stdClass|null | |
| 780 | 818 | */ |
| 819 | + private static function prepare_form_row_data( $row ) { | |
| 820 | + $row = wp_unslash( $row ); | |
| 821 | + if ( ! is_object( $row ) ) { | |
| 822 | + return $row; | |
| 823 | + } | |
| 824 | + | |
| 825 | + if ( ! is_array( $row->options ) ) { | |
| 826 | + $row->options = FrmFormsHelper::get_default_opts(); | |
| 827 | + } | |
| 828 | + | |
| 829 | + /** | |
| 830 | + * @since 4.03.02 | |
| 831 | + * | |
| 832 | + * @param stdClass $row | |
| 833 | + */ | |
| 834 | + return apply_filters( 'frm_form_object', $row ); | |
| 835 | + } | |
| 836 | + | |
| 837 | + /** | |
| 838 | + * @return array|object of objects | |
| 839 | + */ | |
| 781 | 840 | public static function getAll( $where = array(), $order_by = '', $limit = '' ) { |
| 782 | 841 | if ( is_array( $where ) && ! empty( $where ) ) { |
| 783 | 842 | if ( isset( $where['is_template'] ) && $where['is_template'] && ! isset( $where['status'] ) && ! isset( $where['status !'] ) ) { |
| 784 | 843 | // don't get trashed templates |
| @@ -788,9 +847,9 @@ | ||
| 788 | 847 | $results = FrmDb::get_results( 'frm_forms', $where, '*', compact( 'order_by', 'limit' ) ); |
| 789 | 848 | } else { |
| 790 | 849 | global $wpdb; |
| 791 | 850 | |
| 792 | - // the query has already been prepared if this is not an array | |
| 851 | + // The query has already been prepared if this is not an array. | |
| 793 | 852 | $query = 'SELECT * FROM ' . $wpdb->prefix . 'frm_forms' . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . FrmDb::esc_order( $order_by ) . FrmDb::esc_limit( $limit ); |
| 794 | 853 | $results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 795 | 854 | } |
| 796 | 855 | |
| @@ -800,9 +859,9 @@ | ||
| 800 | 859 | FrmAppHelper::unserialize_or_decode( $result->options ); |
| 801 | 860 | } |
| 802 | 861 | } |
| 803 | 862 | |
| 804 | - if ( $limit == ' LIMIT 1' || $limit == 1 ) { | |
| 863 | + if ( $limit === ' LIMIT 1' || $limit == 1 ) { | |
| 805 | 864 | // return the first form object if we are only getting one form |
| 806 | 865 | $results = reset( $results ); |
| 807 | 866 | } |
| 808 | 867 | |
| @@ -821,9 +880,9 @@ | ||
| 821 | 880 | */ |
| 822 | 881 | public static function get_published_forms( $query = array(), $limit = 999, $inc_children = 'exclude' ) { |
| 823 | 882 | $query['is_template'] = 0; |
| 824 | 883 | $query['status'] = array( null, '', 'published' ); |
| 825 | - if ( $inc_children == 'exclude' ) { | |
| 884 | + if ( $inc_children === 'exclude' ) { | |
| 826 | 885 | $query['parent_form_id'] = array( null, 0 ); |
| 827 | 886 | } |
| 828 | 887 | |
| 829 | 888 | $forms = self::getAll( $query, 'name', $limit ); |
| @@ -859,18 +918,18 @@ | ||
| 859 | 918 | |
| 860 | 919 | foreach ( $results as $row ) { |
| 861 | 920 | if ( 'trash' != $row->status ) { |
| 862 | 921 | if ( $row->is_template ) { |
| 863 | - $counts['template'] ++; | |
| 922 | + ++$counts['template']; | |
| 864 | 923 | } else { |
| 865 | - $counts['published'] ++; | |
| 924 | + ++$counts['published']; | |
| 866 | 925 | } |
| 867 | 926 | } else { |
| 868 | - $counts['trash'] ++; | |
| 927 | + ++$counts['trash']; | |
| 869 | 928 | } |
| 870 | 929 | |
| 871 | 930 | if ( 'draft' == $row->status ) { |
| 872 | - $counts['draft'] ++; | |
| 931 | + ++$counts['draft']; | |
| 873 | 932 | } |
| 874 | 933 | |
| 875 | 934 | unset( $row ); |
| 876 | 935 | } |
| @@ -936,11 +995,11 @@ | ||
| 936 | 995 | $values['posted_form_id'] = FrmAppHelper::get_param( 'form', '', 'get', 'absint' ); |
| 937 | 996 | } |
| 938 | 997 | |
| 939 | 998 | if ( $form->id == $values['posted_form_id'] ) { |
| 940 | - //if there are two forms on the same page, make sure not to submit both | |
| 999 | + // If there are two forms on the same page, make sure not to submit both. | |
| 941 | 1000 | foreach ( $default_values as $var => $default ) { |
| 942 | - if ( $var == 'action' ) { | |
| 1001 | + if ( $var === 'action' ) { | |
| 943 | 1002 | $values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
| 944 | 1003 | } else { |
| 945 | 1004 | $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
| 946 | 1005 | } |
| @@ -1008,9 +1067,9 @@ | ||
| 1008 | 1067 | return $values; |
| 1009 | 1068 | } |
| 1010 | 1069 | |
| 1011 | 1070 | public static function get_current_form_id( $default_form = 'none' ) { |
| 1012 | - if ( 'first' == $default_form ) { | |
| 1071 | + if ( 'first' === $default_form ) { | |
| 1013 | 1072 | $form = self::get_current_form(); |
| 1014 | 1073 | } else { |
| 1015 | 1074 | $form = self::maybe_get_current_form(); |
| 1016 | 1075 | } |
| @@ -1091,9 +1150,9 @@ | ||
| 1091 | 1150 | return $visible; |
| 1092 | 1151 | } |
| 1093 | 1152 | |
| 1094 | 1153 | public static function show_submit( $form ) { |
| 1095 | - $show = ( ! $form->is_template && $form->status == 'published' && ! FrmAppHelper::is_admin() ); | |
| 1154 | + $show = ( ! $form->is_template && $form->status === 'published' && ! FrmAppHelper::is_admin() ); | |
| 1096 | 1155 | $show = apply_filters( 'frm_show_submit_button', $show, $form ); |
| 1097 | 1156 | |
| 1098 | 1157 | return $show; |
| 1099 | 1158 | } |
| @@ -1101,9 +1160,9 @@ | ||
| 1101 | 1160 | /** |
| 1102 | 1161 | * @since 2.3 |
| 1103 | 1162 | */ |
| 1104 | 1163 | public static function get_option( $atts ) { |
| 1105 | - $form = $atts['form']; | |
| 1164 | + $form = $atts['form']; | |
| 1106 | 1165 | $default = isset( $atts['default'] ) ? $atts['default'] : ''; |
| 1107 | 1166 | |
| 1108 | 1167 | return isset( $form->options[ $atts['option'] ] ) ? $form->options[ $atts['option'] ] : $default; |
| 1109 | 1168 | } |
| @@ -1130,8 +1189,50 @@ | ||
| 1130 | 1189 | return ! empty( $form->options['ajax_submit'] ); |
| 1131 | 1190 | } |
| 1132 | 1191 | |
| 1133 | 1192 | /** |
| 1193 | + * Get the latest form available. | |
| 1194 | + * | |
| 1195 | + * @since 6.8 | |
| 1196 | + * @return object | |
| 1197 | + */ | |
| 1198 | + public static function get_latest_form() { | |
| 1199 | + | |
| 1200 | + $args = array( | |
| 1201 | + array( | |
| 1202 | + 'or' => 1, | |
| 1203 | + 'parent_form_id' => null, | |
| 1204 | + 'parent_form_id <' => 1, | |
| 1205 | + ), | |
| 1206 | + 'is_template' => 0, | |
| 1207 | + 'status !' => 'trash', | |
| 1208 | + ); | |
| 1209 | + | |
| 1210 | + return self::getAll( $args, 'created_at desc', 1 ); | |
| 1211 | + } | |
| 1212 | + | |
| 1213 | + /** | |
| 1214 | + * Count and return total forms. | |
| 1215 | + * | |
| 1216 | + * @since 6.8 | |
| 1217 | + * @return int | |
| 1218 | + */ | |
| 1219 | + public static function get_forms_count() { | |
| 1220 | + | |
| 1221 | + $args = array( | |
| 1222 | + array( | |
| 1223 | + 'or' => 1, | |
| 1224 | + 'parent_form_id' => null, | |
| 1225 | + 'parent_form_id <' => 1, | |
| 1226 | + ), | |
| 1227 | + 'is_template' => 0, | |
| 1228 | + 'status !' => 'trash', | |
| 1229 | + ); | |
| 1230 | + | |
| 1231 | + return FrmDb::get_count( 'frm_forms', $args ); | |
| 1232 | + } | |
| 1233 | + | |
| 1234 | + /** | |
| 1134 | 1235 | * @deprecated 2.03.05 This is still referenced in a few add ons (API, locations). |
| 1135 | 1236 | * @codeCoverageIgnore |
| 1136 | 1237 | * |
| 1137 | 1238 | * @param string $key |
| @@ -1145,9 +1246,9 @@ | ||
| 1145 | 1246 | /** |
| 1146 | 1247 | * @deprecated 2.03.05 This is still referenced in the API add on as of v1.13. |
| 1147 | 1248 | * @codeCoverageIgnore |
| 1148 | 1249 | * |
| 1149 | - * @param string|int $id | |
| 1250 | + * @param int|string $id | |
| 1150 | 1251 | * @return string |
| 1151 | 1252 | */ |
| 1152 | 1253 | public static function getKeyById( $id ) { |
| 1153 | 1254 | _deprecated_function( __FUNCTION__, '2.03.05', 'FrmForm::get_key_by_id' ); |