PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 3.06.06
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v3.06.06
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmField.php +307 -521 6.5.33.06.06 View file →
@@ -9,236 +9,156 @@
9 9 public static $transient_size = 200;
10 10
11 11 public static function field_selection() {
12 12 $fields = array(
13 - 'text' => array(
14 - 'name' => __( 'Text', 'formidable' ),
15 - 'icon' => 'frm_icon_font frm_text2_icon',
13 + 'text' => array(
14 + 'name' => __( 'Text', 'formidable' ),
15 + 'icon' => 'frm_css_icon frm_text_icon',
16 16 ),
17 - 'textarea' => array(
18 - 'name' => __( 'Paragraph', 'formidable' ),
19 - 'icon' => 'frm_icon_font frm_paragraph_icon',
17 + 'textarea' => array(
18 + 'name' => __( 'Paragraph', 'formidable' ),
19 + 'icon' => 'frm_icon_font frm_paragraph_icon',
20 20 ),
21 - 'checkbox' => array(
22 - 'name' => __( 'Checkboxes', 'formidable' ),
23 - 'icon' => 'frm_icon_font frm_check_square_icon',
21 + 'checkbox' => array(
22 + 'name' => __( 'Checkboxes', 'formidable' ),
23 + 'icon' => 'frm_icon_font frm_check-square_icon',
24 24 ),
25 - 'radio' => array(
26 - 'name' => __( 'Radio Buttons', 'formidable' ),
27 - 'icon' => 'frm_icon_font frm_radio_checked_icon',
25 + 'radio' => array(
26 + 'name' => __( 'Radio Button', 'formidable' ),
27 + 'icon' => 'frm_icon_font frm_radio-checked_icon',
28 28 ),
29 - 'select' => array(
30 - 'name' => __( 'Dropdown', 'formidable' ),
31 - 'icon' => 'frm_icon_font frm_caret_square_down_icon',
29 + 'select' => array(
30 + 'name' => __( 'Dropdown', 'formidable' ),
31 + 'icon' => 'frm_icon_font frm_caret-square-down_icon',
32 32 ),
33 - 'email' => array(
34 - 'name' => __( 'Email', 'formidable' ),
35 - 'icon' => 'frm_icon_font frm_email_icon',
33 + 'email' => array(
34 + 'name' => __( 'Email', 'formidable' ),
35 + 'icon' => 'frm_icon_font frm_envelope_icon',
36 36 ),
37 - 'url' => array(
38 - 'name' => __( 'Website/URL', 'formidable' ),
39 - 'icon' => 'frm_icon_font frm_link_icon',
37 + 'url' => array(
38 + 'name' => __( 'Website/URL', 'formidable' ),
39 + 'icon' => 'dashicons dashicons-admin-links',
40 40 ),
41 - 'number' => array(
42 - 'name' => __( 'Number', 'formidable' ),
43 - 'icon' => 'frm_icon_font frm_hashtag_icon',
41 + 'number' => array(
42 + 'name' => __( 'Number', 'formidable' ),
43 + 'icon' => 'frm_css_icon frm_number_icon',
44 44 ),
45 - 'name' => array(
46 - 'name' => __( 'Name', 'formidable' ),
47 - 'icon' => 'frm_icon_font frm_user_name_icon',
45 + 'phone' => array(
46 + 'name' => __( 'Phone', 'formidable' ),
47 + 'icon' => 'frm_icon_font frm_phone_icon',
48 48 ),
49 - 'phone' => array(
50 - 'name' => __( 'Phone', 'formidable' ),
51 - 'icon' => 'frm_icon_font frm_phone_icon',
49 + 'html' => array(
50 + 'name' => __( 'HTML', 'formidable' ),
51 + 'icon' => 'frm_icon_font frm_embed2_icon',
52 52 ),
53 - 'html' => array(
54 - 'name' => __( 'HTML', 'formidable' ),
55 - 'icon' => 'frm_icon_font frm_code_icon',
53 + 'hidden' => array(
54 + 'name' => __( 'Hidden Field', 'formidable' ),
55 + 'icon' => 'frm_icon_font frm_eye-slash_icon',
56 56 ),
57 - 'hidden' => array(
58 - 'name' => __( 'Hidden', 'formidable' ),
59 - 'icon' => 'frm_icon_font frm_eye_slash_icon',
57 + 'user_id' => array(
58 + 'name' => __( 'User ID', 'formidable' ),
59 + 'icon' => 'frm_icon_font frm_user_icon',
60 60 ),
61 - 'user_id' => array(
62 - 'name' => __( 'User ID', 'formidable' ),
63 - 'icon' => 'frm_icon_font frm_user_icon',
61 + 'captcha' => array(
62 + 'name' => __( 'reCAPTCHA', 'formidable' ),
63 + 'icon' => 'frm_icon_font frm_shield-check_icon',
64 64 ),
65 - 'captcha' => array(
66 - 'name' => self::get_captcha_field_name(),
67 - 'icon' => 'frm_icon_font frm_shield_check_icon',
68 - ),
69 - 'credit_card' => array(
70 - 'name' => __( 'Payment', 'formidable' ),
71 - 'icon' => 'frm_icon_font frm_credit_card_icon',
72 - ),
73 65 );
74 66
75 - /**
76 - * @param array $fields
77 - */
78 67 return apply_filters( 'frm_available_fields', $fields );
79 68 }
80 69
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 70 public static function pro_field_selection() {
100 - $images_url = FrmAppHelper::plugin_url() . '/images/';
101 - $fields = array(
102 - 'file' => array(
103 - 'name' => __( 'File Upload', 'formidable' ),
104 - 'icon' => 'frm_icon_font frm_upload_icon',
105 - 'message' => 'Add file uploads to save time and cut down on back-and-forth. Upgrade to Pro to get Upload fields and more.',
71 + $fields = array(
72 + 'file' => array(
73 + 'name' => __( 'File Upload', 'formidable' ),
74 + 'icon' => 'frm_icon_font frm_upload2_icon',
106 75 ),
107 - 'rte' => array(
108 - 'name' => __( 'Rich Text', 'formidable' ),
109 - 'icon' => 'frm_icon_font frm_align_right_icon',
76 + 'rte' => array(
77 + 'name' => __( 'Rich Text', 'formidable' ),
78 + 'icon' => 'dashicons dashicons-editor-alignright',
110 79 ),
111 - 'date' => array(
112 - 'name' => __( 'Date', 'formidable' ),
113 - 'icon' => 'frm_icon_font frm_calendar_icon',
80 + 'date' => array(
81 + 'name' => __( 'Date', 'formidable' ),
82 + 'icon' => 'frm_icon_font frm_calendar_icon',
114 83 ),
115 - 'time' => array(
116 - 'name' => __( 'Time', 'formidable' ),
117 - 'icon' => 'frm_icon_font frm_clock_icon',
84 + 'time' => array(
85 + 'name' => __( 'Time', 'formidable' ),
86 + 'icon' => 'frm_icon_font frm_clock-o_icon',
118 87 ),
119 - 'scale' => array(
120 - 'name' => __( 'Scale', 'formidable' ),
121 - 'icon' => 'frm_icon_font frm_linear_scale_icon',
122 - 'message' => 'Add a set of radio buttons with whatever range you choose. <img src="' . esc_attr( $images_url ) . 'scale_field.png" alt="Scale Field" />',
88 + 'scale' => array(
89 + 'name' => __( 'Scale', 'formidable' ),
90 + 'icon' => 'frm_icon_font frm_linear_scale_icon',
123 91 ),
124 - 'star' => array(
125 - 'name' => __( 'Star Rating', 'formidable' ),
126 - 'icon' => 'frm_icon_font frm_star_icon',
92 + 'star' => array(
93 + 'name' => __( 'Star Rating', 'formidable' ),
94 + 'icon' => 'frm_icon_font frm_star-full_icon',
127 95 ),
128 - 'range' => array(
129 - 'name' => __( 'Slider', 'formidable' ),
130 - 'icon' => 'frm_icon_font frm_code_commit_icon',
96 + 'range' => array(
97 + 'name' => __( 'Slider', 'formidable' ),
98 + 'icon' => 'frm_icon_font frm_sliders_icon',
131 99 ),
132 - 'toggle' => array(
133 - 'name' => __( 'Toggle', 'formidable' ),
134 - 'icon' => 'frm_icon_font frm_toggle_on_icon',
100 + 'toggle' => array(
101 + 'name' => __( 'Toggle', 'formidable' ),
102 + 'icon' => 'frm_icon_font frm_toggle-on_icon',
135 103 ),
136 - 'data' => array(
137 - 'name' => __( 'Dynamic', 'formidable' ),
138 - 'icon' => 'frm_icon_font frm_sitemap_icon',
139 - 'message' => 'Create relationships between multiple forms. You can link a member to a team, a rating to a product, a comment to a submission, and much more.',
104 + 'data' => array(
105 + 'name' => __( 'Dynamic', 'formidable' ),
106 + 'icon' => 'frm_icon_font frm_sitemap_icon',
140 107 ),
141 - 'lookup' => array(
142 - 'name' => __( 'Lookup', 'formidable' ),
143 - 'icon' => 'frm_icon_font frm_search_icon',
144 - 'message' => 'Filter the options in the next field and automatically add values to other fields. Upgrade to Pro to get Lookup fields and more. <img src="' . esc_attr( $images_url ) . 'look-up_year-make-model.gif" alt="cascading lookup fields" />',
108 + 'lookup' => array(
109 + 'name' => __( 'Lookup', 'formidable' ),
110 + 'icon' => 'frm_icon_font frm_search_icon',
145 111 ),
146 112 'divider|repeat' => array(
147 - 'name' => __( 'Repeater', 'formidable' ),
148 - 'icon' => 'frm_icon_font frm_repeater_icon',
149 - 'message' => 'Allow your visitors to add new sets of fields while filling out forms. Increase conversions while saving building time and server resources. <img src="' . esc_attr( $images_url ) . 'repeatable-section_frontend.gif" alt="Dynamically Add Form Fields with repeatable sections" />',
113 + 'name' => __( 'Repeater', 'formidable' ),
114 + 'icon' => 'frm_icon_font frm_repeat_icon',
150 115 ),
151 - 'end_divider' => array(
152 - 'name' => __( 'Section Buttons', 'formidable' ),
116 + 'end_divider' => array(
117 + 'name' => __( 'End Section', 'formidable' ),
153 118 'switch_from' => 'divider',
154 119 ),
155 - 'divider' => array(
156 - 'name' => __( 'Section', 'formidable' ),
157 - 'icon' => 'frm_icon_font frm_header_icon',
120 + 'divider' => array(
121 + 'name' => __( 'Section', 'formidable' ),
122 + 'icon' => 'frm_css_icon frm_heading_icon',
158 123 ),
159 - 'break' => array(
160 - 'name' => __( 'Page Break', 'formidable' ),
161 - 'icon' => 'frm_icon_font frm_page_break_icon',
162 - 'message' => 'Get multi-paged forms with progress bars. Did you know you can upgrade to PRO to unlock multi-step forms with more awesome features?',
124 + 'break' => array(
125 + 'name' => __( 'Page Break', 'formidable' ),
126 + 'icon' => 'frm_icon_font frm_page-break_icon',
163 127 ),
164 - 'form' => array(
165 - 'name' => __( 'Embed Form', 'formidable' ),
166 - 'icon' => 'frm_icon_font frm_file_text_icon',
128 + 'form' => array(
129 + 'name' => __( 'Embed Form', 'formidable' ),
130 + 'icon' => 'dashicons dashicons-editor-table',
167 131 ),
168 - 'likert' => array(
169 - 'name' => __( 'Likert Scale', 'formidable' ),
170 - 'icon' => 'frm_icon_font frm_likert_scale frm_show_upgrade',
171 - 'addon' => 'surveys',
132 + 'password' => array(
133 + 'name' => __( 'Password', 'formidable' ),
134 + 'icon' => 'frm_icon_font frm_key_icon',
172 135 ),
173 - 'nps' => array(
174 - 'name' => __( 'NPS', 'formidable' ),
175 - 'icon' => 'frm_icon_font frm_nps frm_show_upgrade',
176 - 'addon' => 'surveys',
136 + 'tag' => array(
137 + 'name' => __( 'Tags', 'formidable' ),
138 + 'icon' => 'frm_icon_font frm_price-tags_icon',
177 139 ),
178 - 'password' => array(
179 - 'name' => __( 'Password', 'formidable' ),
180 - 'icon' => 'frm_icon_font frm_lock_open_icon',
140 + 'credit_card' => array(
141 + 'name' => __( 'Credit Card', 'formidable' ),
142 + 'icon' => 'frm_icon_font frm_credit-card-alt_icon frm_show_upgrade',
143 + 'addon' => 'stripe',
181 144 ),
182 - 'tag' => array(
183 - 'name' => __( 'Tags', 'formidable' ),
184 - 'icon' => 'frm_icon_font frm_price_tags_icon',
145 + 'address' => array(
146 + 'name' => __( 'Address', 'formidable' ),
147 + 'icon' => 'frm_icon_font frm_location_icon',
185 148 ),
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 - 'credit_card' => array(
189 - 'name' => '',
190 - 'icon' => '',
191 - ),
192 - 'address' => array(
193 - 'name' => __( 'Address', 'formidable' ),
194 - 'icon' => 'frm_icon_font frm_location_icon',
195 - ),
196 - 'summary' => array(
197 - 'name' => __( 'Summary', 'formidable' ),
198 - 'icon' => 'frm_icon_font frm_file_text_icon',
199 - 'message' => 'Allow visitors to review their responses before a form is submitted. Upgrade to Pro to get Summary fields and more.',
200 - ),
201 149 'signature' => array(
202 150 'name' => __( 'Signature', 'formidable' ),
203 - 'icon' => 'frm_icon_font frm_signature_icon frm_show_upgrade',
151 + 'icon' => 'frm_icon_font frm_pencil_icon frm_show_upgrade',
204 152 'addon' => 'signature',
205 153 ),
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.',
154 + 'quiz_score' => array(
155 + 'name' => __( 'Quiz Score', 'formidable' ),
156 + 'icon' => 'frm_icon_font frm_calculator_icon frm_show_upgrade',
157 + 'addon' => 'quizzes',
211 158 ),
212 - 'ssa-appointment' => array(
213 - 'name' => __( 'Appointment', 'formidable' ),
214 - 'icon' => 'frm_icon_font frm_calendar_icon frm_show_upgrade',
215 - 'require' => 'Simply Schedule Appointments',
216 - 'message' => 'Appointment fields are an integration with <a href="https://simplyscheduleappointments.com/meet/formidable/">Simply Schedule Appointments</a>. Get started now to schedule appointments directly from your forms.
217 - <img src="' . esc_attr( $images_url ) . 'appointments.png" alt="Scheduling" />',
218 - 'link' => 'https://simplyscheduleappointments.com/meet/formidable/',
219 - ),
220 - 'product' => array(
221 - 'name' => __( 'Product', 'formidable' ),
222 - 'icon' => 'frm_icon_font frm_product_icon',
223 - 'section' => 'pricing',
224 - ),
225 - 'quantity' => array(
226 - 'name' => __( 'Quantity', 'formidable' ),
227 - 'icon' => 'frm_icon_font frm_quantity_icon',
228 - 'section' => 'pricing',
229 - ),
230 - 'total' => array(
231 - 'name' => __( 'Total', 'formidable' ),
232 - 'icon' => 'frm_icon_font frm_total_icon',
233 - 'section' => 'pricing',
234 - ),
235 159 );
236 160
237 - if ( ! FrmAppHelper::show_new_feature( 'ai' ) ) {
238 - unset( $fields['ai'] );
239 - }
240 -
241 161 // Since the signature field may be in a different section, don't show it twice.
242 162 $lite_fields = self::field_selection();
243 163 if ( isset( $lite_fields['signature'] ) ) {
244 164 unset( $fields['signature'] );
@@ -246,152 +166,85 @@
246 166
247 167 return apply_filters( 'frm_pro_available_fields', $fields );
248 168 }
249 169
250 - /**
251 - * @since 4.0
252 - */
253 - public static function all_field_selection() {
254 - $pro_field_selection = self::pro_field_selection();
255 - return array_merge( $pro_field_selection, self::field_selection() );
256 - }
170 + public static function create( $values, $return = true ) {
171 + global $wpdb, $frm_duplicate_ids;
257 172
258 - /**
259 - * Create a field.
260 - *
261 - * @param array $values
262 - * @param bool $return
263 - * @return int|false
264 - */
265 - public static function create( $values, $return = true ) {
266 - global $wpdb, $frm_duplicate_ids;
267 -
268 - $new_values = array();
269 - $key = isset( $values['field_key'] ) ? $values['field_key'] : $values['name'];
173 + $new_values = array();
174 + $key = isset( $values['field_key'] ) ? $values['field_key'] : $values['name'];
270 175 $new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' );
271 176
272 - $values = FrmAppHelper::maybe_filter_array( $values, array( 'name', 'description' ) );
273 -
274 177 foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) {
275 178 $new_values[ $col ] = $values[ $col ];
276 - }
179 + }
277 180
278 - $new_values['options'] = self::maybe_filter_options( $values['options'] );
279 - $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null;
280 - $new_values['required'] = isset( $values['required'] ) ? (int) $values['required'] : 0;
281 - $new_values['form_id'] = isset( $values['form_id'] ) ? (int) $values['form_id'] : null;
282 - $new_values['field_options'] = $values['field_options'];
283 - $new_values['created_at'] = current_time( 'mysql', 1 );
181 + $new_values['options'] = $values['options'];
284 182
183 + $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null;
184 + $new_values['required'] = isset( $values['required'] ) ? (int) $values['required'] : 0;
185 + $new_values['form_id'] = isset( $values['form_id'] ) ? (int) $values['form_id'] : null;
186 + $new_values['field_options'] = $values['field_options'];
187 + $new_values['created_at'] = current_time( 'mysql', 1 );
188 +
285 189 if ( isset( $values['id'] ) ) {
286 190 $frm_duplicate_ids[ $values['field_key'] ] = $new_values['field_key'];
287 - $new_values = apply_filters( 'frm_duplicated_field', $new_values );
288 - }
191 + $new_values = apply_filters( 'frm_duplicated_field', $new_values );
192 + }
289 193
290 194 self::preserve_format_option_backslashes( $new_values );
291 195
292 196 foreach ( $new_values as $k => $v ) {
293 - if ( is_array( $v ) ) {
294 - if ( $k === 'default_value' ) {
295 - $new_values[ $k ] = FrmAppHelper::maybe_json_encode( $v );
296 - } else {
297 - $new_values[ $k ] = serialize( $v );
298 - }
197 + if ( is_array( $v ) ) {
198 + $new_values[ $k ] = serialize( $v );
299 199 }
300 - unset( $k, $v );
301 - }
200 + unset( $k, $v );
201 + }
302 202
203 + //if(isset($values['id']) and is_numeric($values['id']))
204 + // $new_values['id'] = $values['id'];
205 +
303 206 $query_results = $wpdb->insert( $wpdb->prefix . 'frm_fields', $new_values );
304 -
305 - if ( ! $query_results ) {
306 - return false;
207 + $new_id = 0;
208 + if ( $query_results ) {
209 + self::delete_form_transient( $new_values['form_id'] );
210 + $new_id = $wpdb->insert_id;
307 211 }
308 212
309 - self::delete_form_transient( $new_values['form_id'] );
310 - $new_id = $wpdb->insert_id;
311 -
312 213 if ( ! $return ) {
313 214 return false;
314 215 }
315 216
316 - if ( isset( $values['id'] ) ) {
317 - $frm_duplicate_ids[ $values['id'] ] = $new_id;
318 - }
319 -
320 - return $new_id;
321 - }
322 -
323 - /**
324 - * @since 5.0.08
325 - *
326 - * @param array $options
327 - * @return array
328 - */
329 - private static function maybe_filter_options( $options ) {
330 - return FrmAppHelper::maybe_filter_array( $options, array( 'custom_html' ) );
331 - }
332 -
333 - /**
334 - * Process the field duplication.
335 - *
336 - * @since 5.0.05
337 - */
338 - public static function duplicate_single_field( $field_id, $form_id ) {
339 - $copy_field = self::getOne( $field_id );
340 - if ( ! $copy_field ) {
217 + if ( $query_results ) {
218 + if ( isset( $values['id'] ) ) {
219 + $frm_duplicate_ids[ $values['id'] ] = $new_id;
220 + }
221 + return $new_id;
222 + } else {
341 223 return false;
342 224 }
225 + }
343 226
344 - do_action( 'frm_duplicate_field', $copy_field, $form_id );
345 - do_action( 'frm_duplicate_field_' . $copy_field->type, $copy_field, $form_id );
227 + public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) {
228 + global $frm_duplicate_ids;
346 229
347 - $values = array(
348 - 'id' => $copy_field->id,
349 - );
350 - FrmFieldsHelper::fill_field( $values, $copy_field, $copy_field->form_id );
351 - $values = apply_filters( 'frm_prepare_single_field_for_duplication', $values );
352 -
353 - $field_id = self::create( $values );
354 -
355 - /**
356 - * Fires after duplicating a field.
357 - *
358 - * @since 5.0.04
359 - *
360 - * @param array $args {
361 - * The arguments.
362 - *
363 - * @type int $field_id New field ID.
364 - * @type array $values Values before inserting.
365 - * @type object $copy_field Copy field data.
366 - * @type int $form_id Form ID.
367 - * }
368 - */
369 - do_action( 'frm_after_duplicate_field', compact( 'field_id', 'values', 'copy_field', 'form_id' ) );
370 -
371 - return compact( 'field_id', 'values' );
372 - }
373 -
374 - public static function duplicate( $old_form_id, $form_id, $copy_keys = false, $blog_id = false ) {
375 - global $frm_duplicate_ids;
376 -
377 - $where = array(
230 + $where = array(
378 231 array(
379 - 'or' => 1,
380 - 'fi.form_id' => $old_form_id,
232 + 'or' => 1,
233 + 'fi.form_id' => $old_form_id,
381 234 'fr.parent_form_id' => $old_form_id,
382 235 ),
383 236 );
384 237 $fields = self::getAll( $where, 'field_order', '', $blog_id );
385 238
386 - foreach ( (array) $fields as $field ) {
239 + foreach ( (array) $fields as $field ) {
387 240 $new_key = $copy_keys ? $field->field_key : '';
388 - if ( $copy_keys && substr( $field->field_key, - 1 ) == 2 ) {
241 + if ( $copy_keys && substr( $field->field_key, -1 ) == 2 ) {
389 242 $new_key = rtrim( $new_key, 2 );
390 243 }
391 244
392 - $values = array();
393 - FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
245 + $values = array();
246 + FrmFieldsHelper::fill_field( $values, $field, $form_id, $new_key );
394 247
395 248 // If this is a repeating section, create new form
396 249 if ( self::is_repeating_field( $field ) ) {
397 250 // create the repeatable form
@@ -417,21 +270,20 @@
417 270 }
418 271
419 272 $values['description'] = FrmFieldsHelper::switch_field_ids( $values['description'] );
420 273
421 - $values = apply_filters( 'frm_duplicated_field', $values );
422 - $new_id = self::create( $values );
423 - $frm_duplicate_ids[ $field->id ] = $new_id;
274 + $values = apply_filters( 'frm_duplicated_field', $values );
275 + $new_id = self::create( $values );
276 + $frm_duplicate_ids[ $field->id ] = $new_id;
424 277 $frm_duplicate_ids[ $field->field_key ] = $new_id;
425 278 unset( $field );
426 - }
427 - }
279 + }
280 + }
428 281
429 282 public static function update( $id, $values ) {
430 - global $wpdb;
283 + global $wpdb;
431 284
432 - $id = absint( $id );
433 - $values = FrmAppHelper::maybe_filter_array( $values, array( 'name', 'description' ) );
285 + $id = absint( $id );
434 286
435 287 if ( isset( $values['field_key'] ) ) {
436 288 $values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id );
437 289 }
@@ -436,10 +288,10 @@
436 288 $values['field_key'] = FrmAppHelper::get_unique_key( $values['field_key'], $wpdb->prefix . 'frm_fields', 'field_key', $id );
437 289 }
438 290
439 291 if ( isset( $values['required'] ) ) {
440 - $values['required'] = (int) $values['required'];
441 - }
292 + $values['required'] = (int) $values['required'];
293 + }
442 294
443 295 self::preserve_format_option_backslashes( $values );
444 296
445 297 if ( isset( $values['type'] ) ) {
@@ -444,9 +296,9 @@
444 296
445 297 if ( isset( $values['type'] ) ) {
446 298 $values = apply_filters( 'frm_clean_' . $values['type'] . '_field_options_before_update', $values );
447 299
448 - if ( $values['type'] === 'hidden' && isset( $values['field_options'] ) && isset( $values['field_options']['clear_on_focus'] ) ) {
300 + if ( $values['type'] == 'hidden' && isset( $values['field_options'] ) && isset( $values['field_options']['clear_on_focus'] ) ) {
449 301 // don't keep the old placeholder setting for hidden fields
450 302 $values['field_options']['clear_on_focus'] = 0;
451 303 }
452 304 }
@@ -451,51 +303,44 @@
451 303 }
452 304 }
453 305
454 306 // serialize array values
455 - foreach ( array( 'field_options', 'options' ) as $opt ) {
307 + foreach ( array( 'default_value', 'field_options', 'options' ) as $opt ) {
456 308 if ( isset( $values[ $opt ] ) && is_array( $values[ $opt ] ) ) {
457 - if ( 'field_options' === $opt ) {
458 - $values[ $opt ] = self::maybe_filter_options( $values[ $opt ] );
459 - }
460 309 $values[ $opt ] = serialize( $values[ $opt ] );
461 310 }
462 311 }
463 - if ( isset( $values['default_value'] ) && is_array( $values['default_value'] ) ) {
464 - $values['default_value'] = json_encode( $values['default_value'] );
465 - }
466 312
467 313 $query_results = $wpdb->update( $wpdb->prefix . 'frm_fields', $values, array( 'id' => $id ) );
468 314
469 - $form_id = 0;
315 + $form_id = 0;
470 316 if ( isset( $values['form_id'] ) ) {
471 - $form_id = absint( $values['form_id'] );
317 + $form_id = absint( $values['form_id'] );
472 318 } else {
473 319 $field = self::getOne( $id );
474 - if ( $field ) {
475 - $form_id = $field->form_id;
476 - }
320 + if ( $field ) {
321 + $form_id = $field->form_id;
322 + }
477 323 unset( $field );
478 - }
324 + }
479 325 unset( $values );
480 326
481 327 if ( $query_results ) {
482 - wp_cache_delete( $id, 'frm_field' );
483 - if ( $form_id ) {
484 - self::delete_form_transient( $form_id );
485 - }
486 - }
328 + wp_cache_delete( $id, 'frm_field' );
329 + if ( $form_id ) {
330 + self::delete_form_transient( $form_id );
331 + }
332 + }
487 333
488 - return $query_results;
489 - }
334 + return $query_results;
335 + }
490 336
491 337 /**
492 - * Keep backslashes in the phone format option
493 - *
494 - * @since 2.0.8
495 - *
496 - * @param $values array - pass by reference
497 - */
338 + * Keep backslashes in the phone format option
339 + *
340 + * @since 2.0.8
341 + * @param $values array - pass by reference
342 + */
498 343 private static function preserve_format_option_backslashes( &$values ) {
499 344 if ( isset( $values['field_options']['format'] ) ) {
500 345 $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
501 346 }
@@ -500,9 +345,9 @@
500 345 $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
501 346 }
502 347 }
503 348
504 - public static function destroy( $id ) {
349 + public static function destroy( $id ) {
505 350 global $wpdb;
506 351
507 352 do_action( 'frm_before_destroy_field', $id );
508 353
@@ -514,11 +359,10 @@
514 359
515 360 self::delete_form_transient( $field->form_id );
516 361
517 362 $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id=%d', $id ) );
518 -
519 363 return $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_fields WHERE id=%d', $id ) );
520 - }
364 + }
521 365
522 366 public static function delete_form_transient( $form_id ) {
523 367 $form_id = absint( $form_id );
524 368 delete_transient( 'frm_form_fields_' . $form_id . 'excludeinclude' );
@@ -531,12 +375,12 @@
531 375
532 376 FrmDb::cache_delete_group( 'frm_field' );
533 377
534 378 $form = FrmForm::getOne( $form_id );
535 - if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) {
536 - self::delete_form_transient( $form->parent_form_id );
537 - }
538 - }
379 + if ( $form && $form->parent_form_id && $form->parent_form_id != $form_id ) {
380 + self::delete_form_transient( $form->parent_form_id );
381 + }
382 + }
539 383
540 384 /**
541 385 * If $field is numeric, get the field object
542 386 */
@@ -554,31 +398,31 @@
554 398 if ( empty( $id ) ) {
555 399 return null;
556 400 }
557 401
558 - global $wpdb;
402 + global $wpdb;
559 403
560 404 $where = is_numeric( $id ) ? 'id=%d' : 'field_key=%s';
561 - $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
405 + $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'frm_fields WHERE ' . $where, $id ); // WPCS: unprepared SQL ok.
562 406
563 - $results = FrmDb::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
407 + $results = FrmDb::check_cache( $id, 'frm_field', $query, 'get_row', 0 );
564 408
565 409 if ( empty( $results ) ) {
566 410 self::filter_field( $filter, $results );
567 - return $results;
568 - }
411 + return $results;
412 + }
569 413
570 414 if ( is_numeric( $id ) ) {
571 415 FrmDb::set_cache( $results->field_key, $results, 'frm_field' );
572 - } elseif ( $results ) {
416 + } else if ( $results ) {
573 417 FrmDb::set_cache( $results->id, $results, 'frm_field' );
574 - }
418 + }
575 419
576 420 self::prepare_options( $results );
577 421 self::filter_field( $filter, $results );
578 422
579 - return wp_unslash( $results );
580 - }
423 + return stripslashes_deep( $results );
424 + }
581 425
582 426 /**
583 427 * @since 3.06.01
584 428 * @param bool $filter When true, run the frm_field filter.
@@ -598,28 +442,28 @@
598 442 *
599 443 * @param int|string The field id or key
600 444 * @param mixed $col The name of the column in the fields database table
601 445 */
602 - public static function get_type( $id, $col = 'type' ) {
603 - $field = FrmDb::check_cache( $id, 'frm_field' );
604 - if ( $field ) {
605 - $type = $field->{$col};
606 - } else {
446 + public static function get_type( $id, $col = 'type' ) {
447 + $field = FrmDb::check_cache( $id, 'frm_field' );
448 + if ( $field ) {
449 + $type = $field->{$col};
450 + } else {
607 451 $where = array(
608 452 'or' => 1,
609 453 'id' => $id,
610 454 'field_key' => $id,
611 455 );
612 - $type = FrmDb::get_var( 'frm_fields', $where, $col );
613 - }
456 + $type = FrmDb::get_var( 'frm_fields', $where, $col );
457 + }
614 458
615 - return $type;
616 - }
459 + return $type;
460 + }
617 461
618 462 public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) {
619 - if ( ! $form_id ) {
620 - return array();
621 - }
463 + if ( ! $form_id ) {
464 + return array();
465 + }
622 466
623 467 $results = self::get_fields_from_transients(
624 468 $form_id,
625 469 array(
@@ -627,99 +471,98 @@
627 471 'inc_repeat' => $inc_sub,
628 472 )
629 473 );
630 474 if ( ! empty( $results ) ) {
631 - $fields = array();
632 - $count = 0;
633 - foreach ( $results as $result ) {
634 - if ( $type != $result->type ) {
635 - continue;
636 - }
475 + $fields = array();
476 + $count = 0;
477 + foreach ( $results as $result ) {
478 + if ( $type != $result->type ) {
479 + continue;
480 + }
637 481
638 482 $fields[ $result->id ] = $result;
639 - $count ++;
640 - if ( $limit == 1 ) {
641 - $fields = $result;
642 - break;
643 - }
483 + $count++;
484 + if ( $limit == 1 ) {
485 + $fields = $result;
486 + break;
487 + }
644 488
645 489 if ( ! empty( $limit ) && $count >= $limit ) {
646 - break;
647 - }
490 + break;
491 + }
648 492
649 493 unset( $result );
650 494 }
495 + return stripslashes_deep( $fields );
496 + }
651 497
652 - return wp_unslash( $fields );
653 - }
498 + self::$use_cache = false;
654 499
655 - self::$use_cache = false;
656 -
657 500 $where = array(
658 501 'fi.form_id' => (int) $form_id,
659 502 'fi.type' => $type,
660 503 );
661 504 self::maybe_include_repeating_fields( $inc_sub, $where );
662 - $results = self::getAll( $where, 'field_order', $limit );
663 - self::$use_cache = true;
664 - self::include_sub_fields( $results, $inc_sub, $type, $form_id );
505 + $results = self::getAll( $where, 'field_order', $limit );
506 + self::$use_cache = true;
507 + self::include_sub_fields( $results, $inc_sub, $type );
665 508
666 - return $results;
667 - }
509 + return $results;
510 + }
668 511
669 512 public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) {
670 - if ( ! (int) $form_id ) {
671 - return array();
672 - }
513 + if ( ! (int) $form_id ) {
514 + return array();
515 + }
673 516
674 517 $results = self::get_fields_from_transients( $form_id, compact( 'inc_embed', 'inc_repeat' ) );
675 518 if ( ! empty( $results ) ) {
676 519 if ( empty( $limit ) ) {
677 520 return $results;
678 - }
521 + }
679 522
680 - $fields = array();
681 - $count = 0;
682 - foreach ( $results as $result ) {
683 - $count ++;
523 + $fields = array();
524 + $count = 0;
525 + foreach ( $results as $result ) {
526 + $count++;
684 527 $fields[ $result->id ] = $result;
685 528 if ( ! empty( $limit ) && $count >= $limit ) {
686 - break;
687 - }
688 - }
529 + break;
530 + }
531 + }
689 532
690 533 return $fields;
691 - }
534 + }
692 535
693 - self::$use_cache = false;
536 + self::$use_cache = false;
694 537
695 538 $where = array( 'fi.form_id' => absint( $form_id ) );
696 539 self::maybe_include_repeating_fields( $inc_repeat, $where );
697 540 $results = self::getAll( $where, 'field_order', $limit );
698 541
699 - self::$use_cache = true;
542 + self::$use_cache = true;
700 543
701 - self::include_sub_fields( $results, $inc_embed, 'all', $form_id );
544 + self::include_sub_fields( $results, $inc_embed, 'all' );
702 545
703 546 if ( empty( $limit ) ) {
704 547 self::set_field_transient( $results, $form_id, 0, compact( 'inc_embed', 'inc_repeat' ) );
705 - }
548 + }
706 549
707 550 return $results;
708 - }
551 + }
709 552
710 553 /**
711 - * If repeating fields should be included, adjust $where accordingly
712 - *
713 - * @param string $inc_repeat
714 - * @param array $where - pass by reference
715 - */
554 + * If repeating fields should be included, adjust $where accordingly
555 + *
556 + * @param string $inc_repeat
557 + * @param array $where - pass by reference
558 + */
716 559 private static function maybe_include_repeating_fields( $inc_repeat, &$where ) {
717 560 if ( $inc_repeat == 'include' ) {
718 561 $form_id = $where['fi.form_id'];
719 562 $where[] = array(
720 - 'or' => 1,
721 - 'fi.form_id' => $form_id,
563 + 'or' => 1,
564 + 'fi.form_id' => $form_id,
722 565 'fr.parent_form_id' => $form_id,
723 566 );
724 567 unset( $where['fi.form_id'] );
725 568 }
@@ -724,67 +567,61 @@
724 567 unset( $where['fi.form_id'] );
725 568 }
726 569 }
727 570
728 - public static function include_sub_fields( &$results, $inc_embed, $type = 'all', $form_id = '' ) {
729 - $no_sub_forms = empty( $results ) && $type === 'all';
730 - if ( 'include' != $inc_embed || $no_sub_forms ) {
731 - return;
732 - }
571 + public static function include_sub_fields( &$results, $inc_embed, $type = 'all' ) {
572 + if ( 'include' != $inc_embed || empty( $results ) ) {
573 + return;
574 + }
733 575
734 - $form_fields = $results;
735 - $should_get_subforms = ( $type !== 'all' && $type !== 'form' && ! empty( $form_id ) );
736 - if ( $should_get_subforms ) {
737 - $form_fields = self::get_all_types_in_form( $form_id, 'form' );
738 - }
739 -
576 + $form_fields = $results;
740 577 $index_offset = 1;
741 - foreach ( $form_fields as $k => $field ) {
578 + foreach ( $form_fields as $k => $field ) {
742 579 if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) {
743 - continue;
744 - }
580 + continue;
581 + }
745 582
746 - if ( $type == 'all' ) {
747 - $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
748 - } else {
749 - $sub_fields = self::get_all_types_in_form( $field->field_options['form_select'], $type );
750 - }
583 + if ( $type == 'all' ) {
584 + $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
585 + } else {
586 + $sub_fields = self::get_all_types_in_form( $field->form_id, $type );
587 + }
751 588
752 589 if ( ! empty( $sub_fields ) ) {
753 - $index = $k + $index_offset;
590 + $index = $k + $index_offset;
754 591 $index_offset += count( $sub_fields );
755 592 array_splice( $results, $index, 0, $sub_fields );
756 593 }
757 594 unset( $field, $sub_fields );
758 - }
759 - }
595 + }
596 + }
760 597
761 598 public static function getAll( $where = array(), $order_by = '', $limit = '', $blog_id = false ) {
762 - $cache_key = FrmAppHelper::maybe_json_encode( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id;
763 - if ( self::$use_cache ) {
764 - // make sure old cache doesn't get saved as a transient
599 + $cache_key = maybe_serialize( $where ) . $order_by . 'l' . $limit . 'b' . $blog_id;
600 + if ( self::$use_cache ) {
601 + // make sure old cache doesn't get saved as a transient
765 602 $results = wp_cache_get( $cache_key, 'frm_field' );
766 - if ( false !== $results ) {
767 - return wp_unslash( $results );
768 - }
769 - }
603 + if ( false !== $results ) {
604 + return stripslashes_deep( $results );
605 + }
606 + }
770 607
771 - global $wpdb;
608 + global $wpdb;
772 609
773 - if ( $blog_id && is_multisite() ) {
774 - global $wpmuBaseTablePrefix;
775 - if ( $wpmuBaseTablePrefix ) {
610 + if ( $blog_id && is_multisite() ) {
611 + global $wpmuBaseTablePrefix;
612 + if ( $wpmuBaseTablePrefix ) {
776 613 $prefix = $wpmuBaseTablePrefix . $blog_id . '_';
777 - } else {
778 - $prefix = $wpdb->get_blog_prefix( $blog_id );
779 - }
614 + } else {
615 + $prefix = $wpdb->get_blog_prefix( $blog_id );
616 + }
780 617
781 - $table_name = $prefix . 'frm_fields';
618 + $table_name = $prefix . 'frm_fields';
782 619 $form_table_name = $prefix . 'frm_forms';
783 620 } else {
784 - $table_name = $wpdb->prefix . 'frm_fields';
621 + $table_name = $wpdb->prefix . 'frm_fields';
785 622 $form_table_name = $wpdb->prefix . 'frm_forms';
786 - }
623 + }
787 624
788 625 if ( ! empty( $order_by ) && strpos( $order_by, 'ORDER BY' ) === false ) {
789 626 $order_by = ' ORDER BY ' . $order_by;
790 627 }
@@ -790,13 +627,13 @@
790 627 }
791 628
792 629 $limit = FrmDb::esc_limit( $limit );
793 630
794 - $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
795 - $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
631 + $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi LEFT OUTER JOIN {$form_table_name} fr ON fi.form_id=fr.id";
632 + $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
796 633
797 634 if ( is_array( $where ) ) {
798 - $args = array(
635 + $args = array(
799 636 'order_by' => $order_by,
800 637 'limit' => $limit,
801 638 );
802 639 $results = FrmDb::get_var( $table_name . ' fi LEFT OUTER JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', $args, '', $query_type );
@@ -804,17 +641,17 @@
804 641 // if the query is not an array, then it has already been prepared
805 642 $query .= FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
806 643
807 644 $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
808 - $results = $wpdb->$function_name( $query );
809 - }
810 - unset( $where );
645 + $results = $wpdb->$function_name( $query );
646 + }
647 + unset( $where );
811 648
812 649 self::format_field_results( $results );
813 650
814 651 FrmDb::set_cache( $cache_key, $results, 'frm_field' );
815 652
816 - return wp_unslash( $results );
653 + return stripslashes_deep( $results );
817 654 }
818 655
819 656 /**
820 657 * @since 2.0.8
@@ -824,16 +661,15 @@
824 661 foreach ( $results as $r_key => $result ) {
825 662 FrmDb::set_cache( $result->id, $result, 'frm_field' );
826 663 FrmDb::set_cache( $result->field_key, $result, 'frm_field' );
827 664
828 - self::prepare_options( $result );
829 - $results[ $r_key ]->field_options = $result->field_options;
830 - $results[ $r_key ]->options = $result->options;
831 - $results[ $r_key ]->default_value = $result->default_value;
665 + $results[ $r_key ]->field_options = maybe_unserialize( $result->field_options );
666 + $results[ $r_key ]->options = maybe_unserialize( $result->options );
667 + $results[ $r_key ]->default_value = maybe_unserialize( $result->default_value );
832 668
833 669 unset( $r_key, $result );
834 670 }
835 - } elseif ( $results ) {
671 + } else if ( $results ) {
836 672 FrmDb::set_cache( $results->id, $results, 'frm_field' );
837 673 FrmDb::set_cache( $results->field_key, $results, 'frm_field' );
838 674
839 675 self::prepare_options( $results );
@@ -845,17 +681,12 @@
845 681 *
846 682 * @since 2.0
847 683 */
848 684 private static function prepare_options( &$results ) {
849 - FrmAppHelper::unserialize_or_decode( $results->field_options );
850 - FrmAppHelper::unserialize_or_decode( $results->options );
685 + $results->field_options = maybe_unserialize( $results->field_options );
851 686
852 - // Allow a single box to be checked for the default value.
853 - $before = $results->default_value;
854 - FrmAppHelper::unserialize_or_decode( $results->default_value );
855 - if ( $before === $results->default_value && ! is_array( $before ) && strpos( $before, '["' ) === 0 ) {
856 - $results->default_value = FrmAppHelper::maybe_json_decode( $results->default_value );
857 - }
687 + $results->options = maybe_unserialize( $results->options );
688 + $results->default_value = maybe_unserialize( $results->default_value );
858 689 }
859 690
860 691 /**
861 692 * If a form has too many fields, thay won't all save into a single transient.
@@ -865,9 +696,8 @@
865 696 */
866 697 private static function get_fields_from_transients( $form_id, $args ) {
867 698 $fields = array();
868 699 self::get_next_transient( $fields, 'frm_form_fields_' . $form_id . $args['inc_embed'] . $args['inc_repeat'] );
869 -
870 700 return $fields;
871 701 }
872 702
873 703 /**
@@ -875,9 +705,9 @@
875 705 *
876 706 * @since 2.0.1
877 707 */
878 708 private static function get_next_transient( &$fields, $base_name, $next = 0 ) {
879 - $name = $next ? $base_name . $next : $base_name;
709 + $name = $next ? $base_name . $next : $base_name;
880 710 $next_fields = get_transient( $name );
881 711
882 712 if ( $next_fields ) {
883 713 $fields = array_merge( $fields, $next_fields );
@@ -883,9 +713,9 @@
883 713 $fields = array_merge( $fields, $next_fields );
884 714
885 715 if ( count( $next_fields ) >= self::$transient_size ) {
886 716 // if this transient is full, check for another
887 - $next ++;
717 + $next++;
888 718 self::get_next_transient( $fields, $base_name, $next );
889 719 }
890 720 }
891 721 }
@@ -895,14 +725,14 @@
895 725 *
896 726 * @since 2.0.1
897 727 */
898 728 private static function set_field_transient( &$fields, $form_id, $next = 0, $args = array() ) {
899 - $base_name = 'frm_form_fields_' . $form_id . $args['inc_embed'] . $args['inc_repeat'];
729 + $base_name = 'frm_form_fields_' . $form_id . $args['inc_embed'] . $args['inc_repeat'];
900 730 $field_chunks = array_chunk( $fields, self::$transient_size );
901 731
902 732 foreach ( $field_chunks as $field ) {
903 733 $name = $next ? $base_name . $next : $base_name;
904 - $set = set_transient( $name, $field, 60 * 60 * 6 );
734 + $set = set_transient( $name, $field, 60 * 60 * 6 );
905 735 if ( ! $set ) {
906 736 // the transient didn't save
907 737 if ( $name != $base_name ) {
908 738 // if the first saved an others fail, this will show an incmoplete form
@@ -907,13 +737,12 @@
907 737 if ( $name != $base_name ) {
908 738 // if the first saved an others fail, this will show an incmoplete form
909 739 self::delete_form_transient( $form_id );
910 740 }
911 -
912 741 return;
913 742 }
914 743
915 - $next ++;
744 + $next++;
916 745 }
917 746 }
918 747
919 748 public static function is_no_save_field( $type ) {
@@ -920,9 +749,9 @@
920 749 return in_array( $type, self::no_save_fields() );
921 750 }
922 751
923 752 public static function no_save_fields() {
924 - return array( 'divider', 'end_divider', 'captcha', 'break', 'html', 'form', 'summary' );
753 + return array( 'divider', 'end_divider', 'captcha', 'break', 'html', 'form' );
925 754 }
926 755
927 756 /**
928 757 * Check if this field can hold an array of values
@@ -929,9 +758,8 @@
929 758 *
930 759 * @since 2.0.9
931 760 *
932 761 * @param array|object $field
933 - *
934 762 * @return boolean
935 763 */
936 764 public static function is_field_with_multiple_values( $field ) {
937 765 if ( ! $field ) {
@@ -961,9 +789,9 @@
961 789 * @since 3.0
962 790 * @return string
963 791 */
964 792 public static function get_original_field_type( $field ) {
965 - $field_type = self::get_field_type( $field );
793 + $field_type = self::get_field_type( $field );
966 794 $original_type = self::get_option( $field, 'original_type' );
967 795
968 796 if ( ! empty( $original_type ) && $original_type != $field_type ) {
969 797 $field_type = $original_type; // check the original type for arrays
@@ -978,11 +806,12 @@
978 806 * @since 2.0.9
979 807 * @return boolean
980 808 */
981 809 public static function is_multiple_select( $field ) {
982 - $field_type = self::get_field_type( $field );
983 - $is_multiple = self::is_option_true( $field, 'multiple' ) && self::is_field_type( $field, 'select' ) && $field_type !== 'hidden';
810 + $field_type = self::get_field_type( $field );
811 + $data_type = self::get_option( $field, 'data_type' );
984 812
813 + $is_multiple = self::is_option_true( $field, 'multiple' ) && ( ( $field_type == 'select' || ( $field_type == 'data' && $data_type == 'select' ) ) );
985 814 return apply_filters( 'frm_is_multiple_select', $is_multiple, $field );
986 815 }
987 816
988 817 /**
@@ -992,9 +821,8 @@
992 821 * @since 2.0.9
993 822 */
994 823 public static function is_read_only( $field ) {
995 824 global $frm_vars;
996 -
997 825 return ( self::is_option_true( $field, 'read_only' ) && ( ! isset( $frm_vars['readonly'] ) || $frm_vars['readonly'] != 'disabled' ) );
998 826 }
999 827
1000 828 /**
@@ -1002,9 +830,8 @@
1002 830 */
1003 831 public static function is_required( $field ) {
1004 832 $required = ( $field['required'] != '0' );
1005 833 $required = apply_filters( 'frm_is_field_required', $required, $field );
1006 -
1007 834 return $required;
1008 835 }
1009 836
1010 837 /**
@@ -1057,23 +884,13 @@
1057 884 $option = self::get_option_in_array( $field, $option );
1058 885 } else {
1059 886 $option = self::get_option_in_object( $field, $option );
1060 887 }
1061 -
1062 888 return $option;
1063 889 }
1064 890
1065 891 public static function get_option_in_array( $field, $option ) {
1066 -
1067 - if ( isset( $field[ $option ] ) ) {
1068 - $this_option = $field[ $option ];
1069 - } elseif ( isset( $field['field_options'] ) && is_array( $field['field_options'] ) && isset( $field['field_options'][ $option ] ) ) {
1070 - $this_option = $field['field_options'][ $option ];
1071 - } else {
1072 - $this_option = '';
1073 - }
1074 -
1075 - return $this_option;
892 + return isset( $field[ $option ] ) ? $field[ $option ] : '';
1076 893 }
1077 894
1078 895 public static function get_option_in_object( $field, $option ) {
1079 896 return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : '';
@@ -1079,10 +896,10 @@
1079 896 return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : '';
1080 897 }
1081 898
1082 899 /**
1083 - * @since 2.0.09
1084 - */
900 + * @since 2.0.09
901 + */
1085 902 public static function is_repeating_field( $field ) {
1086 903 if ( is_array( $field ) ) {
1087 904 $is_repeating_field = ( 'divider' == $field['type'] );
1088 905 } else {
@@ -1087,27 +904,23 @@
1087 904 $is_repeating_field = ( 'divider' == $field['type'] );
1088 905 } else {
1089 906 $is_repeating_field = ( 'divider' == $field->type );
1090 907 }
1091 -
1092 908 return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) );
1093 909 }
1094 910
1095 911 /**
1096 912 * @param string $key
1097 - *
1098 913 * @return int field id
1099 914 */
1100 915 public static function get_id_by_key( $key ) {
1101 916 $id = FrmDb::get_var( 'frm_fields', array( 'field_key' => sanitize_title( $key ) ) );
1102 -
1103 917 return (int) $id;
1104 918 }
1105 919
1106 920 /**
1107 921 * @param string $id
1108 - *
1109 - * @return null|string
922 + * @return string
1110 923 */
1111 924 public static function get_key_by_id( $id ) {
1112 925 return FrmDb::get_var( 'frm_fields', array( 'id' => $id ), 'field_key' );
1113 926 }
@@ -1113,9 +926,8 @@
1113 926 }
1114 927
1115 928 public static function is_image( $field ) {
1116 929 $type = self::get_field_type( $field );
1117 -
1118 930 return ( $type == 'url' && self::get_option( $field, 'show_image' ) );
1119 931 }
1120 932
1121 933 /**
@@ -1123,9 +935,8 @@
1123 935 *
1124 936 * @since 3.0
1125 937 *
1126 938 * @param array|object $field
1127 - *
1128 939 * @return boolean true if field type is radio or Dynamic radio
1129 940 */
1130 941 public static function is_radio( $field ) {
1131 942 return self::is_field_type( $field, 'radio' );
@@ -1136,9 +947,8 @@
1136 947 *
1137 948 * @since 3.0
1138 949 *
1139 950 * @param array|object $field
1140 - *
1141 951 * @return boolean true if field type is checkbox or Dynamic checkbox
1142 952 */
1143 953 public static function is_checkbox( $field ) {
1144 954 return self::is_field_type( $field, 'checkbox' );
@@ -1150,41 +960,17 @@
1150 960 * @since 3.0
1151 961 *
1152 962 * @param array|object $field
1153 963 * @param string $is_type Options include radio, checkbox, text
1154 - *
1155 964 * @return boolean true if field type is checkbox or Dynamic checkbox
1156 965 */
1157 966 public static function is_field_type( $field, $is_type ) {
1158 967 $field_type = self::get_original_field_type( $field );
1159 - $data_type = self::get_option( $field, 'data_type' );
968 + $data_type = self::get_option( $field, 'data_type' );
1160 969
1161 - $is_field_type = (
970 + return (
1162 971 $is_type === $field_type ||
1163 972 ( 'data' === $field_type && $is_type === $data_type ) ||
1164 - ( 'lookup' === $field_type && $is_type === $data_type ) ||
1165 - ( 'product' === $field_type && $is_type === $data_type )
973 + ( 'lookup' === $field_type && $is_type === $data_type )
1166 974 );
1167 -
1168 - /**
1169 - * When a field type is checked, allow individual fields
1170 - * to set the type.
1171 - *
1172 - * @since 4.04
1173 - */
1174 - return apply_filters( 'frm_is_field_type', $is_field_type, compact( 'field', 'is_type' ) );
1175 - }
1176 -
1177 - /**
1178 - * Checks if the given field array is a combo field.
1179 - *
1180 - * @since 4.10.02
1181 - *
1182 - * @param array $field Field array.
1183 - * @return bool
1184 - */
1185 - public static function is_combo_field( $field ) {
1186 - $field_type_obj = FrmFieldFactory::get_field_factory( $field );
1187 -
1188 - return ! empty( $field_type_obj->is_combo_field );
1189 975 }
1190 976 }