| @@ -8,17 +8,8 @@ | ||
| 8 | 8 | public static $use_cache = true; |
| 9 | 9 | public static $transient_size = 200; |
| 10 | 10 | |
| 11 | 11 | public static function field_selection() { |
| 12 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 13 | - $active_captcha = $frm_settings->active_captcha; | |
| 14 | - if ( ! FrmFieldCaptcha::should_show_captcha() ) { | |
| 15 | - $captcha_name = 'Captcha'; | |
| 16 | - } elseif ( $active_captcha === 'recaptcha' ) { | |
| 17 | - $captcha_name = 'reCAPTCHA'; | |
| 18 | - } else { | |
| 19 | - $captcha_name = 'hCaptcha'; | |
| 20 | - } | |
| 21 | 12 | $fields = array( |
| 22 | 13 | 'text' => array( |
| 23 | 14 | 'name' => __( 'Text', 'formidable' ), |
| 24 | 15 | 'icon' => 'frm_icon_font frm_text2_icon', |
| @@ -71,16 +62,41 @@ | ||
| 71 | 62 | 'name' => __( 'User ID', 'formidable' ), |
| 72 | 63 | 'icon' => 'frm_icon_font frm_user_icon', |
| 73 | 64 | ), |
| 74 | 65 | 'captcha' => array( |
| 75 | - 'name' => $captcha_name, | |
| 66 | + 'name' => self::get_captcha_field_name(), | |
| 76 | 67 | 'icon' => 'frm_icon_font frm_shield_check_icon', |
| 77 | 68 | ), |
| 69 | + 'credit_card' => array( | |
| 70 | + 'name' => __( 'Payment', 'formidable' ), | |
| 71 | + 'icon' => 'frm_icon_font frm_credit_card_icon', | |
| 72 | + ), | |
| 78 | 73 | ); |
| 79 | 74 | |
| 75 | + /** | |
| 76 | + * @param array $fields | |
| 77 | + */ | |
| 80 | 78 | return apply_filters( 'frm_available_fields', $fields ); |
| 81 | 79 | } |
| 82 | 80 | |
| 81 | + /** | |
| 82 | + * Get the name of the Captcha field based on the global Captcha setting. | |
| 83 | + * | |
| 84 | + * @return string | |
| 85 | + */ | |
| 86 | + private static function get_captcha_field_name() { | |
| 87 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 88 | + $active_captcha = $frm_settings->active_captcha; | |
| 89 | + if ( ! FrmFieldCaptcha::should_show_captcha() ) { | |
| 90 | + $captcha_name = 'Captcha'; | |
| 91 | + } elseif ( $active_captcha === 'recaptcha' ) { | |
| 92 | + $captcha_name = 'reCAPTCHA'; | |
| 93 | + } else { | |
| 94 | + $captcha_name = 'hCaptcha'; | |
| 95 | + } | |
| 96 | + return $captcha_name; | |
| 97 | + } | |
| 98 | + | |
| 83 | 99 | public static function pro_field_selection() { |
| 84 | 100 | $images_url = FrmAppHelper::plugin_url() . '/images/'; |
| 85 | 101 | $fields = array( |
| 86 | 102 | 'file' => array( |
| @@ -166,12 +182,13 @@ | ||
| 166 | 182 | 'tag' => array( |
| 167 | 183 | 'name' => __( 'Tags', 'formidable' ), |
| 168 | 184 | 'icon' => 'frm_icon_font frm_price_tags_icon', |
| 169 | 185 | ), |
| 186 | + // This is no longer a Pro field, but without this here, Pro triggers "undefined index" notices. | |
| 187 | + // Right now it leaves a gap. Maybe we can skip anything without a name or something. | |
| 170 | 188 | 'credit_card' => array( |
| 171 | - 'name' => __( 'Credit Card', 'formidable' ), | |
| 172 | - 'icon' => 'frm_icon_font frm_credit_card_icon frm_show_upgrade', | |
| 173 | - 'addon' => 'stripe', | |
| 189 | + 'name' => '', | |
| 190 | + 'icon' => '', | |
| 174 | 191 | ), |
| 175 | 192 | 'address' => array( |
| 176 | 193 | 'name' => __( 'Address', 'formidable' ), |
| 177 | 194 | 'icon' => 'frm_icon_font frm_location_icon', |
| @@ -237,8 +254,15 @@ | ||
| 237 | 254 | $pro_field_selection = self::pro_field_selection(); |
| 238 | 255 | return array_merge( $pro_field_selection, self::field_selection() ); |
| 239 | 256 | } |
| 240 | 257 | |
| 258 | + /** | |
| 259 | + * Create a field. | |
| 260 | + * | |
| 261 | + * @param array $values | |
| 262 | + * @param bool $return | |
| 263 | + * @return int|false | |
| 264 | + */ | |
| 241 | 265 | public static function create( $values, $return = true ) { |
| 242 | 266 | global $wpdb, $frm_duplicate_ids; |
| 243 | 267 | |
| 244 | 268 | $new_values = array(); |
| @@ -276,27 +300,25 @@ | ||
| 276 | 300 | unset( $k, $v ); |
| 277 | 301 | } |
| 278 | 302 | |
| 279 | 303 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_fields', $new_values ); |
| 280 | - $new_id = 0; | |
| 281 | - if ( $query_results ) { | |
| 282 | - self::delete_form_transient( $new_values['form_id'] ); | |
| 283 | - $new_id = $wpdb->insert_id; | |
| 304 | + | |
| 305 | + if ( ! $query_results ) { | |
| 306 | + return false; | |
| 284 | 307 | } |
| 285 | 308 | |
| 309 | + self::delete_form_transient( $new_values['form_id'] ); | |
| 310 | + $new_id = $wpdb->insert_id; | |
| 311 | + | |
| 286 | 312 | if ( ! $return ) { |
| 287 | 313 | return false; |
| 288 | 314 | } |
| 289 | 315 | |
| 290 | - if ( $query_results ) { | |
| 291 | - if ( isset( $values['id'] ) ) { | |
| 292 | - $frm_duplicate_ids[ $values['id'] ] = $new_id; | |
| 293 | - } | |
| 316 | + if ( isset( $values['id'] ) ) { | |
| 317 | + $frm_duplicate_ids[ $values['id'] ] = $new_id; | |
| 318 | + } | |
| 294 | 319 | |
| 295 | - return $new_id; | |
| 296 | - } else { | |
| 297 | - return false; | |
| 298 | - } | |
| 320 | + return $new_id; | |
| 299 | 321 | } |
| 300 | 322 | |
| 301 | 323 | /** |
| 302 | 324 | * @since 5.0.08 |
| @@ -400,9 +422,9 @@ | ||
| 400 | 422 | $new_id = self::create( $values ); |
| 401 | 423 | $frm_duplicate_ids[ $field->id ] = $new_id; |
| 402 | 424 | $frm_duplicate_ids[ $field->field_key ] = $new_id; |
| 403 | 425 | unset( $field ); |
| 404 | - } | |
| 426 | + }//end foreach | |
| 405 | 427 | } |
| 406 | 428 | |
| 407 | 429 | public static function update( $id, $values ) { |
| 408 | 430 | global $wpdb; |
| @@ -420,8 +442,14 @@ | ||
| 420 | 442 | |
| 421 | 443 | self::preserve_format_option_backslashes( $values ); |
| 422 | 444 | |
| 423 | 445 | if ( isset( $values['type'] ) ) { |
| 446 | + if ( 'dropdown' === $values['type'] ) { | |
| 447 | + // To avoid conflicts with security plugins the value "dropdown" is sent for select fields. | |
| 448 | + // This is because "select" gets matched for SQL injection attempts. | |
| 449 | + $values['type'] = 'select'; | |
| 450 | + } | |
| 451 | + | |
| 424 | 452 | $values = apply_filters( 'frm_clean_' . $values['type'] . '_field_options_before_update', $values ); |
| 425 | 453 | |
| 426 | 454 | if ( $values['type'] === 'hidden' && isset( $values['field_options'] ) && isset( $values['field_options']['clear_on_focus'] ) ) { |
| 427 | 455 | // don't keep the old placeholder setting for hidden fields |
| @@ -470,9 +498,9 @@ | ||
| 470 | 498 | * Keep backslashes in the phone format option |
| 471 | 499 | * |
| 472 | 500 | * @since 2.0.8 |
| 473 | 501 | * |
| 474 | - * @param $values array - pass by reference | |
| 502 | + * @param array $values Pass by reference. | |
| 475 | 503 | */ |
| 476 | 504 | private static function preserve_format_option_backslashes( &$values ) { |
| 477 | 505 | if ( isset( $values['field_options']['format'] ) ) { |
| 478 | 506 | $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] ); |
| @@ -525,9 +553,9 @@ | ||
| 525 | 553 | } |
| 526 | 554 | |
| 527 | 555 | /** |
| 528 | 556 | * @param string|int $id The field id or key. |
| 529 | - * @param bool $filter When true, run the frm_field filter. | |
| 557 | + * @param bool $filter When true, run the frm_field filter. | |
| 530 | 558 | */ |
| 531 | 559 | public static function getOne( $id, $filter = false ) { |
| 532 | 560 | if ( empty( $id ) ) { |
| 533 | 561 | return null; |
| @@ -573,10 +601,10 @@ | ||
| 573 | 601 | |
| 574 | 602 | /** |
| 575 | 603 | * Get the field type by key or id |
| 576 | 604 | * |
| 577 | - * @param int|string The field id or key | |
| 578 | - * @param mixed $col The name of the column in the fields database table | |
| 605 | + * @param int|string $id The field id or key. | |
| 606 | + * @param mixed $col The name of the column in the fields database table. | |
| 579 | 607 | */ |
| 580 | 608 | public static function get_type( $id, $col = 'type' ) { |
| 581 | 609 | $field = FrmDb::check_cache( $id, 'frm_field' ); |
| 582 | 610 | if ( $field ) { |
| @@ -627,9 +655,9 @@ | ||
| 627 | 655 | unset( $result ); |
| 628 | 656 | } |
| 629 | 657 | |
| 630 | 658 | return wp_unslash( $fields ); |
| 631 | - } | |
| 659 | + }//end if | |
| 632 | 660 | |
| 633 | 661 | self::$use_cache = false; |
| 634 | 662 | |
| 635 | 663 | $where = array( |
| @@ -688,9 +716,9 @@ | ||
| 688 | 716 | /** |
| 689 | 717 | * If repeating fields should be included, adjust $where accordingly |
| 690 | 718 | * |
| 691 | 719 | * @param string $inc_repeat |
| 692 | - * @param array $where - pass by reference | |
| 720 | + * @param array $where Pass by reference. | |
| 693 | 721 | */ |
| 694 | 722 | private static function maybe_include_repeating_fields( $inc_repeat, &$where ) { |
| 695 | 723 | if ( $inc_repeat == 'include' ) { |
| 696 | 724 | $form_id = $where['fi.form_id']; |
| @@ -943,9 +971,10 @@ | ||
| 943 | 971 | $field_type = self::get_field_type( $field ); |
| 944 | 972 | $original_type = self::get_option( $field, 'original_type' ); |
| 945 | 973 | |
| 946 | 974 | if ( ! empty( $original_type ) && $original_type != $field_type ) { |
| 947 | - $field_type = $original_type; // check the original type for arrays | |
| 975 | + // Check the original type for arrays. | |
| 976 | + $field_type = $original_type; | |
| 948 | 977 | } |
| 949 | 978 | |
| 950 | 979 | return $field_type; |
| 951 | 980 | } |
| @@ -1127,9 +1156,9 @@ | ||
| 1127 | 1156 | * |
| 1128 | 1157 | * @since 3.0 |
| 1129 | 1158 | * |
| 1130 | 1159 | * @param array|object $field |
| 1131 | - * @param string $is_type Options include radio, checkbox, text | |
| 1160 | + * @param string $is_type Options include radio, checkbox, text. | |
| 1132 | 1161 | * |
| 1133 | 1162 | * @return boolean true if field type is checkbox or Dynamic checkbox |
| 1134 | 1163 | */ |
| 1135 | 1164 | public static function is_field_type( $field, $is_type ) { |