| @@ -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 |
| @@ -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 |