| @@ -6,10 +6,9 @@ | ||
| 6 | 6 | class FrmForm { |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * @param array $values |
| 10 | - * | |
| 11 | - * @return bool|int id on success or false on failure. | |
| 10 | + * @return int|bool id on success or false on failure. | |
| 12 | 11 | */ |
| 13 | 12 | public static function create( $values ) { |
| 14 | 13 | global $wpdb; |
| 15 | 14 | |
| @@ -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,22 +69,14 @@ | ||
| 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 | - * @return bool|int ID on success or false on failure | |
| 73 | + * @return int|boolean 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; |
| 86 | 77 | |
| 87 | 78 | $values = self::getOne( $id, $blog_id ); |
| 88 | - | |
| 89 | 79 | if ( ! $values ) { |
| 90 | 80 | return false; |
| 91 | 81 | } |
| 92 | 82 | |
| @@ -103,10 +93,10 @@ | ||
| 103 | 93 | 'is_template' => $template ? 1 : 0, |
| 104 | 94 | ); |
| 105 | 95 | |
| 106 | 96 | if ( $blog_id ) { |
| 107 | - $new_values['status'] = 'published'; | |
| 108 | - $new_options = $values->options; | |
| 97 | + $new_values['status'] = 'published'; | |
| 98 | + $new_options = $values->options; | |
| 109 | 99 | FrmAppHelper::unserialize_or_decode( $new_options ); |
| 110 | 100 | $new_options['email_to'] = get_option( 'admin_email' ); |
| 111 | 101 | $new_options['copy'] = false; |
| 112 | 102 | $new_values['options'] = $new_options; |
| @@ -135,16 +125,10 @@ | ||
| 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 | - $new_opts = $values['options']; | |
| 130 | + $new_opts = $values['options']; | |
| 147 | 131 | FrmAppHelper::unserialize_or_decode( $new_opts ); |
| 148 | 132 | $values['options'] = $new_opts; |
| 149 | 133 | |
| 150 | 134 | if ( isset( $new_opts['success_msg'] ) ) { |
| @@ -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,11 +157,10 @@ | ||
| 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 | - $sql_cols .= ',fi.' . $key; | |
| 162 | + $sql_cols .= ( ',fi.' . $key ); | |
| 182 | 163 | } |
| 183 | 164 | |
| 184 | 165 | $fields = FrmDb::get_results( |
| 185 | 166 | "{$wpdb->prefix}frm_fields AS fi LEFT OUTER JOIN {$wpdb->prefix}frm_forms AS fr ON fi.form_id = fr.id", |
| @@ -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 | } |
| @@ -232,9 +210,9 @@ | ||
| 232 | 210 | |
| 233 | 211 | if ( $new_val !== $value ) { |
| 234 | 212 | $new_values[ $key ] = $new_val; |
| 235 | 213 | } |
| 236 | - }//end foreach | |
| 214 | + } | |
| 237 | 215 | |
| 238 | 216 | if ( ! empty( $new_values ) ) { |
| 239 | 217 | FrmField::update( $field['id'], $new_values ); |
| 240 | 218 | } |
| @@ -240,15 +218,9 @@ | ||
| 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 | - * @return bool|int | |
| 222 | + * @return int|boolean | |
| 251 | 223 | */ |
| 252 | 224 | public static function update( $id, $values, $create_link = false ) { |
| 253 | 225 | global $wpdb; |
| 254 | 226 | |
| @@ -271,15 +243,14 @@ | ||
| 271 | 243 | $new_values[ $value_key ] = $value; |
| 272 | 244 | } |
| 273 | 245 | } |
| 274 | 246 | |
| 275 | - if ( ! empty( $values['new_status'] ) ) { | |
| 247 | + if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) { | |
| 276 | 248 | $new_values['status'] = $values['new_status']; |
| 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'] ) ) { |
| @@ -306,16 +276,21 @@ | ||
| 306 | 276 | if ( ! isset( $values['options'] ) ) { |
| 307 | 277 | return $new_values; |
| 308 | 278 | } |
| 309 | 279 | |
| 310 | - $options = ! empty( $values['options'] ) ? (array) $values['options'] : array(); | |
| 280 | + $options = isset( $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' ); | |
| 316 | - $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' ); | |
| 317 | 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 | + | |
| 318 | 293 | /** |
| 319 | 294 | * Allows modifying form options before updating or creating. |
| 320 | 295 | * |
| 321 | 296 | * @since 5.4 Added the third param. |
| @@ -331,11 +306,8 @@ | ||
| 331 | 306 | return $new_values; |
| 332 | 307 | } |
| 333 | 308 | |
| 334 | 309 | /** |
| 335 | - * @param int $id Form ID. | |
| 336 | - * @param array $values Form values array. | |
| 337 | - * | |
| 338 | 310 | * @return array |
| 339 | 311 | */ |
| 340 | 312 | public static function update_fields( $id, $values ) { |
| 341 | 313 | |
| @@ -343,9 +315,8 @@ | ||
| 343 | 315 | return $values; |
| 344 | 316 | } |
| 345 | 317 | |
| 346 | 318 | $all_fields = FrmField::get_all_for_form( $id ); |
| 347 | - | |
| 348 | 319 | if ( empty( $all_fields ) ) { |
| 349 | 320 | return $values; |
| 350 | 321 | } |
| 351 | 322 | |
| @@ -354,9 +325,8 @@ | ||
| 354 | 325 | } |
| 355 | 326 | |
| 356 | 327 | $field_array = array(); |
| 357 | 328 | $existing_keys = array_keys( $values['item_meta'] ); |
| 358 | - | |
| 359 | 329 | foreach ( $all_fields as $fid ) { |
| 360 | 330 | if ( ! in_array( $fid->id, $existing_keys ) && ( isset( $values['frm_fields_submitted'] ) && in_array( $fid->id, $values['frm_fields_submitted'] ) ) || isset( $values['options'] ) ) { |
| 361 | 331 | $values['item_meta'][ $fid->id ] = ''; |
| 362 | 332 | } |
| @@ -375,9 +345,8 @@ | ||
| 375 | 345 | continue; |
| 376 | 346 | } |
| 377 | 347 | |
| 378 | 348 | $is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ); |
| 379 | - | |
| 380 | 349 | if ( $is_settings_page ) { |
| 381 | 350 | self::get_settings_page_html( $values, $field ); |
| 382 | 351 | |
| 383 | 352 | if ( ! defined( 'WP_IMPORTING' ) ) { |
| @@ -384,20 +353,15 @@ | ||
| 384 | 353 | continue; |
| 385 | 354 | } |
| 386 | 355 | } |
| 387 | 356 | |
| 388 | - // Updating the form. | |
| 357 | + //updating the form | |
| 389 | 358 | $update_options = FrmFieldsHelper::get_default_field_options_from_field( $field ); |
| 390 | - // Don't check for POST html. | |
| 391 | - unset( $update_options['custom_html'] ); | |
| 359 | + unset( $update_options['custom_html'] ); // don't check for POST html | |
| 392 | 360 | $update_options = apply_filters( 'frm_field_options_to_update', $update_options ); |
| 393 | 361 | |
| 394 | - if ( ! is_array( $field->field_options ) ) { | |
| 395 | - $field->field_options = array(); | |
| 396 | - } | |
| 397 | - | |
| 398 | 362 | foreach ( $update_options as $opt => $default ) { |
| 399 | - $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; | |
| 400 | 364 | self::sanitize_field_opt( $opt, $field->field_options[ $opt ] ); |
| 401 | 365 | } |
| 402 | 366 | |
| 403 | 367 | $field->field_options = apply_filters( 'frm_update_field_options', $field->field_options, $field, $values ); |
| @@ -406,25 +370,14 @@ | ||
| 406 | 370 | 'field_options' => $field->field_options, |
| 407 | 371 | 'default_value' => isset( $values[ 'default_value_' . $field_id ] ) ? FrmAppHelper::maybe_json_encode( $values[ 'default_value_' . $field_id ] ) : '', |
| 408 | 372 | ); |
| 409 | 373 | |
| 410 | - if ( ! FrmAppHelper::allow_unfiltered_html() && isset( $values['field_options'][ 'options_' . $field_id ] ) && is_array( $values['field_options'][ 'options_' . $field_id ] ) ) { | |
| 411 | - foreach ( $values['field_options'][ 'options_' . $field_id ] as $option_key => $option ) { | |
| 412 | - if ( is_array( $option ) ) { | |
| 413 | - foreach ( $option as $key => $item ) { | |
| 414 | - $values['field_options'][ 'options_' . $field_id ][ $option_key ][ $key ] = FrmAppHelper::kses( $item, 'all' ); | |
| 415 | - } | |
| 416 | - } | |
| 417 | - } | |
| 418 | - } | |
| 419 | - | |
| 420 | 374 | self::prepare_field_update_values( $field, $values, $new_field ); |
| 421 | - self::maybe_update_max_option( $field, $values, $new_field ); | |
| 422 | 375 | |
| 423 | 376 | FrmField::update( $field_id, $new_field ); |
| 424 | 377 | |
| 425 | 378 | FrmField::delete_form_transient( $field->form_id ); |
| 426 | - }//end foreach | |
| 379 | + } | |
| 427 | 380 | self::clear_form_cache(); |
| 428 | 381 | |
| 429 | 382 | return $values; |
| 430 | 383 | } |
| @@ -429,37 +382,10 @@ | ||
| 429 | 382 | return $values; |
| 430 | 383 | } |
| 431 | 384 | |
| 432 | 385 | /** |
| 433 | - * Resets the 'max' option of a field when changing paragraph field type to other field types like text, email etc. | |
| 434 | - * | |
| 435 | - * @since 6.7 | |
| 436 | - * | |
| 437 | - * @param array $field | |
| 438 | - * @param array $values | |
| 439 | - * @param array $new_field | |
| 440 | - * | |
| 441 | - * @return void | |
| 442 | - */ | |
| 443 | - private static function maybe_update_max_option( $field, $values, &$new_field ) { | |
| 444 | - if ( $field->type === 'textarea' && | |
| 445 | - ! empty( $values['field_options'][ 'type_' . $field->id ] ) && | |
| 446 | - in_array( $values['field_options'][ 'type_' . $field->id ], array( 'text', 'email', 'url', 'password', 'phone' ), true ) ) { | |
| 447 | - | |
| 448 | - $new_field['field_options']['max'] = ''; | |
| 449 | - | |
| 450 | - /** | |
| 451 | - * Update posted field setting so that new 'max' option is displayed after form is saved and page reloads. | |
| 452 | - * FrmFieldsHelper::fill_default_field_opts populates field options by calling self::get_posted_field_setting. | |
| 453 | - */ | |
| 454 | - $_POST['field_options'][ 'max_' . $field->id ] = ''; | |
| 455 | - } | |
| 456 | - } | |
| 457 | - | |
| 458 | - /** | |
| 459 | 386 | * @param string $opt |
| 460 | 387 | * @param mixed $value |
| 461 | - * | |
| 462 | 388 | * @return void |
| 463 | 389 | */ |
| 464 | 390 | private static function sanitize_field_opt( $opt, &$value ) { |
| 465 | 391 | if ( ! is_string( $value ) ) { |
| @@ -491,9 +417,8 @@ | ||
| 491 | 417 | } |
| 492 | 418 | |
| 493 | 419 | /** |
| 494 | 420 | * @param string $value |
| 495 | - * | |
| 496 | 421 | * @return string |
| 497 | 422 | */ |
| 498 | 423 | private static function sanitize_calc( $value ) { |
| 499 | 424 | if ( false !== strpos( $value, '<' ) ) { |
| @@ -498,10 +423,9 @@ | ||
| 498 | 423 | private static function sanitize_calc( $value ) { |
| 499 | 424 | if ( false !== strpos( $value, '<' ) ) { |
| 500 | 425 | $value = self::normalize_calc_spaces( $value ); |
| 501 | 426 | } |
| 502 | - // Allow <= and >=. | |
| 503 | - $allow = array( '<= ', ' >=' ); | |
| 427 | + $allow = array( '<= ', ' >=' ); // Allow <= and >= | |
| 504 | 428 | $temp = array( '< = ', ' > =' ); |
| 505 | 429 | $value = str_replace( $allow, $temp, $value ); |
| 506 | 430 | $value = strip_tags( $value ); |
| 507 | 431 | $value = str_replace( $temp, $allow, $value ); |
| @@ -512,44 +436,35 @@ | ||
| 512 | 436 | * Format a comparison like 5<10 to 5 < 10. Also works on 5< 10, 5 <10, 5<=10 variations. |
| 513 | 437 | * This is to avoid an issue with unspaced calculations being recognized as HTML that gets removed when strip_tags is called. |
| 514 | 438 | * |
| 515 | 439 | * @param string $calc |
| 516 | - * | |
| 517 | 440 | * @return string |
| 518 | 441 | */ |
| 519 | 442 | private static function normalize_calc_spaces( $calc ) { |
| 520 | 443 | // Check for a pattern with 5 parts |
| 521 | - // $1 \d|\] the first comparison digit or the end of a comparison shortcode. | |
| 444 | + // $1 \d the first comparison digit. | |
| 522 | 445 | // $2 a space (optional). |
| 523 | 446 | // $3 an equals sign (optional) that follows the < operator for <= comparisons. |
| 524 | 447 | // $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; | |
| 448 | + // $5 \d the second comparison digit. | |
| 449 | + return preg_replace( '/(\d)( ){0,1}<(=){0,1}( ){0,1}(\d)/', '$1 <$3 $5', $calc ); | |
| 529 | 450 | } |
| 530 | 451 | |
| 531 | 452 | /** |
| 532 | 453 | * 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 | 454 | */ |
| 539 | 455 | private static function get_settings_page_html( $values, &$field ) { |
| 540 | 456 | if ( isset( $values['field_options'][ 'custom_html_' . $field->id ] ) ) { |
| 541 | 457 | $prev_opts = array(); |
| 542 | - $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 ); | |
| 543 | 459 | |
| 544 | - $field->field_options['custom_html'] = $values['field_options'][ 'custom_html_' . $field->id ] ?? $fallback_html; | |
| 545 | - } 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' ) { | |
| 546 | 462 | $prev_opts = $field->field_options; |
| 547 | 463 | } |
| 548 | 464 | |
| 549 | 465 | if ( isset( $prev_opts ) ) { |
| 550 | 466 | $field->field_options = apply_filters( 'frm_update_form_field_options', $field->field_options, $field, $values ); |
| 551 | - | |
| 552 | 467 | if ( $prev_opts != $field->field_options ) { |
| 553 | 468 | FrmField::update( $field->id, array( 'field_options' => $field->field_options ) ); |
| 554 | 469 | } |
| 555 | 470 | } |
| @@ -554,15 +469,8 @@ | ||
| 554 | 469 | } |
| 555 | 470 | } |
| 556 | 471 | } |
| 557 | 472 | |
| 558 | - /** | |
| 559 | - * @param object $field | |
| 560 | - * @param array $values | |
| 561 | - * @param array $new_field | |
| 562 | - * | |
| 563 | - * @return void | |
| 564 | - */ | |
| 565 | 473 | private static function prepare_field_update_values( $field, $values, &$new_field ) { |
| 566 | 474 | $field_cols = array( |
| 567 | 475 | 'field_order' => 0, |
| 568 | 476 | 'field_key' => '', |
| @@ -571,16 +479,12 @@ | ||
| 571 | 479 | 'description' => '', |
| 572 | 480 | 'options' => '', |
| 573 | 481 | 'name' => '', |
| 574 | 482 | ); |
| 575 | - | |
| 576 | 483 | foreach ( $field_cols as $col => $default ) { |
| 577 | - $default = $default === '' ? $field->{$col} : $default; | |
| 578 | - $new_field[ $col ] = $values['field_options'][ $col . '_' . $field->id ] ?? $default; | |
| 579 | - } | |
| 484 | + $default = ( $default === '' ) ? $field->{$col} : $default; | |
| 580 | 485 | |
| 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; | |
| 486 | + $new_field[ $col ] = isset( $values['field_options'][ $col . '_' . $field->id ] ) ? $values['field_options'][ $col . '_' . $field->id ] : $default; | |
| 583 | 487 | } |
| 584 | 488 | |
| 585 | 489 | // Don't save the template option. |
| 586 | 490 | if ( is_array( $new_field['options'] ) && isset( $new_field['options']['000'] ) ) { |
| @@ -592,12 +496,9 @@ | ||
| 592 | 496 | * Get a list of all form settings that should be translated |
| 593 | 497 | * on a multilingual site. |
| 594 | 498 | * |
| 595 | 499 | * @since 3.06.01 |
| 596 | - * | |
| 597 | - * @param object $form The form object. | |
| 598 | - * | |
| 599 | - * @return array | |
| 500 | + * @param object $form - The form object | |
| 600 | 501 | */ |
| 601 | 502 | public static function translatable_strings( $form ) { |
| 602 | 503 | $strings = array( |
| 603 | 504 | 'name', |
| @@ -614,12 +515,11 @@ | ||
| 614 | 515 | return apply_filters( 'frm_form_strings', $strings, $form ); |
| 615 | 516 | } |
| 616 | 517 | |
| 617 | 518 | /** |
| 618 | - * @param int $id | |
| 619 | 519 | * @param string $status |
| 620 | 520 | * |
| 621 | - * @return bool|int | |
| 521 | + * @return int|boolean | |
| 622 | 522 | */ |
| 623 | 523 | public static function set_status( $id, $status ) { |
| 624 | 524 | if ( 'trash' == $status ) { |
| 625 | 525 | return self::trash( $id ); |
| @@ -625,10 +525,9 @@ | ||
| 625 | 525 | return self::trash( $id ); |
| 626 | 526 | } |
| 627 | 527 | |
| 628 | 528 | $statuses = array( 'published', 'draft', 'trash' ); |
| 629 | - | |
| 630 | - if ( ! in_array( $status, $statuses, true ) ) { | |
| 529 | + if ( ! in_array( $status, $statuses ) ) { | |
| 631 | 530 | return false; |
| 632 | 531 | } |
| 633 | 532 | |
| 634 | 533 | global $wpdb; |
| @@ -655,11 +554,9 @@ | ||
| 655 | 554 | return $query_results; |
| 656 | 555 | } |
| 657 | 556 | |
| 658 | 557 | /** |
| 659 | - * @param int|string $id Form ID. | |
| 660 | - * | |
| 661 | - * @return bool|int | |
| 558 | + * @return int|boolean | |
| 662 | 559 | */ |
| 663 | 560 | public static function trash( $id ) { |
| 664 | 561 | if ( ! EMPTY_TRASH_DAYS ) { |
| 665 | 562 | return self::destroy( $id ); |
| @@ -665,17 +562,12 @@ | ||
| 665 | 562 | return self::destroy( $id ); |
| 666 | 563 | } |
| 667 | 564 | |
| 668 | 565 | $form = self::getOne( $id ); |
| 669 | - | |
| 670 | 566 | if ( ! $form ) { |
| 671 | 567 | return false; |
| 672 | 568 | } |
| 673 | 569 | |
| 674 | - if ( $form->status === 'trash' ) { | |
| 675 | - return false; | |
| 676 | - } | |
| 677 | - | |
| 678 | 570 | $options = $form->options; |
| 679 | 571 | $options['trash_time'] = time(); |
| 680 | 572 | |
| 681 | 573 | global $wpdb; |
| @@ -708,26 +600,21 @@ | ||
| 708 | 600 | return $query_results; |
| 709 | 601 | } |
| 710 | 602 | |
| 711 | 603 | /** |
| 712 | - * @param int|string $id Form ID. | |
| 713 | - * | |
| 714 | - * @return bool|int | |
| 604 | + * @return int|boolean | |
| 715 | 605 | */ |
| 716 | 606 | public static function destroy( $id ) { |
| 717 | 607 | global $wpdb; |
| 718 | 608 | |
| 719 | 609 | $form = self::getOne( $id ); |
| 720 | - | |
| 721 | 610 | if ( ! $form ) { |
| 722 | 611 | return false; |
| 723 | 612 | } |
| 724 | - | |
| 725 | 613 | $id = $form->id; |
| 726 | 614 | |
| 727 | 615 | // Disconnect the entries from this form |
| 728 | 616 | $entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) ); |
| 729 | - | |
| 730 | 617 | foreach ( $entries as $entry_id ) { |
| 731 | 618 | FrmEntry::destroy( $entry_id ); |
| 732 | 619 | unset( $entry_id ); |
| 733 | 620 | } |
| @@ -735,14 +622,10 @@ | ||
| 735 | 622 | // Disconnect the fields from this form |
| 736 | 623 | $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 | 624 | |
| 738 | 625 | $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) ); |
| 739 | - | |
| 740 | 626 | if ( $query_results ) { |
| 741 | 627 | // Delete all form actions linked to this form |
| 742 | - /** | |
| 743 | - * @var FrmFormAction | |
| 744 | - */ | |
| 745 | 628 | $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
| 746 | 629 | $action_control->destroy( $id, 'all' ); |
| 747 | 630 | |
| 748 | 631 | // Clear form caching |
| @@ -757,16 +640,14 @@ | ||
| 757 | 640 | |
| 758 | 641 | /** |
| 759 | 642 | * Delete trashed forms based on how long they have been trashed |
| 760 | 643 | * |
| 761 | - * @param int|string $delete_timestamp Timestamp cutoff for deletion. | |
| 762 | - * | |
| 763 | 644 | * @return int The number of forms deleted |
| 764 | 645 | */ |
| 765 | 646 | public static function scheduled_delete( $delete_timestamp = '' ) { |
| 766 | 647 | global $wpdb; |
| 767 | 648 | |
| 768 | - $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' ); | |
| 769 | 650 | |
| 770 | 651 | if ( ! $trash_forms ) { |
| 771 | 652 | return 0; |
| 772 | 653 | } |
| @@ -775,18 +656,13 @@ | ||
| 775 | 656 | $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); |
| 776 | 657 | } |
| 777 | 658 | |
| 778 | 659 | $count = 0; |
| 779 | - | |
| 780 | 660 | foreach ( $trash_forms as $form ) { |
| 781 | 661 | FrmAppHelper::unserialize_or_decode( $form->options ); |
| 782 | - | |
| 783 | 662 | if ( ! isset( $form->options['trash_time'] ) || $form->options['trash_time'] < $delete_timestamp ) { |
| 784 | 663 | self::destroy( $form->id ); |
| 785 | - | |
| 786 | - if ( empty( $form->parent_form_id ) ) { | |
| 787 | - ++$count; | |
| 788 | - } | |
| 664 | + $count ++; | |
| 789 | 665 | } |
| 790 | 666 | |
| 791 | 667 | unset( $form ); |
| 792 | 668 | } |
| @@ -794,15 +670,12 @@ | ||
| 794 | 670 | return $count; |
| 795 | 671 | } |
| 796 | 672 | |
| 797 | 673 | /** |
| 798 | - * @param int|string $id Form ID or key. | |
| 799 | - * | |
| 800 | 674 | * @return string form name |
| 801 | 675 | */ |
| 802 | 676 | public static function getName( $id ) { |
| 803 | 677 | $form = FrmDb::check_cache( $id, 'frm_form' ); |
| 804 | - | |
| 805 | 678 | if ( $form ) { |
| 806 | 679 | $r = stripslashes( $form->name ); |
| 807 | 680 | |
| 808 | 681 | return $r; |
| @@ -809,12 +682,10 @@ | ||
| 809 | 682 | } |
| 810 | 683 | |
| 811 | 684 | $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
| 812 | 685 | $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
| 686 | + $r = stripslashes( $r ); | |
| 813 | 687 | |
| 814 | - // An empty form name can result in a null value. | |
| 815 | - $r = is_null( $r ) ? '' : stripslashes( $r ); | |
| 816 | - | |
| 817 | 688 | return $r; |
| 818 | 689 | } |
| 819 | 690 | |
| 820 | 691 | /** |
| @@ -830,9 +701,9 @@ | ||
| 830 | 701 | |
| 831 | 702 | /** |
| 832 | 703 | * @since 3.0 |
| 833 | 704 | * |
| 834 | - * @param int|string $id | |
| 705 | + * @param int $id | |
| 835 | 706 | * |
| 836 | 707 | * @return string form key |
| 837 | 708 | */ |
| 838 | 709 | public static function get_key_by_id( $id ) { |
| @@ -837,9 +708,8 @@ | ||
| 837 | 708 | */ |
| 838 | 709 | public static function get_key_by_id( $id ) { |
| 839 | 710 | $id = (int) $id; |
| 840 | 711 | $cache = FrmDb::check_cache( $id, 'frm_form' ); |
| 841 | - | |
| 842 | 712 | if ( $cache ) { |
| 843 | 713 | return $cache->form_key; |
| 844 | 714 | } |
| 845 | 715 | |
| @@ -850,13 +720,11 @@ | ||
| 850 | 720 | |
| 851 | 721 | /** |
| 852 | 722 | * If $form is numeric, get the form object |
| 853 | 723 | * |
| 724 | + * @param object|int $form | |
| 725 | + * | |
| 854 | 726 | * @since 2.0.9 |
| 855 | - * | |
| 856 | - * @param int|object $form | |
| 857 | - * | |
| 858 | - * @return void | |
| 859 | 727 | */ |
| 860 | 728 | public static function maybe_get_form( &$form ) { |
| 861 | 729 | if ( ! is_object( $form ) && ! is_array( $form ) && ! empty( $form ) ) { |
| 862 | 730 | $form = self::getOne( $form ); |
| @@ -863,28 +731,27 @@ | ||
| 863 | 731 | } |
| 864 | 732 | } |
| 865 | 733 | |
| 866 | 734 | /** |
| 867 | - * @param int|string $id | |
| 868 | - * @param false|int $blog_id | |
| 869 | - * | |
| 870 | - * @return stdClass|null | |
| 735 | + * @return object form | |
| 871 | 736 | */ |
| 872 | 737 | public static function getOne( $id, $blog_id = false ) { |
| 873 | 738 | global $wpdb; |
| 874 | 739 | |
| 875 | 740 | if ( $blog_id && is_multisite() ) { |
| 876 | - $prefix = $wpdb->get_blog_prefix( $blog_id ); | |
| 741 | + global $wpmuBaseTablePrefix; | |
| 742 | + $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id ); | |
| 743 | + | |
| 877 | 744 | $table_name = $prefix . 'frm_forms'; |
| 878 | 745 | } else { |
| 879 | 746 | $table_name = $wpdb->prefix . 'frm_forms'; |
| 880 | 747 | $cache = wp_cache_get( $id, 'frm_form' ); |
| 881 | - | |
| 882 | 748 | if ( $cache ) { |
| 883 | 749 | if ( isset( $cache->options ) ) { |
| 884 | 750 | FrmAppHelper::unserialize_or_decode( $cache->options ); |
| 885 | 751 | } |
| 886 | - return self::prepare_form_row_data( $cache ); | |
| 752 | + | |
| 753 | + return apply_filters( 'frm_form_object', wp_unslash( $cache ) ); | |
| 887 | 754 | } |
| 888 | 755 | } |
| 889 | 756 | |
| 890 | 757 | if ( is_numeric( $id ) ) { |
| @@ -899,49 +766,17 @@ | ||
| 899 | 766 | FrmDb::set_cache( $results->id, $results, 'frm_form' ); |
| 900 | 767 | FrmAppHelper::unserialize_or_decode( $results->options ); |
| 901 | 768 | } |
| 902 | 769 | |
| 903 | - return self::prepare_form_row_data( $results ); | |
| 770 | + return apply_filters( 'frm_form_object', wp_unslash( $results ) ); | |
| 904 | 771 | } |
| 905 | 772 | |
| 906 | 773 | /** |
| 907 | - * Make sure that if $row is an object, that $row->options is an array and not a string. | |
| 908 | - * | |
| 909 | - * @since 6.8.3 | |
| 910 | - * | |
| 911 | - * @param stdClass|null $row The database row for a target form. | |
| 912 | - * | |
| 913 | - * @return stdClass|null | |
| 774 | + * @return object|array of objects | |
| 914 | 775 | */ |
| 915 | - private static function prepare_form_row_data( $row ) { | |
| 916 | - $row = wp_unslash( $row ); | |
| 917 | - | |
| 918 | - if ( ! is_object( $row ) ) { | |
| 919 | - return $row; | |
| 920 | - } | |
| 921 | - | |
| 922 | - if ( ! is_array( $row->options ) ) { | |
| 923 | - $row->options = FrmFormsHelper::get_default_opts(); | |
| 924 | - } | |
| 925 | - | |
| 926 | - /** | |
| 927 | - * @since 4.03.02 | |
| 928 | - * | |
| 929 | - * @param stdClass $row | |
| 930 | - */ | |
| 931 | - return apply_filters( 'frm_form_object', $row ); | |
| 932 | - } | |
| 933 | - | |
| 934 | - /** | |
| 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 | - * @return array|object of objects | |
| 940 | - */ | |
| 941 | 776 | public static function getAll( $where = array(), $order_by = '', $limit = '' ) { |
| 942 | 777 | if ( is_array( $where ) && ! empty( $where ) ) { |
| 943 | - 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 !'] ) ) { | |
| 944 | 779 | // don't get trashed templates |
| 945 | 780 | $where['status'] = array( null, '', 'published' ); |
| 946 | 781 | } |
| 947 | 782 | |
| @@ -948,9 +783,9 @@ | ||
| 948 | 783 | $results = FrmDb::get_results( 'frm_forms', $where, '*', compact( 'order_by', 'limit' ) ); |
| 949 | 784 | } else { |
| 950 | 785 | global $wpdb; |
| 951 | 786 | |
| 952 | - // 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 | |
| 953 | 788 | $query = 'SELECT * FROM ' . $wpdb->prefix . 'frm_forms' . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . FrmDb::esc_order( $order_by ) . FrmDb::esc_limit( $limit ); |
| 954 | 789 | $results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
| 955 | 790 | } |
| 956 | 791 | |
| @@ -960,9 +795,9 @@ | ||
| 960 | 795 | FrmAppHelper::unserialize_or_decode( $result->options ); |
| 961 | 796 | } |
| 962 | 797 | } |
| 963 | 798 | |
| 964 | - if ( $limit === ' LIMIT 1' || $limit == 1 ) { | |
| 799 | + if ( $limit == ' LIMIT 1' || $limit == 1 ) { | |
| 965 | 800 | // return the first form object if we are only getting one form |
| 966 | 801 | $results = reset( $results ); |
| 967 | 802 | } |
| 968 | 803 | |
| @@ -976,16 +811,14 @@ | ||
| 976 | 811 | * |
| 977 | 812 | * @param array $query |
| 978 | 813 | * @param int $limit |
| 979 | 814 | * @param string $inc_children |
| 980 | - * | |
| 981 | 815 | * @return array|object of forms A single form object would be passed if $limit was set to 1. |
| 982 | 816 | */ |
| 983 | 817 | public static function get_published_forms( $query = array(), $limit = 999, $inc_children = 'exclude' ) { |
| 984 | 818 | $query['is_template'] = 0; |
| 985 | 819 | $query['status'] = array( null, '', 'published' ); |
| 986 | - | |
| 987 | - if ( $inc_children === 'exclude' ) { | |
| 820 | + if ( $inc_children == 'exclude' ) { | |
| 988 | 821 | $query['parent_form_id'] = array( null, 0 ); |
| 989 | 822 | } |
| 990 | 823 | |
| 991 | 824 | $forms = self::getAll( $query, 'name', $limit ); |
| @@ -1001,14 +834,13 @@ | ||
| 1001 | 834 | |
| 1002 | 835 | $cache_key = 'frm_form_counts'; |
| 1003 | 836 | |
| 1004 | 837 | $counts = wp_cache_get( $cache_key, 'frm_form' ); |
| 1005 | - | |
| 1006 | 838 | if ( false !== $counts ) { |
| 1007 | 839 | return $counts; |
| 1008 | 840 | } |
| 1009 | 841 | |
| 1010 | - $results = FrmDb::get_results( | |
| 842 | + $results = (array) FrmDb::get_results( | |
| 1011 | 843 | 'frm_forms', |
| 1012 | 844 | array( |
| 1013 | 845 | 'or' => 1, |
| 1014 | 846 | 'parent_form_id' => null, |
| @@ -1022,18 +854,18 @@ | ||
| 1022 | 854 | |
| 1023 | 855 | foreach ( $results as $row ) { |
| 1024 | 856 | if ( 'trash' != $row->status ) { |
| 1025 | 857 | if ( $row->is_template ) { |
| 1026 | - ++$counts['template']; | |
| 858 | + $counts['template'] ++; | |
| 1027 | 859 | } else { |
| 1028 | - ++$counts['published']; | |
| 860 | + $counts['published'] ++; | |
| 1029 | 861 | } |
| 1030 | 862 | } else { |
| 1031 | - ++$counts['trash']; | |
| 863 | + $counts['trash'] ++; | |
| 1032 | 864 | } |
| 1033 | 865 | |
| 1034 | 866 | if ( 'draft' == $row->status ) { |
| 1035 | - ++$counts['draft']; | |
| 867 | + $counts['draft'] ++; | |
| 1036 | 868 | } |
| 1037 | 869 | |
| 1038 | 870 | unset( $row ); |
| 1039 | 871 | } |
| @@ -1049,10 +881,8 @@ | ||
| 1049 | 881 | * Called when a form is created, updated, duplicated, or deleted |
| 1050 | 882 | * or when the form status is changed |
| 1051 | 883 | * |
| 1052 | 884 | * @since 2.0.4 |
| 1053 | - * | |
| 1054 | - * @return void | |
| 1055 | 885 | */ |
| 1056 | 886 | public static function clear_form_cache() { |
| 1057 | 887 | FrmDb::cache_delete_group( 'frm_form' ); |
| 1058 | 888 | } |
| @@ -1057,22 +887,16 @@ | ||
| 1057 | 887 | FrmDb::cache_delete_group( 'frm_form' ); |
| 1058 | 888 | } |
| 1059 | 889 | |
| 1060 | 890 | /** |
| 1061 | - * @param array $values Form values to validate. | |
| 1062 | - * | |
| 1063 | 891 | * @return array of errors |
| 1064 | 892 | */ |
| 1065 | 893 | public static function validate( $values ) { |
| 1066 | 894 | $errors = array(); |
| 895 | + | |
| 1067 | 896 | return apply_filters( 'frm_validate_form', $errors, $values ); |
| 1068 | 897 | } |
| 1069 | 898 | |
| 1070 | - /** | |
| 1071 | - * @param object|null $form | |
| 1072 | - * | |
| 1073 | - * @return array | |
| 1074 | - */ | |
| 1075 | 899 | public static function get_params( $form = null ) { |
| 1076 | 900 | global $frm_vars; |
| 1077 | 901 | |
| 1078 | 902 | if ( ! $form ) { |
| @@ -1102,17 +926,16 @@ | ||
| 1102 | 926 | ); |
| 1103 | 927 | |
| 1104 | 928 | $values = array(); |
| 1105 | 929 | $values['posted_form_id'] = FrmAppHelper::get_param( 'form_id', '', 'get', 'absint' ); |
| 1106 | - | |
| 1107 | 930 | if ( ! $values['posted_form_id'] ) { |
| 1108 | 931 | $values['posted_form_id'] = FrmAppHelper::get_param( 'form', '', 'get', 'absint' ); |
| 1109 | 932 | } |
| 1110 | 933 | |
| 1111 | 934 | if ( $form->id == $values['posted_form_id'] ) { |
| 1112 | - // 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 | |
| 1113 | 936 | foreach ( $default_values as $var => $default ) { |
| 1114 | - if ( $var === 'action' ) { | |
| 937 | + if ( $var == 'action' ) { | |
| 1115 | 938 | $values[ $var ] = FrmAppHelper::get_param( $action_var, $default, 'get', 'sanitize_title' ); |
| 1116 | 939 | } else { |
| 1117 | 940 | $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
| 1118 | 941 | } |
| @@ -1133,11 +956,8 @@ | ||
| 1133 | 956 | |
| 1134 | 957 | return $values; |
| 1135 | 958 | } |
| 1136 | 959 | |
| 1137 | - /** | |
| 1138 | - * @return array | |
| 1139 | - */ | |
| 1140 | 960 | public static function list_page_params() { |
| 1141 | 961 | $values = array(); |
| 1142 | 962 | $defaults = array( |
| 1143 | 963 | 'template' => 0, |
| @@ -1147,9 +967,8 @@ | ||
| 1147 | 967 | 'search' => '', |
| 1148 | 968 | 'sort' => '', |
| 1149 | 969 | 'sdir' => '', |
| 1150 | 970 | ); |
| 1151 | - | |
| 1152 | 971 | foreach ( $defaults as $var => $default ) { |
| 1153 | 972 | $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
| 1154 | 973 | } |
| 1155 | 974 | |
| @@ -1155,16 +974,10 @@ | ||
| 1155 | 974 | |
| 1156 | 975 | return $values; |
| 1157 | 976 | } |
| 1158 | 977 | |
| 1159 | - /** | |
| 1160 | - * @param int|object|string|null $form | |
| 1161 | - * | |
| 1162 | - * @return array | |
| 1163 | - */ | |
| 1164 | 978 | public static function get_admin_params( $form = null ) { |
| 1165 | 979 | $form_id = $form; |
| 1166 | - | |
| 1167 | 980 | if ( $form === null ) { |
| 1168 | 981 | $form_id = self::get_current_form_id(); |
| 1169 | 982 | } elseif ( $form && is_object( $form ) ) { |
| 1170 | 983 | $form_id = $form->id; |
| @@ -1182,9 +995,8 @@ | ||
| 1182 | 995 | 'sdir' => '', |
| 1183 | 996 | 'fid' => '', |
| 1184 | 997 | 'keep_post' => '', |
| 1185 | 998 | ); |
| 1186 | - | |
| 1187 | 999 | foreach ( $defaults as $var => $default ) { |
| 1188 | 1000 | $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' ); |
| 1189 | 1001 | } |
| 1190 | 1002 | |
| @@ -1190,39 +1002,27 @@ | ||
| 1190 | 1002 | |
| 1191 | 1003 | return $values; |
| 1192 | 1004 | } |
| 1193 | 1005 | |
| 1194 | - /** | |
| 1195 | - * @param string $default_form | |
| 1196 | - * | |
| 1197 | - * @return int|string | |
| 1198 | - */ | |
| 1199 | 1006 | public static function get_current_form_id( $default_form = 'none' ) { |
| 1200 | - if ( 'first' === $default_form ) { | |
| 1007 | + if ( 'first' == $default_form ) { | |
| 1201 | 1008 | $form = self::get_current_form(); |
| 1202 | 1009 | } else { |
| 1203 | 1010 | $form = self::maybe_get_current_form(); |
| 1204 | 1011 | } |
| 1205 | - | |
| 1206 | 1012 | $form_id = $form ? $form->id : 0; |
| 1207 | 1013 | |
| 1208 | 1014 | return $form_id; |
| 1209 | 1015 | } |
| 1210 | 1016 | |
| 1211 | - /** | |
| 1212 | - * @param int|string $form_id | |
| 1213 | - * | |
| 1214 | - * @return false|int|object|string | |
| 1215 | - */ | |
| 1216 | 1017 | public static function maybe_get_current_form( $form_id = 0 ) { |
| 1217 | 1018 | global $frm_vars; |
| 1218 | 1019 | |
| 1219 | - 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 ) ) { | |
| 1220 | 1021 | return $frm_vars['current_form']; |
| 1221 | 1022 | } |
| 1222 | 1023 | |
| 1223 | 1024 | $form_id = FrmAppHelper::get_param( 'form', $form_id, 'get', 'absint' ); |
| 1224 | - | |
| 1225 | 1025 | if ( $form_id ) { |
| 1226 | 1026 | $form_id = self::set_current_form( $form_id ); |
| 1227 | 1027 | } |
| 1228 | 1028 | |
| @@ -1228,16 +1028,10 @@ | ||
| 1228 | 1028 | |
| 1229 | 1029 | return $form_id; |
| 1230 | 1030 | } |
| 1231 | 1031 | |
| 1232 | - /** | |
| 1233 | - * @param int $form_id | |
| 1234 | - * | |
| 1235 | - * @return false|object | |
| 1236 | - */ | |
| 1237 | 1032 | public static function get_current_form( $form_id = 0 ) { |
| 1238 | 1033 | $form = self::maybe_get_current_form( $form_id ); |
| 1239 | - | |
| 1240 | 1034 | if ( is_numeric( $form ) ) { |
| 1241 | 1035 | $form = self::set_current_form( $form ); |
| 1242 | 1036 | } |
| 1243 | 1037 | |
| @@ -1243,18 +1037,12 @@ | ||
| 1243 | 1037 | |
| 1244 | 1038 | return $form; |
| 1245 | 1039 | } |
| 1246 | 1040 | |
| 1247 | - /** | |
| 1248 | - * @param int $form_id | |
| 1249 | - * | |
| 1250 | - * @return false|object | |
| 1251 | - */ | |
| 1252 | 1041 | public static function set_current_form( $form_id ) { |
| 1253 | 1042 | global $frm_vars; |
| 1254 | 1043 | |
| 1255 | 1044 | $query = array(); |
| 1256 | - | |
| 1257 | 1045 | if ( $form_id ) { |
| 1258 | 1046 | $query['id'] = $form_id; |
| 1259 | 1047 | } |
| 1260 | 1048 | |
| @@ -1262,19 +1050,11 @@ | ||
| 1262 | 1050 | |
| 1263 | 1051 | return $frm_vars['current_form']; |
| 1264 | 1052 | } |
| 1265 | 1053 | |
| 1266 | - /** | |
| 1267 | - * @param object $form | |
| 1268 | - * @param int|string $this_load | |
| 1269 | - * @param bool $global_load | |
| 1270 | - * | |
| 1271 | - * @return bool | |
| 1272 | - */ | |
| 1273 | 1054 | public static function is_form_loaded( $form, $this_load, $global_load ) { |
| 1274 | 1055 | global $frm_vars; |
| 1275 | 1056 | $small_form = new stdClass(); |
| 1276 | - | |
| 1277 | 1057 | foreach ( array( 'id', 'form_key', 'name' ) as $var ) { |
| 1278 | 1058 | $small_form->{$var} = $form->{$var}; |
| 1279 | 1059 | unset( $var ); |
| 1280 | 1060 | } |
| @@ -1285,9 +1065,9 @@ | ||
| 1285 | 1065 | $global_load = true; |
| 1286 | 1066 | $frm_vars['load_css'] = true; |
| 1287 | 1067 | } |
| 1288 | 1068 | |
| 1289 | - return empty( $frm_vars['css_loaded'] ) && $global_load; | |
| 1069 | + return ( ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) && $global_load ); | |
| 1290 | 1070 | } |
| 1291 | 1071 | |
| 1292 | 1072 | /** |
| 1293 | 1073 | * @since 4.06.03 |
| @@ -1302,26 +1082,13 @@ | ||
| 1302 | 1082 | } else { |
| 1303 | 1083 | $visible = true; |
| 1304 | 1084 | } |
| 1305 | 1085 | |
| 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 | 1086 | return $visible; |
| 1315 | 1087 | } |
| 1316 | 1088 | |
| 1317 | - /** | |
| 1318 | - * @param object $form | |
| 1319 | - * | |
| 1320 | - * @return bool | |
| 1321 | - */ | |
| 1322 | 1089 | public static function show_submit( $form ) { |
| 1323 | - $show = ( ! $form->is_template && $form->status === 'published' && ! FrmAppHelper::is_admin() ); | |
| 1090 | + $show = ( ! $form->is_template && $form->status == 'published' && ! FrmAppHelper::is_admin() ); | |
| 1324 | 1091 | $show = apply_filters( 'frm_show_submit_button', $show, $form ); |
| 1325 | 1092 | |
| 1326 | 1093 | return $show; |
| 1327 | 1094 | } |
| @@ -1327,18 +1094,14 @@ | ||
| 1327 | 1094 | } |
| 1328 | 1095 | |
| 1329 | 1096 | /** |
| 1330 | 1097 | * @since 2.3 |
| 1331 | - * | |
| 1332 | - * @param array $atts Attributes including form, option, and default. | |
| 1333 | - * | |
| 1334 | - * @return mixed | |
| 1335 | 1098 | */ |
| 1336 | 1099 | public static function get_option( $atts ) { |
| 1337 | - $form = $atts['form']; | |
| 1338 | - $default = $atts['default'] ?? ''; | |
| 1100 | + $form = $atts['form']; | |
| 1101 | + $default = isset( $atts['default'] ) ? $atts['default'] : ''; | |
| 1339 | 1102 | |
| 1340 | - return $form->options[ $atts['option'] ] ?? $default; | |
| 1103 | + return isset( $form->options[ $atts['option'] ] ) ? $form->options[ $atts['option'] ] : $default; | |
| 1341 | 1104 | } |
| 1342 | 1105 | |
| 1343 | 1106 | /** |
| 1344 | 1107 | * Get the link to edit this form. |
| @@ -1343,12 +1106,9 @@ | ||
| 1343 | 1106 | /** |
| 1344 | 1107 | * Get the link to edit this form. |
| 1345 | 1108 | * |
| 1346 | 1109 | * @since 4.0 |
| 1347 | - * | |
| 1348 | 1110 | * @param int $form_id The id of the form. |
| 1349 | - * | |
| 1350 | - * @return string | |
| 1351 | 1111 | */ |
| 1352 | 1112 | public static function get_edit_link( $form_id ) { |
| 1353 | 1113 | return admin_url( 'admin.php?page=formidable&frm_action=edit&id=' . $form_id ); |
| 1354 | 1114 | } |
| @@ -1358,9 +1118,8 @@ | ||
| 1358 | 1118 | * |
| 1359 | 1119 | * @since 6.2 |
| 1360 | 1120 | * |
| 1361 | 1121 | * @param stdClass $form |
| 1362 | - * | |
| 1363 | 1122 | * @return bool |
| 1364 | 1123 | */ |
| 1365 | 1124 | public static function is_ajax_on( $form ) { |
| 1366 | 1125 | return ! empty( $form->options['ajax_submit'] ); |
| @@ -1366,58 +1125,12 @@ | ||
| 1366 | 1125 | return ! empty( $form->options['ajax_submit'] ); |
| 1367 | 1126 | } |
| 1368 | 1127 | |
| 1369 | 1128 | /** |
| 1370 | - * Get the latest form available. | |
| 1371 | - * | |
| 1372 | - * @since 6.8 | |
| 1373 | - * | |
| 1374 | - * @return object | |
| 1375 | - */ | |
| 1376 | - public static function get_latest_form() { | |
| 1377 | - | |
| 1378 | - $args = array( | |
| 1379 | - array( | |
| 1380 | - 'or' => 1, | |
| 1381 | - 'parent_form_id' => null, | |
| 1382 | - 'parent_form_id <' => 1, | |
| 1383 | - ), | |
| 1384 | - 'is_template' => 0, | |
| 1385 | - 'status !' => 'trash', | |
| 1386 | - ); | |
| 1387 | - | |
| 1388 | - return self::getAll( $args, 'created_at desc', 1 ); | |
| 1389 | - } | |
| 1390 | - | |
| 1391 | - /** | |
| 1392 | - * Count and return total forms. | |
| 1393 | - * | |
| 1394 | - * @since 6.8 | |
| 1395 | - * | |
| 1396 | - * @return int | |
| 1397 | - */ | |
| 1398 | - public static function get_forms_count() { | |
| 1399 | - | |
| 1400 | - $args = array( | |
| 1401 | - array( | |
| 1402 | - 'or' => 1, | |
| 1403 | - 'parent_form_id' => null, | |
| 1404 | - 'parent_form_id <' => 1, | |
| 1405 | - ), | |
| 1406 | - 'is_template' => 0, | |
| 1407 | - 'status !' => 'trash', | |
| 1408 | - ); | |
| 1409 | - | |
| 1410 | - return FrmDb::get_count( 'frm_forms', $args ); | |
| 1411 | - } | |
| 1412 | - | |
| 1413 | - /** | |
| 1414 | 1129 | * @deprecated 2.03.05 This is still referenced in a few add ons (API, locations). |
| 1415 | - * | |
| 1416 | 1130 | * @codeCoverageIgnore |
| 1417 | 1131 | * |
| 1418 | 1132 | * @param string $key |
| 1419 | - * | |
| 1420 | 1133 | * @return int form id |
| 1421 | 1134 | */ |
| 1422 | 1135 | public static function getIdByKey( $key ) { |
| 1423 | 1136 | _deprecated_function( __FUNCTION__, '2.03.05', 'FrmForm::get_id_by_key' ); |
| @@ -1425,13 +1138,11 @@ | ||
| 1425 | 1138 | } |
| 1426 | 1139 | |
| 1427 | 1140 | /** |
| 1428 | 1141 | * @deprecated 2.03.05 This is still referenced in the API add on as of v1.13. |
| 1429 | - * | |
| 1430 | 1142 | * @codeCoverageIgnore |
| 1431 | 1143 | * |
| 1432 | - * @param int|string $id | |
| 1433 | - * | |
| 1144 | + * @param string|int $id | |
| 1434 | 1145 | * @return string |
| 1435 | 1146 | */ |
| 1436 | 1147 | public static function getKeyById( $id ) { |
| 1437 | 1148 | _deprecated_function( __FUNCTION__, '2.03.05', 'FrmForm::get_key_by_id' ); |