| @@ -6,9 +6,9 @@ | ||
| 6 | 6 | class FrmForm { |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * @param array $values |
| 10 | - * @return bool|int id on success or false on failure. | |
| 10 | + * @return int|bool id on success or false on failure. | |
| 11 | 11 | */ |
| 12 | 12 | public static function create( $values ) { |
| 13 | 13 | global $wpdb; |
| 14 | 14 | |
| @@ -17,22 +17,22 @@ | ||
| 17 | 17 | $new_values = array( |
| 18 | 18 | 'form_key' => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ), |
| 19 | 19 | 'name' => $values['name'], |
| 20 | 20 | 'description' => $values['description'], |
| 21 | - 'status' => $values['status'] ?? 'published', | |
| 22 | - 'logged_in' => $values['logged_in'] ?? 0, | |
| 21 | + 'status' => isset( $values['status'] ) ? $values['status'] : 'published', | |
| 22 | + 'logged_in' => isset( $values['logged_in'] ) ? $values['logged_in'] : 0, | |
| 23 | 23 | 'is_template' => isset( $values['is_template'] ) ? (int) $values['is_template'] : 0, |
| 24 | 24 | 'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0, |
| 25 | 25 | 'editable' => isset( $values['editable'] ) ? (int) $values['editable'] : 0, |
| 26 | - 'created_at' => $values['created_at'] ?? current_time( 'mysql', 1 ), | |
| 26 | + 'created_at' => isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 ), | |
| 27 | 27 | ); |
| 28 | 28 | |
| 29 | 29 | $options = isset( $values['options'] ) ? (array) $values['options'] : array(); |
| 30 | 30 | FrmFormsHelper::fill_form_options( $options, $values ); |
| 31 | 31 | |
| 32 | - $options['before_html'] = $values['options']['before_html'] ?? FrmFormsHelper::get_default_html( 'before' ); | |
| 33 | - $options['after_html'] = $values['options']['after_html'] ?? FrmFormsHelper::get_default_html( 'after' ); | |
| 34 | - $options['submit_html'] = $values['options']['submit_html'] ?? FrmFormsHelper::get_default_html( 'submit' ); | |
| 32 | + $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' ); | |
| 33 | + $options['after_html'] = isset( $values['options']['after_html'] ) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html( 'after' ); | |
| 34 | + $options['submit_html'] = isset( $values['options']['submit_html'] ) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' ); | |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Allows modifying form options before updating or creating. |
| 38 | 38 | * |
| @@ -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 bool|int ID on success or false on failure | |
| 73 | + * @return int|boolean 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 | - }//end foreach | |
| 214 | + } | |
| 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 bool|int | |
| 222 | + * @return int|boolean | |
| 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 ( ! empty( $values['new_status'] ) ) { | |
| 247 | + if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) { | |
| 248 | 248 | $new_values['status'] = $values['new_status']; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | if ( ! empty( $new_values ) ) { |
| @@ -276,16 +276,21 @@ | ||
| 276 | 276 | if ( ! isset( $values['options'] ) ) { |
| 277 | 277 | return $new_values; |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - $options = ! empty( $values['options'] ) ? (array) $values['options'] : array(); | |
| 280 | + $options = isset( $values['options'] ) ? (array) $values['options'] : array(); | |
| 281 | 281 | FrmFormsHelper::fill_form_options( $options, $values ); |
| 282 | 282 | |
| 283 | - $options['custom_style'] = $values['options']['custom_style'] ?? 0; | |
| 284 | - $options['before_html'] = $values['options']['before_html'] ?? FrmFormsHelper::get_default_html( 'before' ); | |
| 285 | - $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' ); | |
| 283 | + $options['custom_style'] = isset( $values['options']['custom_style'] ) ? $values['options']['custom_style'] : 0; | |
| 284 | + $options['before_html'] = isset( $values['options']['before_html'] ) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html( 'before' ); | |
| 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' ); | |
| 287 | 287 | |
| 288 | + if ( ! empty( $options['success_url'] ) && ! empty( $args['form_id'] ) ) { | |
| 289 | + $options['success_url'] = FrmFormsHelper::maybe_add_sanitize_url_attr( $options['success_url'], (int) $args['form_id'] ); | |
| 290 | + $values['options']['success_url'] = $options['success_url']; | |
| 291 | + } | |
| 292 | + | |
| 288 | 293 | /** |
| 289 | 294 | * Allows modifying form options before updating or creating. |
| 290 | 295 | * |
| 291 | 296 | * @since 5.4 Added the third param. |
| @@ -348,20 +353,15 @@ | ||
| 348 | 353 | continue; |
| 349 | 354 | } |
| 350 | 355 | } |
| 351 | 356 | |
| 352 | - // Updating the form. | |
| 357 | + //updating the form | |
| 353 | 358 | $update_options = FrmFieldsHelper::get_default_field_options_from_field( $field ); |
| 354 | - // Don't check for POST html. | |
| 355 | - unset( $update_options['custom_html'] ); | |
| 359 | + unset( $update_options['custom_html'] ); // don't check for POST html | |
| 356 | 360 | $update_options = apply_filters( 'frm_field_options_to_update', $update_options ); |
| 357 | 361 | |
| 358 | - if ( ! is_array( $field->field_options ) ) { | |
| 359 | - $field->field_options = array(); | |
| 360 | - } | |
| 361 | - | |
| 362 | 362 | foreach ( $update_options as $opt => $default ) { |
| 363 | - $field->field_options[ $opt ] = $values['field_options'][ $opt . '_' . $field_id ] ?? $default; | |
| 363 | + $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? $values['field_options'][ $opt . '_' . $field_id ] : $default; | |
| 364 | 364 | self::sanitize_field_opt( $opt, $field->field_options[ $opt ] ); |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values ); |
| @@ -370,25 +370,14 @@ | ||
| 370 | 370 | 'field_options' => $field->field_options, |
| 371 | 371 | 'default_value' => isset( $values[ 'default_value_' . $field_id ] ) ? FrmAppHelper::maybe_json_encode( $values[ 'default_value_' . $field_id ] ) : '', |
| 372 | 372 | ); |
| 373 | 373 | |
| 374 | - if ( ! FrmAppHelper::allow_unfiltered_html() && isset( $values['field_options'][ 'options_' . $field_id ] ) && is_array( $values['field_options'][ 'options_' . $field_id ] ) ) { | |
| 375 | - foreach ( $values['field_options'][ 'options_' . $field_id ] as $option_key => $option ) { | |
| 376 | - if ( is_array( $option ) ) { | |
| 377 | - foreach ( $option as $key => $item ) { | |
| 378 | - $values['field_options'][ 'options_' . $field_id ][ $option_key ][ $key ] = FrmAppHelper::kses( $item, 'all' ); | |
| 379 | - } | |
| 380 | - } | |
| 381 | - } | |
| 382 | - } | |
| 383 | - | |
| 384 | 374 | self::prepare_field_update_values( $field, $values, $new_field ); |
| 385 | - self::maybe_update_max_option( $field, $values, $new_field ); | |
| 386 | 375 | |
| 387 | 376 | FrmField::update( $field_id, $new_field ); |
| 388 | 377 | |
| 389 | 378 | FrmField::delete_form_transient( $field->form_id ); |
| 390 | - }//end foreach | |
| 379 | + } | |
| 391 | 380 | self::clear_form_cache(); |
| 392 | 381 | |
| 393 | 382 | return $values; |
| 394 | 383 | } |
| @@ -393,33 +382,8 @@ | ||
| 393 | 382 | return $values; |
| 394 | 383 | } |
| 395 | 384 | |
| 396 | 385 | /** |
| 397 | - * Resets the 'max' option of a field when changing paragraph field type to other field types like text, email etc. | |
| 398 | - * | |
| 399 | - * @since 6.7 | |
| 400 | - * | |
| 401 | - * @param array $field | |
| 402 | - * @param array $values | |
| 403 | - * @param array $new_field | |
| 404 | - * @return void | |
| 405 | - */ | |
| 406 | - private static function maybe_update_max_option( $field, $values, &$new_field ) { | |
| 407 | - if ( $field->type === 'textarea' && | |
| 408 | - ! empty( $values['field_options'][ 'type_' . $field->id ] ) && | |
| 409 | - in_array( $values['field_options'][ 'type_' . $field->id ], array( 'text', 'email', 'url', 'password', 'phone' ), true ) ) { | |
| 410 | - | |
| 411 | - $new_field['field_options']['max'] = ''; | |
| 412 | - | |
| 413 | - /** | |
| 414 | - * Update posted field setting so that new 'max' option is displayed after form is saved and page reloads. | |
| 415 | - * FrmFieldsHelper::fill_default_field_opts populates field options by calling self::get_posted_field_setting. | |
| 416 | - */ | |
| 417 | - $_POST['field_options'][ 'max_' . $field->id ] = ''; | |
| 418 | - } | |
| 419 | - } | |
| 420 | - | |
| 421 | - /** | |
| 422 | 386 | * @param string $opt |
| 423 | 387 | * @param mixed $value |
| 424 | 388 | * @return void |
| 425 | 389 | */ |
| @@ -459,10 +423,9 @@ | ||
| 459 | 423 | private static function sanitize_calc( $value ) { |
| 460 | 424 | if ( false !== strpos( $value, '<' ) ) { |
| 461 | 425 | $value = self::normalize_calc_spaces( $value ); |
| 462 | 426 | } |
| 463 | - // Allow <= and >=. | |
| 464 | - $allow = array( '<= ', ' >=' ); | |
| 427 | + $allow = array( '<= ', ' >=' ); // Allow <= and >= | |
| 465 | 428 | $temp = array( '< = ', ' > =' ); |
| 466 | 429 | $value = str_replace( $allow, $temp, $value ); |
| 467 | 430 | $value = strip_tags( $value ); |
| 468 | 431 | $value = str_replace( $temp, $allow, $value ); |
| @@ -477,16 +440,14 @@ | ||
| 477 | 440 | * @return string |
| 478 | 441 | */ |
| 479 | 442 | private static function normalize_calc_spaces( $calc ) { |
| 480 | 443 | // Check for a pattern with 5 parts |
| 481 | - // $1 \d|\] the first comparison digit or the end of a comparison shortcode. | |
| 444 | + // $1 \d the first comparison digit. | |
| 482 | 445 | // $2 a space (optional). |
| 483 | 446 | // $3 an equals sign (optional) that follows the < operator for <= comparisons. |
| 484 | 447 | // $4 another space (optional). |
| 485 | - // $5 \d|\[ the second comparison digit or the start of a comparison shortcode. | |
| 486 | - $calc = preg_replace( '/(\d|\])( ){0,1}<(=){0,1}( ){0,1}(\d|\[)/', '$1 <$3 $5', $calc ); | |
| 487 | - | |
| 488 | - return $calc; | |
| 448 | + // $5 \d the second comparison digit. | |
| 449 | + return preg_replace( '/(\d)( ){0,1}<(=){0,1}( ){0,1}(\d)/', '$1 <$3 $5', $calc ); | |
| 489 | 450 | } |
| 490 | 451 | |
| 491 | 452 | /** |
| 492 | 453 | * Updating the settings page |
| @@ -493,12 +454,12 @@ | ||
| 493 | 454 | */ |
| 494 | 455 | private static function get_settings_page_html( $values, &$field ) { |
| 495 | 456 | if ( isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ) { |
| 496 | 457 | $prev_opts = array(); |
| 497 | - $fallback_html = $field->field_options['custom_html'] ?? FrmFieldsHelper::get_default_html( $field->type ); | |
| 458 | + $fallback_html = isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ); | |
| 498 | 459 | |
| 499 | - $field->field_options['custom_html'] = $values['field_options'][ 'custom_html_' . $field->id ] ?? $fallback_html; | |
| 500 | - } elseif ( $field->type === 'hidden' || $field->type === 'user_id' ) { | |
| 460 | + $field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ? $values['field_options'][ 'custom_html_' . $field->id ] : $fallback_html; | |
| 461 | + } elseif ( $field->type == 'hidden' || $field->type == 'user_id' ) { | |
| 501 | 462 | $prev_opts = $field->field_options; |
| 502 | 463 | } |
| 503 | 464 | |
| 504 | 465 | if ( isset( $prev_opts ) ) { |
| @@ -519,14 +480,11 @@ | ||
| 519 | 480 | 'options' => '', |
| 520 | 481 | 'name' => '', |
| 521 | 482 | ); |
| 522 | 483 | foreach ( $field_cols as $col => $default ) { |
| 523 | - $default = $default === '' ? $field->{$col} : $default; | |
| 524 | - $new_field[ $col ] = $values['field_options'][ $col . '_' . $field->id ] ?? $default; | |
| 525 | - } | |
| 484 | + $default = ( $default === '' ) ? $field->{$col} : $default; | |
| 526 | 485 | |
| 527 | - if ( $field->type === 'submit' && isset( $new_field['field_order'] ) && (int) $new_field['field_order'] === FrmSubmitHelper::DEFAULT_ORDER ) { | |
| 528 | - $new_field['field_order'] = $field->field_order; | |
| 486 | + $new_field[ $col ] = isset( $values['field_options'][ $col . '_' . $field->id ] ) ? $values['field_options'][ $col . '_' . $field->id ] : $default; | |
| 529 | 487 | } |
| 530 | 488 | |
| 531 | 489 | // Don't save the template option. |
| 532 | 490 | if ( is_array( $new_field['options'] ) && isset( $new_field['options']['000'] ) ) { |
| @@ -538,9 +496,9 @@ | ||
| 538 | 496 | * Get a list of all form settings that should be translated |
| 539 | 497 | * on a multilingual site. |
| 540 | 498 | * |
| 541 | 499 | * @since 3.06.01 |
| 542 | - * @param object $form The form object. | |
| 500 | + * @param object $form - The form object | |
| 543 | 501 | */ |
| 544 | 502 | public static function translatable_strings( $form ) { |
| 545 | 503 | $strings = array( |
| 546 | 504 | 'name', |
| @@ -557,12 +515,11 @@ | ||
| 557 | 515 | return apply_filters( 'frm_form_strings', $strings, $form ); |
| 558 | 516 | } |
| 559 | 517 | |
| 560 | 518 | /** |
| 561 | - * @param int $id | |
| 562 | 519 | * @param string $status |
| 563 | 520 | * |
| 564 | - * @return bool|int | |
| 521 | + * @return int|boolean | |
| 565 | 522 | */ |
| 566 | 523 | public static function set_status( $id, $status ) { |
| 567 | 524 | if ( 'trash' == $status ) { |
| 568 | 525 | return self::trash( $id ); |
| @@ -568,9 +525,9 @@ | ||
| 568 | 525 | return self::trash( $id ); |
| 569 | 526 | } |
| 570 | 527 | |
| 571 | 528 | $statuses = array( 'published', 'draft', 'trash' ); |
| 572 | - if ( ! in_array( $status, $statuses, true ) ) { | |
| 529 | + if ( ! in_array( $status, $statuses ) ) { | |
| 573 | 530 | return false; |
| 574 | 531 | } |
| 575 | 532 | |
| 576 | 533 | global $wpdb; |
| @@ -597,9 +554,9 @@ | ||
| 597 | 554 | return $query_results; |
| 598 | 555 | } |
| 599 | 556 | |
| 600 | 557 | /** |
| 601 | - * @return bool|int | |
| 558 | + * @return int|boolean | |
| 602 | 559 | */ |
| 603 | 560 | public static function trash( $id ) { |
| 604 | 561 | if ( ! EMPTY_TRASH_DAYS ) { |
| 605 | 562 | return self::destroy( $id ); |
| @@ -609,12 +566,8 @@ | ||
| 609 | 566 | if ( ! $form ) { |
| 610 | 567 | return false; |
| 611 | 568 | } |
| 612 | 569 | |
| 613 | - if ( $form->status === 'trash' ) { | |
| 614 | - return false; | |
| 615 | - } | |
| 616 | - | |
| 617 | 570 | $options = $form->options; |
| 618 | 571 | $options['trash_time'] = time(); |
| 619 | 572 | |
| 620 | 573 | global $wpdb; |
| @@ -647,9 +600,9 @@ | ||
| 647 | 600 | return $query_results; |
| 648 | 601 | } |
| 649 | 602 | |
| 650 | 603 | /** |
| 651 | - * @return bool|int | |
| 604 | + * @return int|boolean | |
| 652 | 605 | */ |
| 653 | 606 | public static function destroy( $id ) { |
| 654 | 607 | global $wpdb; |
| 655 | 608 | |
| @@ -671,11 +624,8 @@ | ||
| 671 | 624 | |
| 672 | 625 | $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) ); |
| 673 | 626 | if ( $query_results ) { |
| 674 | 627 | // Delete all form actions linked to this form |
| 675 | - /** | |
| 676 | - * @var FrmFormAction | |
| 677 | - */ | |
| 678 | 628 | $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
| 679 | 629 | $action_control->destroy( $id, 'all' ); |
| 680 | 630 | |
| 681 | 631 | // Clear form caching |
| @@ -695,9 +645,9 @@ | ||
| 695 | 645 | */ |
| 696 | 646 | public static function scheduled_delete( $delete_timestamp = '' ) { |
| 697 | 647 | global $wpdb; |
| 698 | 648 | |
| 699 | - $trash_forms = FrmDb::get_results( $wpdb->prefix . 'frm_forms', array( 'status' => 'trash' ), 'id, parent_form_id, options' ); | |
| 649 | + $trash_forms = FrmDb::get_results( $wpdb->prefix . 'frm_forms', array( 'status' => 'trash' ), 'id, options' ); | |
| 700 | 650 | |
| 701 | 651 | if ( ! $trash_forms ) { |
| 702 | 652 | return 0; |
| 703 | 653 | } |
| @@ -710,11 +660,9 @@ | ||
| 710 | 660 | foreach ( $trash_forms as $form ) { |
| 711 | 661 | FrmAppHelper::unserialize_or_decode( $form->options ); |
| 712 | 662 | if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) { |
| 713 | 663 | self::destroy( $form->id ); |
| 714 | - if ( empty( $form->parent_form_id ) ) { | |
| 715 | - ++$count; | |
| 716 | - } | |
| 664 | + $count ++; | |
| 717 | 665 | } |
| 718 | 666 | |
| 719 | 667 | unset( $form ); |
| 720 | 668 | } |
| @@ -734,12 +682,10 @@ | ||
| 734 | 682 | } |
| 735 | 683 | |
| 736 | 684 | $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
| 737 | 685 | $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
| 686 | + $r = stripslashes( $r ); | |
| 738 | 687 | |
| 739 | - // An empty form name can result in a null value. | |
| 740 | - $r = is_null( $r ) ? '' : stripslashes( $r ); | |
| 741 | - | |
| 742 | 688 | return $r; |
| 743 | 689 | } |
| 744 | 690 | |
| 745 | 691 | /** |
| @@ -774,10 +720,11 @@ | ||
| 774 | 720 | |
| 775 | 721 | /** |
| 776 | 722 | * If $form is numeric, get the form object |
| 777 | 723 | * |
| 724 | + * @param object|int $form | |
| 725 | + * | |
| 778 | 726 | * @since 2.0.9 |
| 779 | - * @param int|object $form | |
| 780 | 727 | */ |
| 781 | 728 | public static function maybe_get_form( &$form ) { |
| 782 | 729 | if ( ! is_object( $form ) && ! is_array( $form ) && ! empty( $form ) ) { |
| 783 | 730 | $form = self::getOne( $form ); |
| @@ -784,11 +731,9 @@ | ||
| 784 | 731 | } |
| 785 | 732 | } |
| 786 | 733 | |
| 787 | 734 | /** |
| 788 | - * @param int|string $id | |
| 789 | - * @param false|int $blog_id | |
| 790 | - * @return stdClass|null | |
| 735 | + * @return object form | |
| 791 | 736 | */ |
| 792 | 737 | public static function getOne( $id, $blog_id = false ) { |
| 793 | 738 | global $wpdb; |
| 794 | 739 | |
| @@ -803,9 +748,10 @@ | ||
| 803 | 748 | if ( $cache ) { |
| 804 | 749 | if ( isset( $cache->options ) ) { |
| 805 | 750 | FrmAppHelper::unserialize_or_decode( $cache->options ); |
| 806 | 751 | } |
| 807 | - return self::prepare_form_row_data( $cache ); | |
| 752 | + | |
| 753 | + return apply_filters( 'frm_form_object', wp_unslash( $cache ) ); | |
| 808 | 754 | } |
| 809 | 755 | } |
| 810 | 756 | |
| 811 | 757 | if ( is_numeric( $id ) ) { |
| @@ -820,43 +766,17 @@ | ||
| 820 | 766 | FrmDb::set_cache( $results->id, $results, 'frm_form' ); |
| 821 | 767 | FrmAppHelper::unserialize_or_decode( $results->options ); |
| 822 | 768 | } |
| 823 | 769 | |
| 824 | - return self::prepare_form_row_data( $results ); | |
| 770 | + return apply_filters( 'frm_form_object', wp_unslash( $results ) ); | |
| 825 | 771 | } |
| 826 | 772 | |
| 827 | 773 | /** |
| 828 | - * Make sure that if $row is an object, that $row->options is an array and not a string. | |
| 829 | - * | |
| 830 | - * @since 6.8.3 | |
| 831 | - * | |
| 832 | - * @param stdClass|null $row The database row for a target form. | |
| 833 | - * @return stdClass|null | |
| 774 | + * @return object|array of objects | |
| 834 | 775 | */ |
| 835 | - private static function prepare_form_row_data( $row ) { | |
| 836 | - $row = wp_unslash( $row ); | |
| 837 | - if ( ! is_object( $row ) ) { | |
| 838 | - return $row; | |
| 839 | - } | |
| 840 | - | |
| 841 | - if ( ! is_array( $row->options ) ) { | |
| 842 | - $row->options = FrmFormsHelper::get_default_opts(); | |
| 843 | - } | |
| 844 | - | |
| 845 | - /** | |
| 846 | - * @since 4.03.02 | |
| 847 | - * | |
| 848 | - * @param stdClass $row | |
| 849 | - */ | |
| 850 | - return apply_filters( 'frm_form_object', $row ); | |
| 851 | - } | |
| 852 | - | |
| 853 | - /** | |
| 854 | - * @return array|object of objects | |
| 855 | - */ | |
| 856 | 776 | public static function getAll( $where = array(), $order_by = '', $limit = '' ) { |
| 857 | 777 | if ( is_array( $where ) && ! empty( $where ) ) { |
| 858 | - if ( ! empty( $where['is_template'] ) && ! isset( $where['status'] ) && ! isset( $where['status !'] ) ) { | |
| 778 | + if ( isset( $where['is_template'] ) && $where['is_template'] && ! isset( $where['status'] ) && ! isset( $where['status !'] ) ) { | |
| 859 | 779 | // don't get trashed templates |
| 860 | 780 | $where['status'] = array( null, '', 'published' ); |
| 861 | 781 | } |
| 862 | 782 | |
| @@ -863,9 +783,9 @@ | ||
| 863 | 783 | $results = FrmDb::get_results( 'frm_forms', $where, '*', compact( 'order_by', 'limit' ) ); |
| 864 | 784 | } else { |
| 865 | 785 | global $wpdb; |
| 866 | 786 | |
| 867 | - // The query has already been prepared if this is not an array. | |
| 787 | + // the query has already been prepared if this is not an array | |
| 868 | 788 | $query = 'SELECT * FROM ' . $wpdb->prefix . 'frm_forms' . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . FrmDb::esc_order( $order_by ) . FrmDb::esc_limit( $limit ); |
| 869 | 789 | $results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 870 | 790 | } |
| 871 | 791 | |
| @@ -875,9 +795,9 @@ | ||
| 875 | 795 | FrmAppHelper::unserialize_or_decode( $result->options ); |
| 876 | 796 | } |
| 877 | 797 | } |
| 878 | 798 | |
| 879 | - if ( $limit === ' LIMIT 1' || $limit == 1 ) { | |
| 799 | + if ( $limit == ' LIMIT 1' || $limit == 1 ) { | |
| 880 | 800 | // return the first form object if we are only getting one form |
| 881 | 801 | $results = reset( $results ); |
| 882 | 802 | } |
| 883 | 803 | |
| @@ -896,9 +816,9 @@ | ||
| 896 | 816 | */ |
| 897 | 817 | public static function get_published_forms( $query = array(), $limit = 999, $inc_children = 'exclude' ) { |
| 898 | 818 | $query['is_template'] = 0; |
| 899 | 819 | $query['status'] = array( null, '', 'published' ); |
| 900 | - if ( $inc_children === 'exclude' ) { | |
| 820 | + if ( $inc_children == 'exclude' ) { | |
| 901 | 821 | $query['parent_form_id'] = array( null, 0 ); |
| 902 | 822 | } |
| 903 | 823 | |
| 904 | 824 | $forms = self::getAll( $query, 'name', $limit ); |
| @@ -934,18 +854,18 @@ | ||
| 934 | 854 | |
| 935 | 855 | foreach ( $results as $row ) { |
| 936 | 856 | if ( 'trash' != $row->status ) { |
| 937 | 857 | if ( $row->is_template ) { |
| 938 | - ++$counts['template']; | |
| 858 | + $counts['template'] ++; | |
| 939 | 859 | } else { |
| 940 | - ++$counts['published']; | |
| 860 | + $counts['published'] ++; | |
| 941 | 861 | } |
| 942 | 862 | } else { |
| 943 | - ++$counts['trash']; | |
| 863 | + $counts['trash'] ++; | |
| 944 | 864 | } |
| 945 | 865 | |
| 946 | 866 | if ( 'draft' == $row->status ) { |
| 947 | - ++$counts['draft']; | |
| 867 | + $counts['draft'] ++; | |
| 948 | 868 | } |
| 949 | 869 | |
| 950 | 870 | unset( $row ); |
| 951 | 871 | } |
| @@ -1011,11 +931,11 @@ | ||
| 1011 | 931 | $values['posted_form_id'] = FrmAppHelper::get_param( 'form', '', 'get', 'absint' ); |
| 1012 | 932 | } |
| 1013 | 933 | |
| 1014 | 934 | if ( $form->id == $values['posted_form_id'] ) { |
| 1015 | - // If there are two forms on the same page, make sure not to submit both. | |
| 935 | + //if there are two forms on the same page, make sure not to submit both | |
| 1016 | 936 | foreach ( $default_values as $var => $default ) { |
| 1017 | - if ( $var === 'action' ) { | |
| 937 | + if ( $var == 'action' ) { | |
| 1018 | 938 | $values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
| 1019 | 939 | } else { |
| 1020 | 940 | $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
| 1021 | 941 | } |
| @@ -1083,9 +1003,9 @@ | ||
| 1083 | 1003 | return $values; |
| 1084 | 1004 | } |
| 1085 | 1005 | |
| 1086 | 1006 | public static function get_current_form_id( $default_form = 'none' ) { |
| 1087 | - if ( 'first' === $default_form ) { | |
| 1007 | + if ( 'first' == $default_form ) { | |
| 1088 | 1008 | $form = self::get_current_form(); |
| 1089 | 1009 | } else { |
| 1090 | 1010 | $form = self::maybe_get_current_form(); |
| 1091 | 1011 | } |
| @@ -1096,9 +1016,9 @@ | ||
| 1096 | 1016 | |
| 1097 | 1017 | public static function maybe_get_current_form( $form_id = 0 ) { |
| 1098 | 1018 | global $frm_vars; |
| 1099 | 1019 | |
| 1100 | - if ( ! empty( $frm_vars['current_form'] ) && ( ! $form_id || $form_id == $frm_vars['current_form']->id ) ) { | |
| 1020 | + if ( isset( $frm_vars['current_form'] ) && $frm_vars['current_form'] && ( ! $form_id || $form_id == $frm_vars['current_form']->id ) ) { | |
| 1101 | 1021 | return $frm_vars['current_form']; |
| 1102 | 1022 | } |
| 1103 | 1023 | |
| 1104 | 1024 | $form_id = FrmAppHelper::get_param( 'form', $form_id, 'get', 'absint' ); |
| @@ -1145,9 +1065,9 @@ | ||
| 1145 | 1065 | $global_load = true; |
| 1146 | 1066 | $frm_vars['load_css'] = true; |
| 1147 | 1067 | } |
| 1148 | 1068 | |
| 1149 | - return empty( $frm_vars['css_loaded'] ) && $global_load; | |
| 1069 | + return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load ); | |
| 1150 | 1070 | } |
| 1151 | 1071 | |
| 1152 | 1072 | /** |
| 1153 | 1073 | * @since 4.06.03 |
| @@ -1162,21 +1082,13 @@ | ||
| 1162 | 1082 | } else { |
| 1163 | 1083 | $visible = true; |
| 1164 | 1084 | } |
| 1165 | 1085 | |
| 1166 | - /** | |
| 1167 | - * @since 6.25 | |
| 1168 | - * | |
| 1169 | - * @param bool $visible | |
| 1170 | - * @param object $form | |
| 1171 | - */ | |
| 1172 | - $visible = (bool) apply_filters( 'frm_form_is_visible', $visible, $form ); | |
| 1173 | - | |
| 1174 | 1086 | return $visible; |
| 1175 | 1087 | } |
| 1176 | 1088 | |
| 1177 | 1089 | public static function show_submit( $form ) { |
| 1178 | - $show = ( ! $form->is_template && $form->status === 'published' && ! FrmAppHelper::is_admin() ); | |
| 1090 | + $show = ( ! $form->is_template && $form->status == 'published' && ! FrmAppHelper::is_admin() ); | |
| 1179 | 1091 | $show = apply_filters( 'frm_show_submit_button', $show, $form ); |
| 1180 | 1092 | |
| 1181 | 1093 | return $show; |
| 1182 | 1094 | } |
| @@ -1184,12 +1096,12 @@ | ||
| 1184 | 1096 | /** |
| 1185 | 1097 | * @since 2.3 |
| 1186 | 1098 | */ |
| 1187 | 1099 | public static function get_option( $atts ) { |
| 1188 | - $form = $atts['form']; | |
| 1189 | - $default = $atts['default'] ?? ''; | |
| 1100 | + $form = $atts['form']; | |
| 1101 | + $default = isset( $atts['default'] ) ? $atts['default'] : ''; | |
| 1190 | 1102 | |
| 1191 | - return $form->options[ $atts['option'] ] ?? $default; | |
| 1103 | + return isset( $form->options[ $atts['option'] ] ) ? $form->options[ $atts['option'] ] : $default; | |
| 1192 | 1104 | } |
| 1193 | 1105 | |
| 1194 | 1106 | /** |
| 1195 | 1107 | * Get the link to edit this form. |
| @@ -1213,50 +1125,8 @@ | ||
| 1213 | 1125 | return ! empty( $form->options['ajax_submit'] ); |
| 1214 | 1126 | } |
| 1215 | 1127 | |
| 1216 | 1128 | /** |
| 1217 | - * Get the latest form available. | |
| 1218 | - * | |
| 1219 | - * @since 6.8 | |
| 1220 | - * @return object | |
| 1221 | - */ | |
| 1222 | - public static function get_latest_form() { | |
| 1223 | - | |
| 1224 | - $args = array( | |
| 1225 | - array( | |
| 1226 | - 'or' => 1, | |
| 1227 | - 'parent_form_id' => null, | |
| 1228 | - 'parent_form_id <' => 1, | |
| 1229 | - ), | |
| 1230 | - 'is_template' => 0, | |
| 1231 | - 'status !' => 'trash', | |
| 1232 | - ); | |
| 1233 | - | |
| 1234 | - return self::getAll( $args, 'created_at desc', 1 ); | |
| 1235 | - } | |
| 1236 | - | |
| 1237 | - /** | |
| 1238 | - * Count and return total forms. | |
| 1239 | - * | |
| 1240 | - * @since 6.8 | |
| 1241 | - * @return int | |
| 1242 | - */ | |
| 1243 | - public static function get_forms_count() { | |
| 1244 | - | |
| 1245 | - $args = array( | |
| 1246 | - array( | |
| 1247 | - 'or' => 1, | |
| 1248 | - 'parent_form_id' => null, | |
| 1249 | - 'parent_form_id <' => 1, | |
| 1250 | - ), | |
| 1251 | - 'is_template' => 0, | |
| 1252 | - 'status !' => 'trash', | |
| 1253 | - ); | |
| 1254 | - | |
| 1255 | - return FrmDb::get_count( 'frm_forms', $args ); | |
| 1256 | - } | |
| 1257 | - | |
| 1258 | - /** | |
| 1259 | 1129 | * @deprecated 2.03.05 This is still referenced in a few add ons (API, locations). |
| 1260 | 1130 | * @codeCoverageIgnore |
| 1261 | 1131 | * |
| 1262 | 1132 | * @param string $key |
| @@ -1270,9 +1140,9 @@ | ||
| 1270 | 1140 | /** |
| 1271 | 1141 | * @deprecated 2.03.05 This is still referenced in the API add on as of v1.13. |
| 1272 | 1142 | * @codeCoverageIgnore |
| 1273 | 1143 | * |
| 1274 | - * @param int|string $id | |
| 1144 | + * @param string|int $id | |
| 1275 | 1145 | * @return string |
| 1276 | 1146 | */ |
| 1277 | 1147 | public static function getKeyById( $id ) { |
| 1278 | 1148 | _deprecated_function( __FUNCTION__, '2.03.05', 'FrmForm::get_key_by_id' ); |