PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.11
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.11
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 +357 -134 6.46.11 View file →
@@ -4,193 +4,206 @@
4 4 }
5 5
6 6 class FrmField {
7 7
8 - public static $use_cache = true;
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 - 'text' => array(
13 + 'text' => array(
23 14 'name' => __( 'Text', 'formidable' ),
24 15 'icon' => 'frm_icon_font frm_text2_icon',
25 16 ),
26 - 'textarea' => array(
17 + 'textarea' => array(
27 18 'name' => __( 'Paragraph', 'formidable' ),
28 19 'icon' => 'frm_icon_font frm_paragraph_icon',
29 20 ),
30 - 'checkbox' => array(
21 + 'checkbox' => array(
31 22 'name' => __( 'Checkboxes', 'formidable' ),
32 23 'icon' => 'frm_icon_font frm_check_square_icon',
33 24 ),
34 - 'radio' => array(
25 + 'radio' => array(
35 26 'name' => __( 'Radio Buttons', 'formidable' ),
36 27 'icon' => 'frm_icon_font frm_radio_checked_icon',
37 28 ),
38 - 'select' => array(
29 + 'select' => array(
39 30 'name' => __( 'Dropdown', 'formidable' ),
40 31 'icon' => 'frm_icon_font frm_caret_square_down_icon',
41 32 ),
42 - 'email' => array(
33 + 'email' => array(
43 34 'name' => __( 'Email', 'formidable' ),
44 35 'icon' => 'frm_icon_font frm_email_icon',
45 36 ),
46 - 'url' => array(
37 + 'url' => array(
47 38 'name' => __( 'Website/URL', 'formidable' ),
48 39 'icon' => 'frm_icon_font frm_link_icon',
49 40 ),
50 - 'number' => array(
41 + 'number' => array(
51 42 'name' => __( 'Number', 'formidable' ),
52 43 'icon' => 'frm_icon_font frm_hashtag_icon',
53 44 ),
54 - 'name' => array(
45 + 'name' => array(
55 46 'name' => __( 'Name', 'formidable' ),
56 47 'icon' => 'frm_icon_font frm_user_name_icon',
57 48 ),
58 - 'phone' => array(
49 + 'phone' => array(
59 50 'name' => __( 'Phone', 'formidable' ),
60 51 'icon' => 'frm_icon_font frm_phone_icon',
61 52 ),
62 - 'html' => array(
53 + 'html' => array(
63 54 'name' => __( 'HTML', 'formidable' ),
64 55 'icon' => 'frm_icon_font frm_code_icon',
65 56 ),
66 - 'hidden' => array(
57 + 'hidden' => array(
67 58 'name' => __( 'Hidden', 'formidable' ),
68 59 'icon' => 'frm_icon_font frm_eye_slash_icon',
69 60 ),
70 - 'user_id' => array(
61 + 'user_id' => array(
71 62 'name' => __( 'User ID', 'formidable' ),
72 63 'icon' => 'frm_icon_font frm_user_icon',
73 64 ),
74 - 'captcha' => array(
75 - 'name' => $captcha_name,
65 + 'captcha' => array(
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 + ),
73 + FrmSubmitHelper::FIELD_TYPE => array(
74 + 'name' => __( 'Submit', 'formidable' ),
75 + 'hide' => true,
76 + ),
78 77 );
79 78
79 + /**
80 + * @param array $fields
81 + */
80 82 return apply_filters( 'frm_available_fields', $fields );
81 83 }
82 84
85 + /**
86 + * Get the name of the Captcha field based on the global Captcha setting.
87 + *
88 + * @return string
89 + */
90 + private static function get_captcha_field_name() {
91 + return 'Captcha';
92 + }
93 +
83 94 public static function pro_field_selection() {
84 95 $images_url = FrmAppHelper::plugin_url() . '/images/';
85 96 $fields = array(
86 - 'file' => array(
87 - 'name' => __( 'File Upload', 'formidable' ),
88 - 'icon' => 'frm_icon_font frm_upload_icon',
97 + 'file' => array(
98 + 'name' => __( 'File Upload', 'formidable' ),
99 + 'icon' => 'frm_icon_font frm_upload_icon',
89 100 'message' => 'Add file uploads to save time and cut down on back-and-forth. Upgrade to Pro to get Upload fields and more.',
90 101 ),
91 - 'rte' => array(
102 + 'ranking' => array(),
103 + 'rte' => array(
92 104 'name' => __( 'Rich Text', 'formidable' ),
93 105 'icon' => 'frm_icon_font frm_align_right_icon',
94 106 ),
95 - 'date' => array(
107 + 'date' => array(
96 108 'name' => __( 'Date', 'formidable' ),
97 109 'icon' => 'frm_icon_font frm_calendar_icon',
98 110 ),
99 - 'time' => array(
111 + 'time' => array(
100 112 'name' => __( 'Time', 'formidable' ),
101 113 'icon' => 'frm_icon_font frm_clock_icon',
102 114 ),
103 - 'scale' => array(
104 - 'name' => __( 'Scale', 'formidable' ),
105 - 'icon' => 'frm_icon_font frm_linear_scale_icon',
106 - 'message' => 'Add a set of radio buttons with whatever range you choose. <img src="' . esc_attr( $images_url ) . 'scale_field.png" alt="Scale Field" />',
115 + 'scale' => array(
116 + 'name' => __( 'Scale', 'formidable' ),
117 + 'icon' => 'frm_icon_font frm_linear_scale_icon',
118 + 'message' => 'Add a set of radio buttons with whatever range you choose. <img src="' . esc_url( $images_url ) . 'scale_field.png" alt="Scale Field" />',
107 119 ),
108 - 'star' => array(
120 + 'star' => array(
109 121 'name' => __( 'Star Rating', 'formidable' ),
110 122 'icon' => 'frm_icon_font frm_star_icon',
111 123 ),
112 - 'range' => array(
124 + 'range' => array(
113 125 'name' => __( 'Slider', 'formidable' ),
114 126 'icon' => 'frm_icon_font frm_code_commit_icon',
115 127 ),
116 - 'toggle' => array(
128 + 'toggle' => array(
117 129 'name' => __( 'Toggle', 'formidable' ),
118 130 'icon' => 'frm_icon_font frm_toggle_on_icon',
119 131 ),
120 - 'data' => array(
121 - 'name' => __( 'Dynamic', 'formidable' ),
122 - 'icon' => 'frm_icon_font frm_sitemap_icon',
132 + 'data' => array(
133 + 'name' => __( 'Dynamic', 'formidable' ),
134 + 'icon' => 'frm_icon_font frm_sitemap_icon',
123 135 '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.',
124 136 ),
125 - 'lookup' => array(
126 - 'name' => __( 'Lookup', 'formidable' ),
127 - 'icon' => 'frm_icon_font frm_search_icon',
128 - '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" />',
137 + 'lookup' => array(
138 + 'name' => __( 'Lookup', 'formidable' ),
139 + 'icon' => 'frm_icon_font frm_search_icon',
140 + '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_url( $images_url ) . 'look-up_year-make-model.gif" alt="cascading lookup fields" />',
129 141 ),
130 - 'divider|repeat' => array(
131 - 'name' => __( 'Repeater', 'formidable' ),
132 - 'icon' => 'frm_icon_font frm_repeater_icon',
133 - '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" />',
142 + 'divider|repeat' => array(
143 + 'name' => __( 'Repeater', 'formidable' ),
144 + 'icon' => 'frm_icon_font frm_repeater_icon',
145 + '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_url( $images_url ) . 'repeatable-section_frontend.gif" alt="Dynamically Add Form Fields with repeatable sections" />',
134 146 ),
135 - 'end_divider' => array(
147 + 'end_divider' => array(
136 148 'name' => __( 'Section Buttons', 'formidable' ),
137 149 'switch_from' => 'divider',
138 150 ),
139 - 'divider' => array(
151 + 'divider' => array(
140 152 'name' => __( 'Section', 'formidable' ),
141 153 'icon' => 'frm_icon_font frm_header_icon',
142 154 ),
143 - 'break' => array(
144 - 'name' => __( 'Page Break', 'formidable' ),
145 - 'icon' => 'frm_icon_font frm_page_break_icon',
155 + 'break' => array(
156 + 'name' => __( 'Page Break', 'formidable' ),
157 + 'icon' => 'frm_icon_font frm_page_break_icon',
146 158 '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?',
147 159 ),
148 - 'form' => array(
160 + 'form' => array(
149 161 'name' => __( 'Embed Form', 'formidable' ),
150 162 'icon' => 'frm_icon_font frm_file_text_icon',
151 163 ),
152 - 'likert' => array(
164 + 'likert' => array(
153 165 'name' => __( 'Likert Scale', 'formidable' ),
154 166 'icon' => 'frm_icon_font frm_likert_scale frm_show_upgrade',
155 167 'addon' => 'surveys',
156 168 ),
157 - 'nps' => array(
169 + 'nps' => array(
158 170 'name' => __( 'NPS', 'formidable' ),
159 171 'icon' => 'frm_icon_font frm_nps frm_show_upgrade',
160 172 'addon' => 'surveys',
161 173 ),
162 - 'password' => array(
174 + 'password' => array(
163 175 'name' => __( 'Password', 'formidable' ),
164 176 'icon' => 'frm_icon_font frm_lock_open_icon',
165 177 ),
166 - 'tag' => array(
178 + 'tag' => array(
167 179 'name' => __( 'Tags', 'formidable' ),
168 180 'icon' => 'frm_icon_font frm_price_tags_icon',
169 181 ),
170 - 'credit_card' => array(
171 - 'name' => __( 'Credit Card', 'formidable' ),
172 - 'icon' => 'frm_icon_font frm_credit_card_icon frm_show_upgrade',
173 - 'addon' => 'stripe',
182 + // This is no longer a Pro field, but without this here, Pro triggers "undefined index" notices.
183 + // Right now it leaves a gap. Maybe we can skip anything without a name or something.
184 + 'credit_card' => array(
185 + 'name' => '',
186 + 'icon' => '',
174 187 ),
175 - 'address' => array(
188 + 'address' => array(
176 189 'name' => __( 'Address', 'formidable' ),
177 190 'icon' => 'frm_icon_font frm_location_icon',
178 191 ),
179 - 'summary' => array(
180 - 'name' => __( 'Summary', 'formidable' ),
181 - 'icon' => 'frm_icon_font frm_file_text_icon',
192 + 'summary' => array(
193 + 'name' => __( 'Summary', 'formidable' ),
194 + 'icon' => 'frm_icon_font frm_file_text_icon',
182 195 'message' => 'Allow visitors to review their responses before a form is submitted. Upgrade to Pro to get Summary fields and more.',
183 196 ),
184 - 'signature' => array(
197 + 'signature' => array(
185 198 'name' => __( 'Signature', 'formidable' ),
186 199 'icon' => 'frm_icon_font frm_signature_icon frm_show_upgrade',
187 200 'addon' => 'signature',
188 201 ),
189 - 'ai' => array(
190 - 'name' => __( 'AI', 'formidable' ),
191 - 'icon' => 'frm_icon_font frm_eye_icon frm_show_upgrade',
192 - 'addon' => 'ai',
202 + 'ai' => array(
203 + 'name' => __( 'AI', 'formidable' ),
204 + 'icon' => 'frm_icon_font frm_eye_icon frm_show_upgrade',
205 + 'addon' => 'ai',
193 206 '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.',
194 207 ),
195 208 'ssa-appointment' => array(
196 209 'name' => __( 'Appointment', 'formidable' ),
@@ -196,22 +209,22 @@
196 209 'name' => __( 'Appointment', 'formidable' ),
197 210 'icon' => 'frm_icon_font frm_calendar_icon frm_show_upgrade',
198 211 'require' => 'Simply Schedule Appointments',
199 212 '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.
200 - <img src="' . esc_attr( $images_url ) . 'appointments.png" alt="Scheduling" />',
213 + <img src="' . esc_url( $images_url ) . 'appointments.png" alt="Scheduling" />',
201 214 'link' => 'https://simplyscheduleappointments.com/meet/formidable/',
202 215 ),
203 - 'product' => array(
216 + 'product' => array(
204 217 'name' => __( 'Product', 'formidable' ),
205 218 'icon' => 'frm_icon_font frm_product_icon',
206 219 'section' => 'pricing',
207 220 ),
208 - 'quantity' => array(
221 + 'quantity' => array(
209 222 'name' => __( 'Quantity', 'formidable' ),
210 223 'icon' => 'frm_icon_font frm_quantity_icon',
211 224 'section' => 'pricing',
212 225 ),
213 - 'total' => array(
226 + 'total' => array(
214 227 'name' => __( 'Total', 'formidable' ),
215 228 'icon' => 'frm_icon_font frm_total_icon',
216 229 'section' => 'pricing',
217 230 ),
@@ -216,8 +229,21 @@
216 229 'section' => 'pricing',
217 230 ),
218 231 );
219 232
233 + if ( self::include_ranking_fields() ) {
234 + $fields['ranking'] = array(
235 + 'name' => __( 'Ranking', 'formidable' ),
236 + 'icon' => 'frm_icon_font frm_chart_bar_icon frm_show_upgrade',
237 + 'message' => 'Now you can effortlessly gather insights, preferences, and opinions by allowing users to rank options.',
238 + 'upsell_image' => $images_url . 'ranking-field.svg',
239 + 'addon' => 'surveys',
240 + 'is_new' => self::field_is_new( 'ranking' ),
241 + );
242 + } else {
243 + unset( $fields['ranking'] );
244 + }
245 +
220 246 if ( ! FrmAppHelper::show_new_feature( 'ai' ) ) {
221 247 unset( $fields['ai'] );
222 248 }
223 249
@@ -230,9 +256,102 @@
230 256 return apply_filters( 'frm_pro_available_fields', $fields );
231 257 }
232 258
233 259 /**
260 + * Check if we should show ranking fields in the builder.
261 + * This is based on the active version coming from our API data.
262 + * If Surveys v1.1 is not released yet, we don't want to display ranking fields yet.
263 + *
264 + * @since 6.8.3
265 + *
266 + * @return bool
267 + */
268 + private static function include_ranking_fields() {
269 + if ( class_exists( 'FrmSurveys\models\fields\Ranking' ) ) {
270 + // Always return true if Ranking fields exist.
271 + return true;
272 + }
273 +
274 + $plugin = 'formidable-surveys/formidable-surveys.php';
275 + $expected_version = '1.1';
276 +
277 + return self::installed_plugin_meets_version( $plugin, $expected_version ) || self::api_meets_version( $plugin, $expected_version );
278 + }
279 +
280 + /**
281 + * @since 6.8.3
282 + *
283 + * @param string $plugin
284 + * @param string $expected_version
285 + * @return bool
286 + */
287 + private static function installed_plugin_meets_version( $plugin, $expected_version ) {
288 + $installed_version = self::get_installed_version( $plugin );
289 + return $installed_version && version_compare( $installed_version, $expected_version, '>=' );
290 + }
291 +
292 + /**
293 + * @since 6.8.3
294 + *
295 + * @param string $plugin
296 + * @return false|string String version. False if the plugin is not installed.
297 + */
298 + private static function get_installed_version( $plugin ) {
299 + if ( ! function_exists( 'get_plugins' ) ) {
300 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
301 + }
302 + $plugins = get_plugins();
303 + if ( isset( $plugins[ $plugin ] ) && ! empty( $plugins[ $plugin ]['Version'] ) ) {
304 + return $plugins[ $plugin ]['Version'];
305 + }
306 + return false;
307 + }
308 +
309 + /**
310 + * @since 6.8.3
311 + *
312 + * @param string $plugin
313 + * @param string $expected_version
314 + * @return bool
315 + */
316 + private static function api_meets_version( $plugin, $expected_version ) {
317 + $api = new FrmFormApi();
318 + $addons = $api->get_api_info();
319 + $matches = wp_list_filter( $addons, array( 'plugin' => $plugin ) );
320 + if ( ! $matches ) {
321 + return false;
322 + }
323 +
324 + $match = reset( $matches );
325 + if ( empty( $match['new_version'] ) ) {
326 + return false;
327 + }
328 +
329 + $api_version = $match['new_version'];
330 + return version_compare( $api_version, $expected_version, '>=' );
331 + }
332 +
333 + /**
334 + * Consider a field new for 90 days after the release date.
335 + *
336 + * @since 6.8.3
337 + *
338 + * @param string $type
339 + * @return bool
340 + */
341 + private static function field_is_new( $type ) {
342 + if ( 'ranking' === $type ) {
343 + $ranking_release_date = '2024-03-12';
344 + $three_months_after_release = gmdate( 'Y-m-d', strtotime( $ranking_release_date . ' + 90 days' ) );
345 + return gmdate( 'Y-m-d' ) < $three_months_after_release;
346 + }
347 + return false;
348 + }
349 +
350 + /**
234 351 * @since 4.0
352 + *
353 + * @return array
235 354 */
236 355 public static function all_field_selection() {
237 356 $pro_field_selection = self::pro_field_selection();
238 357 return array_merge( $pro_field_selection, self::field_selection() );
@@ -237,8 +356,15 @@
237 356 $pro_field_selection = self::pro_field_selection();
238 357 return array_merge( $pro_field_selection, self::field_selection() );
239 358 }
240 359
360 + /**
361 + * Create a field.
362 + *
363 + * @param array $values
364 + * @param bool $return
365 + * @return false|int
366 + */
241 367 public static function create( $values, $return = true ) {
242 368 global $wpdb, $frm_duplicate_ids;
243 369
244 370 $new_values = array();
@@ -276,27 +402,25 @@
276 402 unset( $k, $v );
277 403 }
278 404
279 405 $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;
406 +
407 + if ( ! $query_results ) {
408 + return false;
284 409 }
285 410
411 + self::delete_form_transient( $new_values['form_id'] );
412 + $new_id = $wpdb->insert_id;
413 +
286 414 if ( ! $return ) {
287 415 return false;
288 416 }
289 417
290 - if ( $query_results ) {
291 - if ( isset( $values['id'] ) ) {
292 - $frm_duplicate_ids[ $values['id'] ] = $new_id;
293 - }
418 + if ( isset( $values['id'] ) ) {
419 + $frm_duplicate_ids[ $values['id'] ] = $new_id;
420 + }
294 421
295 - return $new_id;
296 - } else {
297 - return false;
298 - }
422 + return $new_id;
299 423 }
300 424
301 425 /**
302 426 * @since 5.0.08
@@ -400,11 +524,16 @@
400 524 $new_id = self::create( $values );
401 525 $frm_duplicate_ids[ $field->id ] = $new_id;
402 526 $frm_duplicate_ids[ $field->field_key ] = $new_id;
403 527 unset( $field );
404 - }
528 + }//end foreach
405 529 }
406 530
531 + /**
532 + * @param int|string $id
533 + * @param array $values
534 + * @return false|int
535 + */
407 536 public static function update( $id, $values ) {
408 537 global $wpdb;
409 538
410 539 $id = absint( $id );
@@ -420,10 +549,22 @@
420 549
421 550 self::preserve_format_option_backslashes( $values );
422 551
423 552 if ( isset( $values['type'] ) ) {
424 - $values = apply_filters( 'frm_clean_' . $values['type'] . '_field_options_before_update', $values );
553 + if ( 'dropdown' === $values['type'] ) {
554 + // To avoid conflicts with security plugins the value "dropdown" is sent for select fields.
555 + // This is because "select" gets matched for SQL injection attempts.
556 + $values['type'] = 'select';
557 + }
425 558
559 + /**
560 + * @since 6.9 The Field ID param was added.
561 + *
562 + * @param array $values
563 + * @param int $id Field ID.
564 + */
565 + $values = apply_filters( 'frm_clean_' . $values['type'] . '_field_options_before_update', $values, $id );
566 +
426 567 if ( $values['type'] === 'hidden' && isset( $values['field_options'] ) && isset( $values['field_options']['clear_on_focus'] ) ) {
427 568 // don't keep the old placeholder setting for hidden fields
428 569 $values['field_options']['clear_on_focus'] = 0;
429 570 }
@@ -470,9 +611,9 @@
470 611 * Keep backslashes in the phone format option
471 612 *
472 613 * @since 2.0.8
473 614 *
474 - * @param $values array - pass by reference
615 + * @param array $values Pass by reference.
475 616 */
476 617 private static function preserve_format_option_backslashes( &$values ) {
477 618 if ( isset( $values['field_options']['format'] ) ) {
478 619 $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
@@ -516,8 +657,11 @@
516 657 }
517 658
518 659 /**
519 660 * If $field is numeric, get the field object
661 + *
662 + * @param int|object|string $field
663 + * @return void
520 664 */
521 665 public static function maybe_get_field( &$field ) {
522 666 if ( ! is_object( $field ) ) {
523 667 $field = self::getOne( $field );
@@ -524,10 +668,10 @@
524 668 }
525 669 }
526 670
527 671 /**
528 - * @param string|int $id The field id or key.
529 - * @param bool $filter When true, run the frm_field filter.
672 + * @param int|string $id The field id or key.
673 + * @param bool $filter When true, run the frm_field filter.
530 674 */
531 675 public static function getOne( $id, $filter = false ) {
532 676 if ( empty( $id ) ) {
533 677 return null;
@@ -573,10 +717,10 @@
573 717
574 718 /**
575 719 * Get the field type by key or id
576 720 *
577 - * @param int|string The field id or key
578 - * @param mixed $col The name of the column in the fields database table
721 + * @param int|string $id The field id or key.
722 + * @param mixed $col The name of the column in the fields database table.
579 723 */
580 724 public static function get_type( $id, $col = 'type' ) {
581 725 $field = FrmDb::check_cache( $id, 'frm_field' );
582 726 if ( $field ) {
@@ -592,8 +736,14 @@
592 736
593 737 return $type;
594 738 }
595 739
740 + /**
741 + * @param int|string $form_id
742 + * @param string $type
743 + * @param int|string $limit
744 + * @param string $inc_sub
745 + */
596 746 public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) {
597 747 if ( ! $form_id ) {
598 748 return array();
599 749 }
@@ -613,9 +763,9 @@
613 763 continue;
614 764 }
615 765
616 766 $fields[ $result->id ] = $result;
617 - $count ++;
767 + ++$count;
618 768 if ( $limit == 1 ) {
619 769 $fields = $result;
620 770 break;
621 771 }
@@ -627,9 +777,9 @@
627 777 unset( $result );
628 778 }
629 779
630 780 return wp_unslash( $fields );
631 - }
781 + }//end if
632 782
633 783 self::$use_cache = false;
634 784
635 785 $where = array(
@@ -643,8 +793,15 @@
643 793
644 794 return $results;
645 795 }
646 796
797 + /**
798 + * @param int|string $form_id
799 + * @param int|string $limit
800 + * @param string $inc_embed
801 + * @param string $inc_repeat
802 + * @return array
803 + */
647 804 public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) {
648 805 if ( ! (int) $form_id ) {
649 806 return array();
650 807 }
@@ -657,9 +814,9 @@
657 814
658 815 $fields = array();
659 816 $count = 0;
660 817 foreach ( $results as $result ) {
661 - $count ++;
818 + ++$count;
662 819 $fields[ $result->id ] = $result;
663 820 if ( ! empty( $limit ) && $count >= $limit ) {
664 821 break;
665 822 }
@@ -688,12 +845,12 @@
688 845 /**
689 846 * If repeating fields should be included, adjust $where accordingly
690 847 *
691 848 * @param string $inc_repeat
692 - * @param array $where - pass by reference
849 + * @param array $where Pass by reference.
693 850 */
694 851 private static function maybe_include_repeating_fields( $inc_repeat, &$where ) {
695 - if ( $inc_repeat == 'include' ) {
852 + if ( $inc_repeat === 'include' ) {
696 853 $form_id = $where['fi.form_id'];
697 854 $where[] = array(
698 855 'or' => 1,
699 856 'fi.form_id' => $form_id,
@@ -708,9 +865,9 @@
708 865 if ( 'include' != $inc_embed || $no_sub_forms ) {
709 866 return;
710 867 }
711 868
712 - $form_fields = $results;
869 + $form_fields = $results;
713 870 $should_get_subforms = ( $type !== 'all' && $type !== 'form' && ! empty( $form_id ) );
714 871 if ( $should_get_subforms ) {
715 872 $form_fields = self::get_all_types_in_form( $form_id, 'form' );
716 873 }
@@ -720,9 +877,9 @@
720 877 if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) {
721 878 continue;
722 879 }
723 880
724 - if ( $type == 'all' ) {
881 + if ( $type === 'all' ) {
725 882 $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
726 883 } else {
727 884 $sub_fields = self::get_all_types_in_form( $field->field_options['form_select'], $type );
728 885 }
@@ -727,9 +884,9 @@
727 884 $sub_fields = self::get_all_types_in_form( $field->field_options['form_select'], $type );
728 885 }
729 886
730 887 if ( ! empty( $sub_fields ) ) {
731 - $index = $k + $index_offset;
888 + $index = $k + $index_offset;
732 889 $index_offset += count( $sub_fields );
733 890 array_splice( $results, $index, 0, $sub_fields );
734 891 }
735 892 unset( $field, $sub_fields );
@@ -769,9 +926,9 @@
769 926
770 927 $limit = FrmDb::esc_limit( $limit );
771 928
772 929 $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";
773 - $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
930 + $query_type = $limit === ' LIMIT 1' || $limit == 1 ? 'row' : 'results';
774 931
775 932 if ( is_array( $where ) ) {
776 933 $args = array(
777 934 'order_by' => $order_by,
@@ -781,9 +938,9 @@
781 938 } else {
782 939 // if the query is not an array, then it has already been prepared
783 940 $query .= FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
784 941
785 - $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
942 + $function_name = $query_type === 'row' ? 'get_row' : 'get_results';
786 943 $results = $wpdb->$function_name( $query );
787 944 }
788 945 unset( $where );
789 946
@@ -861,9 +1018,9 @@
861 1018 $fields = array_merge( $fields, $next_fields );
862 1019
863 1020 if ( count( $next_fields ) >= self::$transient_size ) {
864 1021 // if this transient is full, check for another
865 - $next ++;
1022 + ++$next;
866 1023 self::get_next_transient( $fields, $base_name, $next );
867 1024 }
868 1025 }
869 1026 }
@@ -889,18 +1046,25 @@
889 1046
890 1047 return;
891 1048 }
892 1049
893 - $next ++;
1050 + ++$next;
894 1051 }
895 1052 }
896 1053
1054 + /**
1055 + * @param string $type
1056 + * @return bool
1057 + */
897 1058 public static function is_no_save_field( $type ) {
898 - return in_array( $type, self::no_save_fields() );
1059 + return in_array( $type, self::no_save_fields(), true );
899 1060 }
900 1061
1062 + /**
1063 + * @return string[]
1064 + */
901 1065 public static function no_save_fields() {
902 - return array( 'divider', 'end_divider', 'captcha', 'break', 'html', 'form', 'summary' );
1066 + return array( 'divider', 'end_divider', 'captcha', 'break', 'html', 'form', 'summary', FrmSubmitHelper::FIELD_TYPE );
903 1067 }
904 1068
905 1069 /**
906 1070 * Check if this field can hold an array of values
@@ -908,9 +1072,9 @@
908 1072 * @since 2.0.9
909 1073 *
910 1074 * @param array|object $field
911 1075 *
912 - * @return boolean
1076 + * @return bool
913 1077 */
914 1078 public static function is_field_with_multiple_values( $field ) {
915 1079 if ( ! $field ) {
916 1080 return false;
@@ -919,9 +1083,9 @@
919 1083 $field_type = self::get_original_field_type( $field );
920 1084
921 1085 $is_multi_value_field = (
922 1086 self::is_checkbox( $field ) ||
923 - $field_type == 'address' ||
1087 + $field_type === 'address' ||
924 1088 self::is_multiple_select( $field )
925 1089 );
926 1090
927 1091 return $is_multi_value_field;
@@ -928,8 +1092,9 @@
928 1092 }
929 1093
930 1094 /**
931 1095 * @since 3.0
1096 + * @param array|object $field
932 1097 * @return string
933 1098 */
934 1099 public static function get_field_type( $field ) {
935 1100 return is_array( $field ) ? $field['type'] : $field->type;
@@ -943,9 +1108,10 @@
943 1108 $field_type = self::get_field_type( $field );
944 1109 $original_type = self::get_option( $field, 'original_type' );
945 1110
946 1111 if ( ! empty( $original_type ) && $original_type != $field_type ) {
947 - $field_type = $original_type; // check the original type for arrays
1112 + // Check the original type for arrays.
1113 + $field_type = $original_type;
948 1114 }
949 1115
950 1116 return $field_type;
951 1117 }
@@ -953,9 +1119,9 @@
953 1119 /**
954 1120 * Check if this is a multiselect dropdown field
955 1121 *
956 1122 * @since 2.0.9
957 - * @return boolean
1123 + * @return bool
958 1124 */
959 1125 public static function is_multiple_select( $field ) {
960 1126 $field_type = self::get_field_type( $field );
961 1127 $is_multiple = self::is_option_true( $field, 'multiple' ) && self::is_field_type( $field, 'select' ) && $field_type !== 'hidden';
@@ -967,63 +1133,104 @@
967 1133 * Check if a field is read only. Read only can be set in the field options,
968 1134 * but disabled with the shortcode options
969 1135 *
970 1136 * @since 2.0.9
1137 + *
1138 + * @param array|object $field
1139 + * @return bool
971 1140 */
972 1141 public static function is_read_only( $field ) {
973 1142 global $frm_vars;
974 -
975 - return ( self::is_option_true( $field, 'read_only' ) && ( ! isset( $frm_vars['readonly'] ) || $frm_vars['readonly'] != 'disabled' ) );
1143 + return self::is_option_true( $field, 'read_only' ) && ( ! isset( $frm_vars['readonly'] ) || $frm_vars['readonly'] !== 'disabled' );
976 1144 }
977 1145
978 1146 /**
979 1147 * @since 2.0.9
1148 + *
1149 + * @param array $field
1150 + * @return bool
980 1151 */
981 1152 public static function is_required( $field ) {
982 - $required = ( $field['required'] != '0' );
983 - $required = apply_filters( 'frm_is_field_required', $required, $field );
1153 + $required = $field['required'] != '0';
984 1154
1155 + /**
1156 + * @param bool $required
1157 + * @param array $field
1158 + */
1159 + $required = (bool) apply_filters( 'frm_is_field_required', $required, $field );
1160 +
985 1161 return $required;
986 1162 }
987 1163
988 1164 /**
989 1165 * @since 2.0.9
1166 + *
1167 + * @param array|object $field
1168 + * @param string $option
1169 + * @return bool
990 1170 */
991 1171 public static function is_option_true( $field, $option ) {
992 1172 if ( is_array( $field ) ) {
993 1173 return self::is_option_true_in_array( $field, $option );
994 - } else {
995 - return self::is_option_true_in_object( $field, $option );
996 1174 }
1175 + return self::is_option_true_in_object( $field, $option );
997 1176 }
998 1177
999 1178 /**
1000 1179 * @since 2.0.9
1180 + *
1181 + * @param array|object $field
1182 + * @param string $option
1183 + * @return bool
1001 1184 */
1002 1185 public static function is_option_empty( $field, $option ) {
1003 1186 if ( is_array( $field ) ) {
1004 1187 return self::is_option_empty_in_array( $field, $option );
1005 - } else {
1006 - return self::is_option_empty_in_object( $field, $option );
1007 1188 }
1189 + return self::is_option_empty_in_object( $field, $option );
1008 1190 }
1009 1191
1192 + /**
1193 + * @param array $field
1194 + * @param string $option
1195 + * @return bool
1196 + */
1010 1197 public static function is_option_true_in_array( $field, $option ) {
1011 - return isset( $field[ $option ] ) && $field[ $option ];
1198 + return ! empty( $field[ $option ] );
1012 1199 }
1013 1200
1201 + /**
1202 + * @param object $field
1203 + * @param string $option
1204 + * @return bool
1205 + */
1014 1206 public static function is_option_true_in_object( $field, $option ) {
1015 1207 return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ];
1016 1208 }
1017 1209
1210 + /**
1211 + * @param array $field
1212 + * @param string $option
1213 + * @return bool
1214 + */
1018 1215 public static function is_option_empty_in_array( $field, $option ) {
1019 - return ! isset( $field[ $option ] ) || empty( $field[ $option ] );
1216 + return empty( $field[ $option ] );
1020 1217 }
1021 1218
1219 + /**
1220 + * @param object $field
1221 + * @param string $option
1222 + * @return bool
1223 + */
1022 1224 public static function is_option_empty_in_object( $field, $option ) {
1023 - return ! isset( $field->field_options[ $option ] ) || empty( $field->field_options[ $option ] );
1225 + return empty( $field->field_options[ $option ] );
1024 1226 }
1025 1227
1228 + /**
1229 + * @param stdClass $field
1230 + * @param string $option
1231 + * @return bool
1232 + */
1026 1233 public static function is_option_value_in_object( $field, $option ) {
1027 1234 return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != '';
1028 1235 }
1029 1236
@@ -1028,8 +1235,12 @@
1028 1235 }
1029 1236
1030 1237 /**
1031 1238 * @since 2.0.18
1239 + *
1240 + * @param array|object $field
1241 + * @param string $option
1242 + * @return mixed
1032 1243 */
1033 1244 public static function get_option( $field, $option ) {
1034 1245 if ( is_array( $field ) ) {
1035 1246 $option = self::get_option_in_array( $field, $option );
@@ -1039,10 +1250,14 @@
1039 1250
1040 1251 return $option;
1041 1252 }
1042 1253
1254 + /**
1255 + * @param array $field
1256 + * @param string $option
1257 + * @return mixed
1258 + */
1043 1259 public static function get_option_in_array( $field, $option ) {
1044 -
1045 1260 if ( isset( $field[ $option ] ) ) {
1046 1261 $this_option = $field[ $option ];
1047 1262 } elseif ( isset( $field['field_options'] ) && is_array( $field['field_options'] ) && isset( $field['field_options'][ $option ] ) ) {
1048 1263 $this_option = $field['field_options'][ $option ];
@@ -1052,8 +1267,13 @@
1052 1267
1053 1268 return $this_option;
1054 1269 }
1055 1270
1271 + /**
1272 + * @param object $field
1273 + * @param string $option
1274 + * @return mixed
1275 + */
1056 1276 public static function get_option_in_object( $field, $option ) {
1057 1277 return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : '';
1058 1278 }
1059 1279
@@ -1058,17 +1278,20 @@
1058 1278 }
1059 1279
1060 1280 /**
1061 1281 * @since 2.0.09
1282 + *
1283 + * @param array|object $field
1284 + * @return bool
1062 1285 */
1063 1286 public static function is_repeating_field( $field ) {
1064 1287 if ( is_array( $field ) ) {
1065 - $is_repeating_field = ( 'divider' == $field['type'] );
1288 + $is_repeating_field = ( 'divider' === $field['type'] );
1066 1289 } else {
1067 - $is_repeating_field = ( 'divider' == $field->type );
1290 + $is_repeating_field = ( 'divider' === $field->type );
1068 1291 }
1069 1292
1070 - return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) );
1293 + return $is_repeating_field && self::is_option_true( $field, 'repeat' );
1071 1294 }
1072 1295
1073 1296 /**
1074 1297 * @param string $key
@@ -1083,9 +1306,9 @@
1083 1306
1084 1307 /**
1085 1308 * @param string $id
1086 1309 *
1087 - * @return null|string
1310 + * @return string|null
1088 1311 */
1089 1312 public static function get_key_by_id( $id ) {
1090 1313 return FrmDb::get_var( 'frm_fields', array( 'id' => $id ), 'field_key' );
1091 1314 }
@@ -1092,9 +1315,9 @@
1092 1315
1093 1316 public static function is_image( $field ) {
1094 1317 $type = self::get_field_type( $field );
1095 1318
1096 - return ( $type == 'url' && self::get_option( $field, 'show_image' ) );
1319 + return ( $type === 'url' && self::get_option( $field, 'show_image' ) );
1097 1320 }
1098 1321
1099 1322 /**
1100 1323 * Check if field is radio or Dynamic radio
@@ -1102,9 +1325,9 @@
1102 1325 * @since 3.0
1103 1326 *
1104 1327 * @param array|object $field
1105 1328 *
1106 - * @return boolean true if field type is radio or Dynamic radio
1329 + * @return bool true if field type is radio or Dynamic radio
1107 1330 */
1108 1331 public static function is_radio( $field ) {
1109 1332 return self::is_field_type( $field, 'radio' );
1110 1333 }
@@ -1115,9 +1338,9 @@
1115 1338 * @since 3.0
1116 1339 *
1117 1340 * @param array|object $field
1118 1341 *
1119 - * @return boolean true if field type is checkbox or Dynamic checkbox
1342 + * @return bool true if field type is checkbox or Dynamic checkbox
1120 1343 */
1121 1344 public static function is_checkbox( $field ) {
1122 1345 return self::is_field_type( $field, 'checkbox' );
1123 1346 }
@@ -1127,11 +1350,11 @@
1127 1350 *
1128 1351 * @since 3.0
1129 1352 *
1130 1353 * @param array|object $field
1131 - * @param string $is_type Options include radio, checkbox, text
1354 + * @param string $is_type Options include radio, checkbox, text.
1132 1355 *
1133 - * @return boolean true if field type is checkbox or Dynamic checkbox
1356 + * @return bool true if field type is checkbox or Dynamic checkbox
1134 1357 */
1135 1358 public static function is_field_type( $field, $is_type ) {
1136 1359 $field_type = self::get_original_field_type( $field );
1137 1360 $data_type = self::get_option( $field, 'data_type' );