| @@ -8,8 +8,17 @@ | ||
| 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 | + } | |
| 12 | 21 | $fields = array( |
| 13 | 22 | 'text' => array( |
| 14 | 23 | 'name' => __( 'Text', 'formidable' ), |
| 15 | 24 | 'icon' => 'frm_icon_font frm_text2_icon', |
| @@ -62,41 +71,16 @@ | ||
| 62 | 71 | 'name' => __( 'User ID', 'formidable' ), |
| 63 | 72 | 'icon' => 'frm_icon_font frm_user_icon', |
| 64 | 73 | ), |
| 65 | 74 | 'captcha' => array( |
| 66 | - 'name' => self::get_captcha_field_name(), | |
| 75 | + 'name' => $captcha_name, | |
| 67 | 76 | 'icon' => 'frm_icon_font frm_shield_check_icon', |
| 68 | 77 | ), |
| 69 | - 'credit_card' => array( | |
| 70 | - 'name' => __( 'Payment', 'formidable' ), | |
| 71 | - 'icon' => 'frm_icon_font frm_credit_card_icon', | |
| 72 | - ), | |
| 73 | 78 | ); |
| 74 | 79 | |
| 75 | - /** | |
| 76 | - * @param array $fields | |
| 77 | - */ | |
| 78 | 80 | return apply_filters( 'frm_available_fields', $fields ); |
| 79 | 81 | } |
| 80 | 82 | |
| 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 | - | |
| 99 | 83 | public static function pro_field_selection() { |
| 100 | 84 | $images_url = FrmAppHelper::plugin_url() . '/images/'; |
| 101 | 85 | $fields = array( |
| 102 | 86 | 'file' => array( |
| @@ -182,13 +166,12 @@ | ||
| 182 | 166 | 'tag' => array( |
| 183 | 167 | 'name' => __( 'Tags', 'formidable' ), |
| 184 | 168 | 'icon' => 'frm_icon_font frm_price_tags_icon', |
| 185 | 169 | ), |
| 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. | |
| 188 | 170 | 'credit_card' => array( |
| 189 | - 'name' => '', | |
| 190 | - 'icon' => '', | |
| 171 | + 'name' => __( 'Credit Card', 'formidable' ), | |
| 172 | + 'icon' => 'frm_icon_font frm_credit_card_icon frm_show_upgrade', | |
| 173 | + 'addon' => 'stripe', | |
| 191 | 174 | ), |
| 192 | 175 | 'address' => array( |
| 193 | 176 | 'name' => __( 'Address', 'formidable' ), |
| 194 | 177 | 'icon' => 'frm_icon_font frm_location_icon', |
| @@ -202,14 +185,8 @@ | ||
| 202 | 185 | 'name' => __( 'Signature', 'formidable' ), |
| 203 | 186 | 'icon' => 'frm_icon_font frm_signature_icon frm_show_upgrade', |
| 204 | 187 | 'addon' => 'signature', |
| 205 | 188 | ), |
| 206 | - 'ai' => array( | |
| 207 | - 'name' => __( 'AI', 'formidable' ), | |
| 208 | - 'icon' => 'frm_icon_font frm_eye_icon frm_show_upgrade', | |
| 209 | - 'addon' => 'ai', | |
| 210 | - 'message' => 'Streamline workflows and reclaim valuable time with the power of AI. You can effortlessly respond to your visitors in real-time with ChatGPT as your automated assistant. Upgrade to Pro and unlock AI-powered fields.', | |
| 211 | - ), | |
| 212 | 189 | 'ssa-appointment' => array( |
| 213 | 190 | 'name' => __( 'Appointment', 'formidable' ), |
| 214 | 191 | 'icon' => 'frm_icon_font frm_calendar_icon frm_show_upgrade', |
| 215 | 192 | 'require' => 'Simply Schedule Appointments', |
| @@ -233,12 +210,8 @@ | ||
| 233 | 210 | 'section' => 'pricing', |
| 234 | 211 | ), |
| 235 | 212 | ); |
| 236 | 213 | |
| 237 | - if ( ! FrmAppHelper::show_new_feature( 'ai' ) ) { | |
| 238 | - unset( $fields['ai'] ); | |
| 239 | - } | |
| 240 | - | |
| 241 | 214 | // Since the signature field may be in a different section, don't show it twice. |
| 242 | 215 | $lite_fields = self::field_selection(); |
| 243 | 216 | if ( isset( $lite_fields['signature'] ) ) { |
| 244 | 217 | unset( $fields['signature'] ); |
| @@ -254,15 +227,8 @@ | ||
| 254 | 227 | $pro_field_selection = self::pro_field_selection(); |
| 255 | 228 | return array_merge( $pro_field_selection, self::field_selection() ); |
| 256 | 229 | } |
| 257 | 230 | |
| 258 | - /** | |
| 259 | - * Create a field. | |
| 260 | - * | |
| 261 | - * @param array $values | |
| 262 | - * @param bool $return | |
| 263 | - * @return int|false | |
| 264 | - */ | |
| 265 | 231 | public static function create( $values, $return = true ) { |
| 266 | 232 | global $wpdb, $frm_duplicate_ids; |
| 267 | 233 | |
| 268 | 234 | $new_values = array(); |
| @@ -300,25 +266,27 @@ | ||
| 300 | 266 | unset( $k, $v ); |
| 301 | 267 | } |
| 302 | 268 | |
| 303 | 269 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_fields', $new_values ); |
| 270 | + $new_id = 0; | |
| 271 | + if ( $query_results ) { | |
| 272 | + self::delete_form_transient( $new_values['form_id'] ); | |
| 273 | + $new_id = $wpdb->insert_id; | |
| 274 | + } | |
| 304 | 275 | |
| 305 | - if ( ! $query_results ) { | |
| 276 | + if ( ! $return ) { | |
| 306 | 277 | return false; |
| 307 | 278 | } |
| 308 | 279 | |
| 309 | - self::delete_form_transient( $new_values['form_id'] ); | |
| 310 | - $new_id = $wpdb->insert_id; | |
| 280 | + if ( $query_results ) { | |
| 281 | + if ( isset( $values['id'] ) ) { | |
| 282 | + $frm_duplicate_ids[ $values['id'] ] = $new_id; | |
| 283 | + } | |
| 311 | 284 | |
| 312 | - if ( ! $return ) { | |
| 285 | + return $new_id; | |
| 286 | + } else { | |
| 313 | 287 | return false; |
| 314 | 288 | } |
| 315 | - | |
| 316 | - if ( isset( $values['id'] ) ) { | |
| 317 | - $frm_duplicate_ids[ $values['id'] ] = $new_id; | |
| 318 | - } | |
| 319 | - | |
| 320 | - return $new_id; | |
| 321 | 289 | } |
| 322 | 290 | |
| 323 | 291 | /** |
| 324 | 292 | * @since 5.0.08 |
| @@ -1105,9 +1073,9 @@ | ||
| 1105 | 1073 | |
| 1106 | 1074 | /** |
| 1107 | 1075 | * @param string $id |
| 1108 | 1076 | * |
| 1109 | - * @return null|string | |
| 1077 | + * @return string | |
| 1110 | 1078 | */ |
| 1111 | 1079 | public static function get_key_by_id( $id ) { |
| 1112 | 1080 | return FrmDb::get_var( 'frm_fields', array( 'id' => $id ), 'field_key' ); |
| 1113 | 1081 | } |