| @@ -6,9 +6,8 @@ | ||
| 6 | 6 | class FrmForm { |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * @param array $values |
| 10 | - * | |
| 11 | 10 | * @return bool|int id on success or false on failure. |
| 12 | 11 | */ |
| 13 | 12 | public static function create( $values ) { |
| 14 | 13 | global $wpdb; |
| @@ -18,22 +17,22 @@ | ||
| 18 | 17 | $new_values = array( |
| 19 | 18 | 'form_key' => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ), |
| 20 | 19 | 'name' => $values['name'], |
| 21 | 20 | 'description' => $values['description'], |
| 22 | - 'status' => $values['status'] ?? 'published', | |
| 23 | - '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, | |
| 24 | 23 | 'is_template' => isset( $values['is_template'] ) ? (int) $values['is_template'] : 0, |
| 25 | 24 | 'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0, |
| 26 | 25 | 'editable' => isset( $values['editable'] ) ? (int) $values['editable'] : 0, |
| 27 | - 'created_at' => $values['created_at'] ?? current_time( 'mysql', 1 ), | |
| 26 | + 'created_at' => isset( $values['created_at'] ) ? $values['created_at'] : current_time( 'mysql', 1 ), | |
| 28 | 27 | ); |
| 29 | 28 | |
| 30 | 29 | $options = isset( $values['options'] ) ? (array) $values['options'] : array(); |
| 31 | 30 | FrmFormsHelper::fill_form_options( $options, $values ); |
| 32 | 31 | |
| 33 | - $options['before_html'] = $values['options']['before_html'] ?? FrmFormsHelper::get_default_html( 'before' ); | |
| 34 | - $options['after_html'] = $values['options']['after_html'] ?? FrmFormsHelper::get_default_html( 'after' ); | |
| 35 | - $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' ); | |
| 36 | 35 | |
| 37 | 36 | /** |
| 38 | 37 | * Allows modifying form options before updating or creating. |
| 39 | 38 | * |
| @@ -60,9 +59,8 @@ | ||
| 60 | 59 | /** |
| 61 | 60 | * @since 5.0.08 |
| 62 | 61 | * |
| 63 | 62 | * @param array $options |
| 64 | - * | |
| 65 | 63 | * @return array |
| 66 | 64 | */ |
| 67 | 65 | private static function maybe_filter_form_options( $options ) { |
| 68 | 66 | if ( ! FrmAppHelper::allow_unfiltered_html() && ! empty( $options['submit_html'] ) ) { |
| @@ -71,15 +69,8 @@ | ||
| 71 | 69 | return FrmAppHelper::maybe_filter_array( $options, array( 'submit_value', 'success_msg', 'before_html', 'after_html' ) ); |
| 72 | 70 | } |
| 73 | 71 | |
| 74 | 72 | /** |
| 75 | - * Duplicate a form. | |
| 76 | - * | |
| 77 | - * @param int $id Form ID to duplicate. | |
| 78 | - * @param bool $template Whether the duplicated form is a template. | |
| 79 | - * @param bool $copy_keys Whether to copy the original form key. | |
| 80 | - * @param false|int $blog_id Blog ID when duplicating across sites, or false for current site. | |
| 81 | - * | |
| 82 | 73 | * @return bool|int ID on success or false on failure |
| 83 | 74 | */ |
| 84 | 75 | public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) { |
| 85 | 76 | global $wpdb; |
| @@ -84,9 +75,8 @@ | ||
| 84 | 75 | public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) { |
| 85 | 76 | global $wpdb; |
| 86 | 77 | |
| 87 | 78 | $values = self::getOne( $id, $blog_id ); |
| 88 | - | |
| 89 | 79 | if ( ! $values ) { |
| 90 | 80 | return false; |
| 91 | 81 | } |
| 92 | 82 | |
| @@ -135,14 +125,8 @@ | ||
| 135 | 125 | |
| 136 | 126 | return false; |
| 137 | 127 | } |
| 138 | 128 | |
| 139 | - /** | |
| 140 | - * @param int $form_id | |
| 141 | - * @param array $values | |
| 142 | - * | |
| 143 | - * @return void | |
| 144 | - */ | |
| 145 | 129 | public static function after_duplicate( $form_id, $values ) { |
| 146 | 130 | $new_opts = $values['options']; |
| 147 | 131 | FrmAppHelper::unserialize_or_decode( $new_opts ); |
| 148 | 132 | $values['options'] = $new_opts; |
| @@ -166,10 +150,8 @@ | ||
| 166 | 150 | * |
| 167 | 151 | * @since 5.3 |
| 168 | 152 | * |
| 169 | 153 | * @param int $form_id Form ID. |
| 170 | - * | |
| 171 | - * @return void | |
| 172 | 154 | */ |
| 173 | 155 | private static function switch_field_ids_in_fields( $form_id ) { |
| 174 | 156 | global $wpdb; |
| 175 | 157 | |
| @@ -175,9 +157,8 @@ | ||
| 175 | 157 | |
| 176 | 158 | // Keys of fields that you want to check to replace field ID. |
| 177 | 159 | $keys = array( 'default_value', 'field_options' ); |
| 178 | 160 | $sql_cols = 'fi.id'; |
| 179 | - | |
| 180 | 161 | foreach ( $keys as $key ) { |
| 181 | 162 | $sql_cols .= ',fi.' . $key; |
| 182 | 163 | } |
| 183 | 164 | |
| @@ -205,14 +186,11 @@ | ||
| 205 | 186 | * |
| 206 | 187 | * @since 5.3 |
| 207 | 188 | * |
| 208 | 189 | * @param array $field Field array. |
| 209 | - * | |
| 210 | - * @return void | |
| 211 | 190 | */ |
| 212 | 191 | private static function switch_field_ids_in_field( $field ) { |
| 213 | 192 | $new_values = array(); |
| 214 | - | |
| 215 | 193 | foreach ( $field as $key => $value ) { |
| 216 | 194 | if ( 'id' === $key || ! $value ) { |
| 217 | 195 | continue; |
| 218 | 196 | } |
| @@ -240,14 +218,8 @@ | ||
| 240 | 218 | } |
| 241 | 219 | } |
| 242 | 220 | |
| 243 | 221 | /** |
| 244 | - * Update a form. | |
| 245 | - * | |
| 246 | - * @param int $id Form ID. | |
| 247 | - * @param array $values Form values to update. | |
| 248 | - * @param bool $create_link Whether this is being called from link creation. | |
| 249 | - * | |
| 250 | 222 | * @return bool|int |
| 251 | 223 | */ |
| 252 | 224 | public static function update( $id, $values, $create_link = false ) { |
| 253 | 225 | global $wpdb; |
| @@ -277,9 +249,8 @@ | ||
| 277 | 249 | } |
| 278 | 250 | |
| 279 | 251 | if ( ! empty( $new_values ) ) { |
| 280 | 252 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $id ) ); |
| 281 | - | |
| 282 | 253 | if ( $query_results ) { |
| 283 | 254 | self::clear_form_cache(); |
| 284 | 255 | } |
| 285 | 256 | } else { |
| @@ -298,9 +269,8 @@ | ||
| 298 | 269 | /** |
| 299 | 270 | * @param array $new_values |
| 300 | 271 | * @param array $values |
| 301 | 272 | * @param array $args |
| 302 | - * | |
| 303 | 273 | * @return array |
| 304 | 274 | */ |
| 305 | 275 | public static function set_update_options( $new_values, $values, $args = array() ) { |
| 306 | 276 | if ( ! isset( $values['options'] ) ) { |
| @@ -309,11 +279,11 @@ | ||
| 309 | 279 | |
| 310 | 280 | $options = ! empty( $values['options'] ) ? (array) $values['options'] : array(); |
| 311 | 281 | FrmFormsHelper::fill_form_options( $options, $values ); |
| 312 | 282 | |
| 313 | - $options['custom_style'] = $values['options']['custom_style'] ?? 0; | |
| 314 | - $options['before_html'] = $values['options']['before_html'] ?? FrmFormsHelper::get_default_html( 'before' ); | |
| 315 | - $options['after_html'] = $values['options']['after_html'] ?? FrmFormsHelper::get_default_html( 'after' ); | |
| 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' ); | |
| 316 | 286 | $options['submit_html'] = isset( $values['options']['submit_html'] ) && '' !== $values['options']['submit_html'] ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html( 'submit' ); |
| 317 | 287 | |
| 318 | 288 | /** |
| 319 | 289 | * Allows modifying form options before updating or creating. |
| @@ -331,11 +301,8 @@ | ||
| 331 | 301 | return $new_values; |
| 332 | 302 | } |
| 333 | 303 | |
| 334 | 304 | /** |
| 335 | - * @param int $id Form ID. | |
| 336 | - * @param array $values Form values array. | |
| 337 | - * | |
| 338 | 305 | * @return array |
| 339 | 306 | */ |
| 340 | 307 | public static function update_fields( $id, $values ) { |
| 341 | 308 | |
| @@ -343,9 +310,8 @@ | ||
| 343 | 310 | return $values; |
| 344 | 311 | } |
| 345 | 312 | |
| 346 | 313 | $all_fields = FrmField::get_all_for_form( $id ); |
| 347 | - | |
| 348 | 314 | if ( empty( $all_fields ) ) { |
| 349 | 315 | return $values; |
| 350 | 316 | } |
| 351 | 317 | |
| @@ -354,9 +320,8 @@ | ||
| 354 | 320 | } |
| 355 | 321 | |
| 356 | 322 | $field_array = array(); |
| 357 | 323 | $existing_keys = array_keys( $values['item_meta'] ); |
| 358 | - | |
| 359 | 324 | foreach ( $all_fields as $fid ) { |
| 360 | 325 | if ( ! in_array( $fid->id, $existing_keys ) && ( isset( $values['frm_fields_submitted'] ) && in_array( $fid->id, $values['frm_fields_submitted'] ) ) || isset( $values['options'] ) ) { |
| 361 | 326 | $values['item_meta'][ $fid->id ] = ''; |
| 362 | 327 | } |
| @@ -375,9 +340,8 @@ | ||
| 375 | 340 | continue; |
| 376 | 341 | } |
| 377 | 342 | |
| 378 | 343 | $is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ); |
| 379 | - | |
| 380 | 344 | if ( $is_settings_page ) { |
| 381 | 345 | self::get_settings_page_html( $values, $field ); |
| 382 | 346 | |
| 383 | 347 | if ( ! defined( 'WP_IMPORTING' ) ) { |
| @@ -390,14 +354,10 @@ | ||
| 390 | 354 | // Don't check for POST html. |
| 391 | 355 | unset( $update_options['custom_html'] ); |
| 392 | 356 | $update_options = apply_filters( 'frm_field_options_to_update', $update_options ); |
| 393 | 357 | |
| 394 | - if ( ! is_array( $field->field_options ) ) { | |
| 395 | - $field->field_options = array(); | |
| 396 | - } | |
| 397 | - | |
| 398 | 358 | foreach ( $update_options as $opt => $default ) { |
| 399 | - $field->field_options[ $opt ] = $values['field_options'][ $opt . '_' . $field_id ] ?? $default; | |
| 359 | + $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? $values['field_options'][ $opt . '_' . $field_id ] : $default; | |
| 400 | 360 | self::sanitize_field_opt( $opt, $field->field_options[ $opt ] ); |
| 401 | 361 | } |
| 402 | 362 | |
| 403 | 363 | $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values ); |
| @@ -436,9 +396,8 @@ | ||
| 436 | 396 | * |
| 437 | 397 | * @param array $field |
| 438 | 398 | * @param array $values |
| 439 | 399 | * @param array $new_field |
| 440 | - * | |
| 441 | 400 | * @return void |
| 442 | 401 | */ |
| 443 | 402 | private static function maybe_update_max_option( $field, $values, &$new_field ) { |
| 444 | 403 | if ( $field->type === 'textarea' && |
| @@ -457,9 +416,8 @@ | ||
| 457 | 416 | |
| 458 | 417 | /** |
| 459 | 418 | * @param string $opt |
| 460 | 419 | * @param mixed $value |
| 461 | - * | |
| 462 | 420 | * @return void |
| 463 | 421 | */ |
| 464 | 422 | private static function sanitize_field_opt( $opt, &$value ) { |
| 465 | 423 | if ( ! is_string( $value ) ) { |
| @@ -491,9 +449,8 @@ | ||
| 491 | 449 | } |
| 492 | 450 | |
| 493 | 451 | /** |
| 494 | 452 | * @param string $value |
| 495 | - * | |
| 496 | 453 | * @return string |
| 497 | 454 | */ |
| 498 | 455 | private static function sanitize_calc( $value ) { |
| 499 | 456 | if ( false !== strpos( $value, '<' ) ) { |
| @@ -512,37 +469,29 @@ | ||
| 512 | 469 | * Format a comparison like 5<10 to 5 < 10. Also works on 5< 10, 5 <10, 5<=10 variations. |
| 513 | 470 | * This is to avoid an issue with unspaced calculations being recognized as HTML that gets removed when strip_tags is called. |
| 514 | 471 | * |
| 515 | 472 | * @param string $calc |
| 516 | - * | |
| 517 | 473 | * @return string |
| 518 | 474 | */ |
| 519 | 475 | private static function normalize_calc_spaces( $calc ) { |
| 520 | 476 | // Check for a pattern with 5 parts |
| 521 | - // $1 \d|\] the first comparison digit or the end of a comparison shortcode. | |
| 477 | + // $1 \d the first comparison digit. | |
| 522 | 478 | // $2 a space (optional). |
| 523 | 479 | // $3 an equals sign (optional) that follows the < operator for <= comparisons. |
| 524 | 480 | // $4 another space (optional). |
| 525 | - // $5 \d|\[ the second comparison digit or the start of a comparison shortcode. | |
| 526 | - $calc = preg_replace( '/(\d|\])( ){0,1}<(=){0,1}( ){0,1}(\d|\[)/', '$1 <$3 $5', $calc ); | |
| 527 | - | |
| 528 | - return $calc; | |
| 481 | + // $5 \d the second comparison digit. | |
| 482 | + return preg_replace( '/(\d)( ){0,1}<(=){0,1}( ){0,1}(\d)/', '$1 <$3 $5', $calc ); | |
| 529 | 483 | } |
| 530 | 484 | |
| 531 | 485 | /** |
| 532 | 486 | * Updating the settings page |
| 533 | - * | |
| 534 | - * @param array $values Form values array. | |
| 535 | - * @param object $field Field object, passed by reference. | |
| 536 | - * | |
| 537 | - * @return void | |
| 538 | 487 | */ |
| 539 | 488 | private static function get_settings_page_html( $values, &$field ) { |
| 540 | 489 | if ( isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ) { |
| 541 | 490 | $prev_opts = array(); |
| 542 | - $fallback_html = $field->field_options['custom_html'] ?? FrmFieldsHelper::get_default_html( $field->type ); | |
| 491 | + $fallback_html = isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ); | |
| 543 | 492 | |
| 544 | - $field->field_options['custom_html'] = $values['field_options'][ 'custom_html_' . $field->id ] ?? $fallback_html; | |
| 493 | + $field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ? $values['field_options'][ 'custom_html_' . $field->id ] : $fallback_html; | |
| 545 | 494 | } elseif ( $field->type === 'hidden' || $field->type === 'user_id' ) { |
| 546 | 495 | $prev_opts = $field->field_options; |
| 547 | 496 | } |
| 548 | 497 | |
| @@ -547,9 +496,8 @@ | ||
| 547 | 496 | } |
| 548 | 497 | |
| 549 | 498 | if ( isset( $prev_opts ) ) { |
| 550 | 499 | $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values ); |
| 551 | - | |
| 552 | 500 | if ( $prev_opts != $field->field_options ) { |
| 553 | 501 | FrmField::update( $field->id, array( 'field_options' => $field->field_options ) ); |
| 554 | 502 | } |
| 555 | 503 | } |
| @@ -554,15 +502,8 @@ | ||
| 554 | 502 | } |
| 555 | 503 | } |
| 556 | 504 | } |
| 557 | 505 | |
| 558 | - /** | |
| 559 | - * @param object $field | |
| 560 | - * @param array $values | |
| 561 | - * @param array $new_field | |
| 562 | - * | |
| 563 | - * @return void | |
| 564 | - */ | |
| 565 | 506 | private static function prepare_field_update_values( $field, $values, &$new_field ) { |
| 566 | 507 | $field_cols = array( |
| 567 | 508 | 'field_order' => 0, |
| 568 | 509 | 'field_key' => '', |
| @@ -571,16 +512,12 @@ | ||
| 571 | 512 | 'description' => '', |
| 572 | 513 | 'options' => '', |
| 573 | 514 | 'name' => '', |
| 574 | 515 | ); |
| 575 | - | |
| 576 | 516 | foreach ( $field_cols as $col => $default ) { |
| 577 | - $default = $default === '' ? $field->{$col} : $default; | |
| 578 | - $new_field[ $col ] = $values['field_options'][ $col . '_' . $field->id ] ?? $default; | |
| 579 | - } | |
| 517 | + $default = $default === '' ? $field->{$col} : $default; | |
| 580 | 518 | |
| 581 | - if ( $field->type === 'submit' && isset( $new_field['field_order'] ) && (int) $new_field['field_order'] === FrmSubmitHelper::DEFAULT_ORDER ) { | |
| 582 | - $new_field['field_order'] = $field->field_order; | |
| 519 | + $new_field[ $col ] = isset( $values['field_options'][ $col . '_' . $field->id ] ) ? $values['field_options'][ $col . '_' . $field->id ] : $default; | |
| 583 | 520 | } |
| 584 | 521 | |
| 585 | 522 | // Don't save the template option. |
| 586 | 523 | if ( is_array( $new_field['options'] ) && isset( $new_field['options']['000'] ) ) { |
| @@ -592,12 +529,9 @@ | ||
| 592 | 529 | * Get a list of all form settings that should be translated |
| 593 | 530 | * on a multilingual site. |
| 594 | 531 | * |
| 595 | 532 | * @since 3.06.01 |
| 596 | - * | |
| 597 | 533 | * @param object $form The form object. |
| 598 | - * | |
| 599 | - * @return array | |
| 600 | 534 | */ |
| 601 | 535 | public static function translatable_strings( $form ) { |
| 602 | 536 | $strings = array( |
| 603 | 537 | 'name', |
| @@ -625,9 +559,8 @@ | ||
| 625 | 559 | return self::trash( $id ); |
| 626 | 560 | } |
| 627 | 561 | |
| 628 | 562 | $statuses = array( 'published', 'draft', 'trash' ); |
| 629 | - | |
| 630 | 563 | if ( ! in_array( $status, $statuses, true ) ) { |
| 631 | 564 | return false; |
| 632 | 565 | } |
| 633 | 566 | |
| @@ -655,10 +588,8 @@ | ||
| 655 | 588 | return $query_results; |
| 656 | 589 | } |
| 657 | 590 | |
| 658 | 591 | /** |
| 659 | - * @param int|string $id Form ID. | |
| 660 | - * | |
| 661 | 592 | * @return bool|int |
| 662 | 593 | */ |
| 663 | 594 | public static function trash( $id ) { |
| 664 | 595 | if ( ! EMPTY_TRASH_DAYS ) { |
| @@ -665,17 +596,12 @@ | ||
| 665 | 596 | return self::destroy( $id ); |
| 666 | 597 | } |
| 667 | 598 | |
| 668 | 599 | $form = self::getOne( $id ); |
| 669 | - | |
| 670 | 600 | if ( ! $form ) { |
| 671 | 601 | return false; |
| 672 | 602 | } |
| 673 | 603 | |
| 674 | - if ( $form->status === 'trash' ) { | |
| 675 | - return false; | |
| 676 | - } | |
| 677 | - | |
| 678 | 604 | $options = $form->options; |
| 679 | 605 | $options['trash_time'] = time(); |
| 680 | 606 | |
| 681 | 607 | global $wpdb; |
| @@ -708,10 +634,8 @@ | ||
| 708 | 634 | return $query_results; |
| 709 | 635 | } |
| 710 | 636 | |
| 711 | 637 | /** |
| 712 | - * @param int|string $id Form ID. | |
| 713 | - * | |
| 714 | 638 | * @return bool|int |
| 715 | 639 | */ |
| 716 | 640 | public static function destroy( $id ) { |
| 717 | 641 | global $wpdb; |
| @@ -716,18 +640,15 @@ | ||
| 716 | 640 | public static function destroy( $id ) { |
| 717 | 641 | global $wpdb; |
| 718 | 642 | |
| 719 | 643 | $form = self::getOne( $id ); |
| 720 | - | |
| 721 | 644 | if ( ! $form ) { |
| 722 | 645 | return false; |
| 723 | 646 | } |
| 724 | - | |
| 725 | 647 | $id = $form->id; |
| 726 | 648 | |
| 727 | 649 | // Disconnect the entries from this form |
| 728 | 650 | $entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) ); |
| 729 | - | |
| 730 | 651 | foreach ( $entries as $entry_id ) { |
| 731 | 652 | FrmEntry::destroy( $entry_id ); |
| 732 | 653 | unset( $entry_id ); |
| 733 | 654 | } |
| @@ -735,14 +656,10 @@ | ||
| 735 | 656 | // Disconnect the fields from this form |
| 736 | 657 | $wpdb->query( $wpdb->prepare( 'DELETE fi FROM ' . $wpdb->prefix . 'frm_fields AS fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id) WHERE fi.form_id=%d OR parent_form_id=%d', $id, $id ) ); |
| 737 | 658 | |
| 738 | 659 | $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) ); |
| 739 | - | |
| 740 | 660 | if ( $query_results ) { |
| 741 | 661 | // Delete all form actions linked to this form |
| 742 | - /** | |
| 743 | - * @var FrmFormAction | |
| 744 | - */ | |
| 745 | 662 | $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
| 746 | 663 | $action_control->destroy( $id, 'all' ); |
| 747 | 664 | |
| 748 | 665 | // Clear form caching |
| @@ -757,10 +674,8 @@ | ||
| 757 | 674 | |
| 758 | 675 | /** |
| 759 | 676 | * Delete trashed forms based on how long they have been trashed |
| 760 | 677 | * |
| 761 | - * @param int|string $delete_timestamp Timestamp cutoff for deletion. | |
| 762 | - * | |
| 763 | 678 | * @return int The number of forms deleted |
| 764 | 679 | */ |
| 765 | 680 | public static function scheduled_delete( $delete_timestamp = '' ) { |
| 766 | 681 | global $wpdb; |
| @@ -775,15 +690,12 @@ | ||
| 775 | 690 | $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); |
| 776 | 691 | } |
| 777 | 692 | |
| 778 | 693 | $count = 0; |
| 779 | - | |
| 780 | 694 | foreach ( $trash_forms as $form ) { |
| 781 | 695 | FrmAppHelper::unserialize_or_decode( $form->options ); |
| 782 | - | |
| 783 | 696 | if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) { |
| 784 | 697 | self::destroy( $form->id ); |
| 785 | - | |
| 786 | 698 | if ( empty( $form->parent_form_id ) ) { |
| 787 | 699 | ++$count; |
| 788 | 700 | } |
| 789 | 701 | } |
| @@ -794,15 +706,12 @@ | ||
| 794 | 706 | return $count; |
| 795 | 707 | } |
| 796 | 708 | |
| 797 | 709 | /** |
| 798 | - * @param int|string $id Form ID or key. | |
| 799 | - * | |
| 800 | 710 | * @return string form name |
| 801 | 711 | */ |
| 802 | 712 | public static function getName( $id ) { |
| 803 | 713 | $form = FrmDb::check_cache( $id, 'frm_form' ); |
| 804 | - | |
| 805 | 714 | if ( $form ) { |
| 806 | 715 | $r = stripslashes( $form->name ); |
| 807 | 716 | |
| 808 | 717 | return $r; |
| @@ -830,9 +739,9 @@ | ||
| 830 | 739 | |
| 831 | 740 | /** |
| 832 | 741 | * @since 3.0 |
| 833 | 742 | * |
| 834 | - * @param int|string $id | |
| 743 | + * @param int $id | |
| 835 | 744 | * |
| 836 | 745 | * @return string form key |
| 837 | 746 | */ |
| 838 | 747 | public static function get_key_by_id( $id ) { |
| @@ -837,9 +746,8 @@ | ||
| 837 | 746 | */ |
| 838 | 747 | public static function get_key_by_id( $id ) { |
| 839 | 748 | $id = (int) $id; |
| 840 | 749 | $cache = FrmDb::check_cache( $id, 'frm_form' ); |
| 841 | - | |
| 842 | 750 | if ( $cache ) { |
| 843 | 751 | return $cache->form_key; |
| 844 | 752 | } |
| 845 | 753 | |
| @@ -851,12 +759,9 @@ | ||
| 851 | 759 | /** |
| 852 | 760 | * If $form is numeric, get the form object |
| 853 | 761 | * |
| 854 | 762 | * @since 2.0.9 |
| 855 | - * | |
| 856 | 763 | * @param int|object $form |
| 857 | - * | |
| 858 | - * @return void | |
| 859 | 764 | */ |
| 860 | 765 | public static function maybe_get_form( &$form ) { |
| 861 | 766 | if ( ! is_object( $form ) && ! is_array( $form ) && ! empty( $form ) ) { |
| 862 | 767 | $form = self::getOne( $form ); |
| @@ -865,9 +770,8 @@ | ||
| 865 | 770 | |
| 866 | 771 | /** |
| 867 | 772 | * @param int|string $id |
| 868 | 773 | * @param false|int $blog_id |
| 869 | - * | |
| 870 | 774 | * @return stdClass|null |
| 871 | 775 | */ |
| 872 | 776 | public static function getOne( $id, $blog_id = false ) { |
| 873 | 777 | global $wpdb; |
| @@ -872,14 +776,15 @@ | ||
| 872 | 776 | public static function getOne( $id, $blog_id = false ) { |
| 873 | 777 | global $wpdb; |
| 874 | 778 | |
| 875 | 779 | if ( $blog_id && is_multisite() ) { |
| 876 | - $prefix = $wpdb->get_blog_prefix( $blog_id ); | |
| 780 | + global $wpmuBaseTablePrefix; | |
| 781 | + $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id ); | |
| 782 | + | |
| 877 | 783 | $table_name = $prefix . 'frm_forms'; |
| 878 | 784 | } else { |
| 879 | 785 | $table_name = $wpdb->prefix . 'frm_forms'; |
| 880 | 786 | $cache = wp_cache_get( $id, 'frm_form' ); |
| 881 | - | |
| 882 | 787 | if ( $cache ) { |
| 883 | 788 | if ( isset( $cache->options ) ) { |
| 884 | 789 | FrmAppHelper::unserialize_or_decode( $cache->options ); |
| 885 | 790 | } |
| @@ -908,14 +813,12 @@ | ||
| 908 | 813 | * |
| 909 | 814 | * @since 6.8.3 |
| 910 | 815 | * |
| 911 | 816 | * @param stdClass|null $row The database row for a target form. |
| 912 | - * | |
| 913 | 817 | * @return stdClass|null |
| 914 | 818 | */ |
| 915 | 819 | private static function prepare_form_row_data( $row ) { |
| 916 | 820 | $row = wp_unslash( $row ); |
| 917 | - | |
| 918 | 821 | if ( ! is_object( $row ) ) { |
| 919 | 822 | return $row; |
| 920 | 823 | } |
| 921 | 824 | |
| @@ -931,17 +834,13 @@ | ||
| 931 | 834 | return apply_filters( 'frm_form_object', $row ); |
| 932 | 835 | } |
| 933 | 836 | |
| 934 | 837 | /** |
| 935 | - * @param array|string $where Where conditions array or raw WHERE string. | |
| 936 | - * @param string $order_by Order by clause. | |
| 937 | - * @param int|string $limit Limit clause or number. | |
| 938 | - * | |
| 939 | 838 | * @return array|object of objects |
| 940 | 839 | */ |
| 941 | 840 | public static function getAll( $where = array(), $order_by = '', $limit = '' ) { |
| 942 | 841 | if ( is_array( $where ) && ! empty( $where ) ) { |
| 943 | - if ( ! empty( $where['is_template'] ) && ! isset( $where['status'] ) && ! isset( $where['status !'] ) ) { | |
| 842 | + if ( isset( $where['is_template'] ) && $where['is_template'] && ! isset( $where['status'] ) && ! isset( $where['status !'] ) ) { | |
| 944 | 843 | // don't get trashed templates |
| 945 | 844 | $where['status'] = array( null, '', 'published' ); |
| 946 | 845 | } |
| 947 | 846 | |
| @@ -976,15 +875,13 @@ | ||
| 976 | 875 | * |
| 977 | 876 | * @param array $query |
| 978 | 877 | * @param int $limit |
| 979 | 878 | * @param string $inc_children |
| 980 | - * | |
| 981 | 879 | * @return array|object of forms A single form object would be passed if $limit was set to 1. |
| 982 | 880 | */ |
| 983 | 881 | public static function get_published_forms( $query = array(), $limit = 999, $inc_children = 'exclude' ) { |
| 984 | 882 | $query['is_template'] = 0; |
| 985 | 883 | $query['status'] = array( null, '', 'published' ); |
| 986 | - | |
| 987 | 884 | if ( $inc_children === 'exclude' ) { |
| 988 | 885 | $query['parent_form_id'] = array( null, 0 ); |
| 989 | 886 | } |
| 990 | 887 | |
| @@ -1001,14 +898,13 @@ | ||
| 1001 | 898 | |
| 1002 | 899 | $cache_key = 'frm_form_counts'; |
| 1003 | 900 | |
| 1004 | 901 | $counts = wp_cache_get( $cache_key, 'frm_form' ); |
| 1005 | - | |
| 1006 | 902 | if ( false !== $counts ) { |
| 1007 | 903 | return $counts; |
| 1008 | 904 | } |
| 1009 | 905 | |
| 1010 | - $results = FrmDb::get_results( | |
| 906 | + $results = (array) FrmDb::get_results( | |
| 1011 | 907 | 'frm_forms', |
| 1012 | 908 | array( |
| 1013 | 909 | 'or' => 1, |
| 1014 | 910 | 'parent_form_id' => null, |
| @@ -1049,10 +945,8 @@ | ||
| 1049 | 945 | * Called when a form is created, updated, duplicated, or deleted |
| 1050 | 946 | * or when the form status is changed |
| 1051 | 947 | * |
| 1052 | 948 | * @since 2.0.4 |
| 1053 | - * | |
| 1054 | - * @return void | |
| 1055 | 949 | */ |
| 1056 | 950 | public static function clear_form_cache() { |
| 1057 | 951 | FrmDb::cache_delete_group( 'frm_form' ); |
| 1058 | 952 | } |
| @@ -1057,22 +951,16 @@ | ||
| 1057 | 951 | FrmDb::cache_delete_group( 'frm_form' ); |
| 1058 | 952 | } |
| 1059 | 953 | |
| 1060 | 954 | /** |
| 1061 | - * @param array $values Form values to validate. | |
| 1062 | - * | |
| 1063 | 955 | * @return array of errors |
| 1064 | 956 | */ |
| 1065 | 957 | public static function validate( $values ) { |
| 1066 | 958 | $errors = array(); |
| 959 | + | |
| 1067 | 960 | return apply_filters( 'frm_validate_form', $errors, $values ); |
| 1068 | 961 | } |
| 1069 | 962 | |
| 1070 | - /** | |
| 1071 | - * @param object|null $form | |
| 1072 | - * | |
| 1073 | - * @return array | |
| 1074 | - */ | |
| 1075 | 963 | public static function get_params( $form = null ) { |
| 1076 | 964 | global $frm_vars; |
| 1077 | 965 | |
| 1078 | 966 | if ( ! $form ) { |
| @@ -1102,9 +990,8 @@ | ||
| 1102 | 990 | ); |
| 1103 | 991 | |
| 1104 | 992 | $values = array(); |
| 1105 | 993 | $values['posted_form_id'] = FrmAppHelper::get_param( 'form_id', '', 'get', 'absint' ); |
| 1106 | - | |
| 1107 | 994 | if ( ! $values['posted_form_id'] ) { |
| 1108 | 995 | $values['posted_form_id'] = FrmAppHelper::get_param( 'form', '', 'get', 'absint' ); |
| 1109 | 996 | } |
| 1110 | 997 | |
| @@ -1133,11 +1020,8 @@ | ||
| 1133 | 1020 | |
| 1134 | 1021 | return $values; |
| 1135 | 1022 | } |
| 1136 | 1023 | |
| 1137 | - /** | |
| 1138 | - * @return array | |
| 1139 | - */ | |
| 1140 | 1024 | public static function list_page_params() { |
| 1141 | 1025 | $values = array(); |
| 1142 | 1026 | $defaults = array( |
| 1143 | 1027 | 'template' => 0, |
| @@ -1147,9 +1031,8 @@ | ||
| 1147 | 1031 | 'search' => '', |
| 1148 | 1032 | 'sort' => '', |
| 1149 | 1033 | 'sdir' => '', |
| 1150 | 1034 | ); |
| 1151 | - | |
| 1152 | 1035 | foreach ( $defaults as $var => $default ) { |
| 1153 | 1036 | $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
| 1154 | 1037 | } |
| 1155 | 1038 | |
| @@ -1155,16 +1038,10 @@ | ||
| 1155 | 1038 | |
| 1156 | 1039 | return $values; |
| 1157 | 1040 | } |
| 1158 | 1041 | |
| 1159 | - /** | |
| 1160 | - * @param int|object|string|null $form | |
| 1161 | - * | |
| 1162 | - * @return array | |
| 1163 | - */ | |
| 1164 | 1042 | public static function get_admin_params( $form = null ) { |
| 1165 | 1043 | $form_id = $form; |
| 1166 | - | |
| 1167 | 1044 | if ( $form === null ) { |
| 1168 | 1045 | $form_id = self::get_current_form_id(); |
| 1169 | 1046 | } elseif ( $form && is_object( $form ) ) { |
| 1170 | 1047 | $form_id = $form->id; |
| @@ -1182,9 +1059,8 @@ | ||
| 1182 | 1059 | 'sdir' => '', |
| 1183 | 1060 | 'fid' => '', |
| 1184 | 1061 | 'keep_post' => '', |
| 1185 | 1062 | ); |
| 1186 | - | |
| 1187 | 1063 | foreach ( $defaults as $var => $default ) { |
| 1188 | 1064 | $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
| 1189 | 1065 | } |
| 1190 | 1066 | |
| @@ -1190,13 +1066,8 @@ | ||
| 1190 | 1066 | |
| 1191 | 1067 | return $values; |
| 1192 | 1068 | } |
| 1193 | 1069 | |
| 1194 | - /** | |
| 1195 | - * @param string $default_form | |
| 1196 | - * | |
| 1197 | - * @return int|string | |
| 1198 | - */ | |
| 1199 | 1070 | public static function get_current_form_id( $default_form = 'none' ) { |
| 1200 | 1071 | if ( 'first' === $default_form ) { |
| 1201 | 1072 | $form = self::get_current_form(); |
| 1202 | 1073 | } else { |
| @@ -1201,28 +1072,21 @@ | ||
| 1201 | 1072 | $form = self::get_current_form(); |
| 1202 | 1073 | } else { |
| 1203 | 1074 | $form = self::maybe_get_current_form(); |
| 1204 | 1075 | } |
| 1205 | - | |
| 1206 | 1076 | $form_id = $form ? $form->id : 0; |
| 1207 | 1077 | |
| 1208 | 1078 | return $form_id; |
| 1209 | 1079 | } |
| 1210 | 1080 | |
| 1211 | - /** | |
| 1212 | - * @param int|string $form_id | |
| 1213 | - * | |
| 1214 | - * @return false|int|object|string | |
| 1215 | - */ | |
| 1216 | 1081 | public static function maybe_get_current_form( $form_id = 0 ) { |
| 1217 | 1082 | global $frm_vars; |
| 1218 | 1083 | |
| 1219 | - if ( ! empty( $frm_vars['current_form'] ) && ( ! $form_id || $form_id == $frm_vars['current_form']->id ) ) { | |
| 1084 | + if ( isset( $frm_vars['current_form'] ) && $frm_vars['current_form'] && ( ! $form_id || $form_id == $frm_vars['current_form']->id ) ) { | |
| 1220 | 1085 | return $frm_vars['current_form']; |
| 1221 | 1086 | } |
| 1222 | 1087 | |
| 1223 | 1088 | $form_id = FrmAppHelper::get_param( 'form', $form_id, 'get', 'absint' ); |
| 1224 | - | |
| 1225 | 1089 | if ( $form_id ) { |
| 1226 | 1090 | $form_id = self::set_current_form( $form_id ); |
| 1227 | 1091 | } |
| 1228 | 1092 | |
| @@ -1228,16 +1092,10 @@ | ||
| 1228 | 1092 | |
| 1229 | 1093 | return $form_id; |
| 1230 | 1094 | } |
| 1231 | 1095 | |
| 1232 | - /** | |
| 1233 | - * @param int $form_id | |
| 1234 | - * | |
| 1235 | - * @return false|object | |
| 1236 | - */ | |
| 1237 | 1096 | public static function get_current_form( $form_id = 0 ) { |
| 1238 | 1097 | $form = self::maybe_get_current_form( $form_id ); |
| 1239 | - | |
| 1240 | 1098 | if ( is_numeric( $form ) ) { |
| 1241 | 1099 | $form = self::set_current_form( $form ); |
| 1242 | 1100 | } |
| 1243 | 1101 | |
| @@ -1243,18 +1101,12 @@ | ||
| 1243 | 1101 | |
| 1244 | 1102 | return $form; |
| 1245 | 1103 | } |
| 1246 | 1104 | |
| 1247 | - /** | |
| 1248 | - * @param int $form_id | |
| 1249 | - * | |
| 1250 | - * @return false|object | |
| 1251 | - */ | |
| 1252 | 1105 | public static function set_current_form( $form_id ) { |
| 1253 | 1106 | global $frm_vars; |
| 1254 | 1107 | |
| 1255 | 1108 | $query = array(); |
| 1256 | - | |
| 1257 | 1109 | if ( $form_id ) { |
| 1258 | 1110 | $query['id'] = $form_id; |
| 1259 | 1111 | } |
| 1260 | 1112 | |
| @@ -1262,19 +1114,11 @@ | ||
| 1262 | 1114 | |
| 1263 | 1115 | return $frm_vars['current_form']; |
| 1264 | 1116 | } |
| 1265 | 1117 | |
| 1266 | - /** | |
| 1267 | - * @param object $form | |
| 1268 | - * @param int|string $this_load | |
| 1269 | - * @param bool $global_load | |
| 1270 | - * | |
| 1271 | - * @return bool | |
| 1272 | - */ | |
| 1273 | 1118 | public static function is_form_loaded( $form, $this_load, $global_load ) { |
| 1274 | 1119 | global $frm_vars; |
| 1275 | 1120 | $small_form = new stdClass(); |
| 1276 | - | |
| 1277 | 1121 | foreach ( array( 'id', 'form_key', 'name' ) as $var ) { |
| 1278 | 1122 | $small_form->{$var} = $form->{$var}; |
| 1279 | 1123 | unset( $var ); |
| 1280 | 1124 | } |
| @@ -1285,9 +1129,9 @@ | ||
| 1285 | 1129 | $global_load = true; |
| 1286 | 1130 | $frm_vars['load_css'] = true; |
| 1287 | 1131 | } |
| 1288 | 1132 | |
| 1289 | - return empty( $frm_vars['css_loaded'] ) && $global_load; | |
| 1133 | + return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load ); | |
| 1290 | 1134 | } |
| 1291 | 1135 | |
| 1292 | 1136 | /** |
| 1293 | 1137 | * @since 4.06.03 |
| @@ -1302,24 +1146,11 @@ | ||
| 1302 | 1146 | } else { |
| 1303 | 1147 | $visible = true; |
| 1304 | 1148 | } |
| 1305 | 1149 | |
| 1306 | - /** | |
| 1307 | - * @since 6.25 | |
| 1308 | - * | |
| 1309 | - * @param bool $visible | |
| 1310 | - * @param object $form | |
| 1311 | - */ | |
| 1312 | - $visible = (bool) apply_filters( 'frm_form_is_visible', $visible, $form ); | |
| 1313 | - | |
| 1314 | 1150 | return $visible; |
| 1315 | 1151 | } |
| 1316 | 1152 | |
| 1317 | - /** | |
| 1318 | - * @param object $form | |
| 1319 | - * | |
| 1320 | - * @return bool | |
| 1321 | - */ | |
| 1322 | 1153 | public static function show_submit( $form ) { |
| 1323 | 1154 | $show = ( ! $form->is_template && $form->status === 'published' && ! FrmAppHelper::is_admin() ); |
| 1324 | 1155 | $show = apply_filters( 'frm_show_submit_button', $show, $form ); |
| 1325 | 1156 | |
| @@ -1327,18 +1158,14 @@ | ||
| 1327 | 1158 | } |
| 1328 | 1159 | |
| 1329 | 1160 | /** |
| 1330 | 1161 | * @since 2.3 |
| 1331 | - * | |
| 1332 | - * @param array $atts Attributes including form, option, and default. | |
| 1333 | - * | |
| 1334 | - * @return mixed | |
| 1335 | 1162 | */ |
| 1336 | 1163 | public static function get_option( $atts ) { |
| 1337 | 1164 | $form = $atts['form']; |
| 1338 | - $default = $atts['default'] ?? ''; | |
| 1165 | + $default = isset( $atts['default'] ) ? $atts['default'] : ''; | |
| 1339 | 1166 | |
| 1340 | - return $form->options[ $atts['option'] ] ?? $default; | |
| 1167 | + return isset( $form->options[ $atts['option'] ] ) ? $form->options[ $atts['option'] ] : $default; | |
| 1341 | 1168 | } |
| 1342 | 1169 | |
| 1343 | 1170 | /** |
| 1344 | 1171 | * Get the link to edit this form. |
| @@ -1343,12 +1170,9 @@ | ||
| 1343 | 1170 | /** |
| 1344 | 1171 | * Get the link to edit this form. |
| 1345 | 1172 | * |
| 1346 | 1173 | * @since 4.0 |
| 1347 | - * | |
| 1348 | 1174 | * @param int $form_id The id of the form. |
| 1349 | - * | |
| 1350 | - * @return string | |
| 1351 | 1175 | */ |
| 1352 | 1176 | public static function get_edit_link( $form_id ) { |
| 1353 | 1177 | return admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id ); |
| 1354 | 1178 | } |
| @@ -1358,9 +1182,8 @@ | ||
| 1358 | 1182 | * |
| 1359 | 1183 | * @since 6.2 |
| 1360 | 1184 | * |
| 1361 | 1185 | * @param stdClass $form |
| 1362 | - * | |
| 1363 | 1186 | * @return bool |
| 1364 | 1187 | */ |
| 1365 | 1188 | public static function is_ajax_on( $form ) { |
| 1366 | 1189 | return ! empty( $form->options['ajax_submit'] ); |
| @@ -1369,9 +1192,8 @@ | ||
| 1369 | 1192 | /** |
| 1370 | 1193 | * Get the latest form available. |
| 1371 | 1194 | * |
| 1372 | 1195 | * @since 6.8 |
| 1373 | - * | |
| 1374 | 1196 | * @return object |
| 1375 | 1197 | */ |
| 1376 | 1198 | public static function get_latest_form() { |
| 1377 | 1199 | |
| @@ -1391,9 +1213,8 @@ | ||
| 1391 | 1213 | /** |
| 1392 | 1214 | * Count and return total forms. |
| 1393 | 1215 | * |
| 1394 | 1216 | * @since 6.8 |
| 1395 | - * | |
| 1396 | 1217 | * @return int |
| 1397 | 1218 | */ |
| 1398 | 1219 | public static function get_forms_count() { |
| 1399 | 1220 | |
| @@ -1411,13 +1232,11 @@ | ||
| 1411 | 1232 | } |
| 1412 | 1233 | |
| 1413 | 1234 | /** |
| 1414 | 1235 | * @deprecated 2.03.05 This is still referenced in a few add ons (API, locations). |
| 1415 | - * | |
| 1416 | 1236 | * @codeCoverageIgnore |
| 1417 | 1237 | * |
| 1418 | 1238 | * @param string $key |
| 1419 | - * | |
| 1420 | 1239 | * @return int form id |
| 1421 | 1240 | */ |
| 1422 | 1241 | public static function getIdByKey( $key ) { |
| 1423 | 1242 | _deprecated_function( __FUNCTION__, '2.03.05', 'FrmForm::get_id_by_key' ); |
| @@ -1425,13 +1244,11 @@ | ||
| 1425 | 1244 | } |
| 1426 | 1245 | |
| 1427 | 1246 | /** |
| 1428 | 1247 | * @deprecated 2.03.05 This is still referenced in the API add on as of v1.13. |
| 1429 | - * | |
| 1430 | 1248 | * @codeCoverageIgnore |
| 1431 | 1249 | * |
| 1432 | 1250 | * @param int|string $id |
| 1433 | - * | |
| 1434 | 1251 | * @return string |
| 1435 | 1252 | */ |
| 1436 | 1253 | public static function getKeyById( $id ) { |
| 1437 | 1254 | _deprecated_function( __FUNCTION__, '2.03.05', 'FrmForm::get_key_by_id' ); |