PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.10
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.10
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 +326 -125 6.5.26.10 View file →
@@ -4,73 +4,77 @@
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 12 $fields = array(
13 - 'text' => array(
13 + 'text' => array(
14 14 'name' => __( 'Text', 'formidable' ),
15 15 'icon' => 'frm_icon_font frm_text2_icon',
16 16 ),
17 - 'textarea' => array(
17 + 'textarea' => array(
18 18 'name' => __( 'Paragraph', 'formidable' ),
19 19 'icon' => 'frm_icon_font frm_paragraph_icon',
20 20 ),
21 - 'checkbox' => array(
21 + 'checkbox' => array(
22 22 'name' => __( 'Checkboxes', 'formidable' ),
23 23 'icon' => 'frm_icon_font frm_check_square_icon',
24 24 ),
25 - 'radio' => array(
25 + 'radio' => array(
26 26 'name' => __( 'Radio Buttons', 'formidable' ),
27 27 'icon' => 'frm_icon_font frm_radio_checked_icon',
28 28 ),
29 - 'select' => array(
29 + 'select' => array(
30 30 'name' => __( 'Dropdown', 'formidable' ),
31 31 'icon' => 'frm_icon_font frm_caret_square_down_icon',
32 32 ),
33 - 'email' => array(
33 + 'email' => array(
34 34 'name' => __( 'Email', 'formidable' ),
35 35 'icon' => 'frm_icon_font frm_email_icon',
36 36 ),
37 - 'url' => array(
37 + 'url' => array(
38 38 'name' => __( 'Website/URL', 'formidable' ),
39 39 'icon' => 'frm_icon_font frm_link_icon',
40 40 ),
41 - 'number' => array(
41 + 'number' => array(
42 42 'name' => __( 'Number', 'formidable' ),
43 43 'icon' => 'frm_icon_font frm_hashtag_icon',
44 44 ),
45 - 'name' => array(
45 + 'name' => array(
46 46 'name' => __( 'Name', 'formidable' ),
47 47 'icon' => 'frm_icon_font frm_user_name_icon',
48 48 ),
49 - 'phone' => array(
49 + 'phone' => array(
50 50 'name' => __( 'Phone', 'formidable' ),
51 51 'icon' => 'frm_icon_font frm_phone_icon',
52 52 ),
53 - 'html' => array(
53 + 'html' => array(
54 54 'name' => __( 'HTML', 'formidable' ),
55 55 'icon' => 'frm_icon_font frm_code_icon',
56 56 ),
57 - 'hidden' => array(
57 + 'hidden' => array(
58 58 'name' => __( 'Hidden', 'formidable' ),
59 59 'icon' => 'frm_icon_font frm_eye_slash_icon',
60 60 ),
61 - 'user_id' => array(
61 + 'user_id' => array(
62 62 'name' => __( 'User ID', 'formidable' ),
63 63 'icon' => 'frm_icon_font frm_user_icon',
64 64 ),
65 - 'captcha' => array(
65 + 'captcha' => array(
66 66 'name' => self::get_captcha_field_name(),
67 67 'icon' => 'frm_icon_font frm_shield_check_icon',
68 68 ),
69 - 'credit_card' => array(
70 - 'name' => __( 'Payment', 'formidable' ),
71 - 'icon' => 'frm_icon_font frm_credit_card_icon',
69 + 'credit_card' => array(
70 + 'name' => __( 'Payment', 'formidable' ),
71 + 'icon' => 'frm_icon_font frm_credit_card_icon',
72 72 ),
73 + FrmSubmitHelper::FIELD_TYPE => array(
74 + 'name' => __( 'Submit', 'formidable' ),
75 + 'hide' => true,
76 + ),
73 77 );
74 78
75 79 /**
76 80 * @param array $fields
@@ -83,131 +87,123 @@
83 87 *
84 88 * @return string
85 89 */
86 90 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;
91 + return 'Captcha';
97 92 }
98 93
99 94 public static function pro_field_selection() {
100 95 $images_url = FrmAppHelper::plugin_url() . '/images/';
101 96 $fields = array(
102 - 'file' => array(
103 - 'name' => __( 'File Upload', 'formidable' ),
104 - 'icon' => 'frm_icon_font frm_upload_icon',
97 + 'file' => array(
98 + 'name' => __( 'File Upload', 'formidable' ),
99 + 'icon' => 'frm_icon_font frm_upload_icon',
105 100 'message' => 'Add file uploads to save time and cut down on back-and-forth. Upgrade to Pro to get Upload fields and more.',
106 101 ),
107 - 'rte' => array(
102 + 'ranking' => array(),
103 + 'rte' => array(
108 104 'name' => __( 'Rich Text', 'formidable' ),
109 105 'icon' => 'frm_icon_font frm_align_right_icon',
110 106 ),
111 - 'date' => array(
107 + 'date' => array(
112 108 'name' => __( 'Date', 'formidable' ),
113 109 'icon' => 'frm_icon_font frm_calendar_icon',
114 110 ),
115 - 'time' => array(
111 + 'time' => array(
116 112 'name' => __( 'Time', 'formidable' ),
117 113 'icon' => 'frm_icon_font frm_clock_icon',
118 114 ),
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" />',
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" />',
123 119 ),
124 - 'star' => array(
120 + 'star' => array(
125 121 'name' => __( 'Star Rating', 'formidable' ),
126 122 'icon' => 'frm_icon_font frm_star_icon',
127 123 ),
128 - 'range' => array(
124 + 'range' => array(
129 125 'name' => __( 'Slider', 'formidable' ),
130 126 'icon' => 'frm_icon_font frm_code_commit_icon',
131 127 ),
132 - 'toggle' => array(
128 + 'toggle' => array(
133 129 'name' => __( 'Toggle', 'formidable' ),
134 130 'icon' => 'frm_icon_font frm_toggle_on_icon',
135 131 ),
136 - 'data' => array(
137 - 'name' => __( 'Dynamic', 'formidable' ),
138 - 'icon' => 'frm_icon_font frm_sitemap_icon',
132 + 'data' => array(
133 + 'name' => __( 'Dynamic', 'formidable' ),
134 + 'icon' => 'frm_icon_font frm_sitemap_icon',
139 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.',
140 136 ),
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" />',
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" />',
145 141 ),
146 - '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" />',
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" />',
150 146 ),
151 - 'end_divider' => array(
147 + 'end_divider' => array(
152 148 'name' => __( 'Section Buttons', 'formidable' ),
153 149 'switch_from' => 'divider',
154 150 ),
155 - 'divider' => array(
151 + 'divider' => array(
156 152 'name' => __( 'Section', 'formidable' ),
157 153 'icon' => 'frm_icon_font frm_header_icon',
158 154 ),
159 - 'break' => array(
160 - 'name' => __( 'Page Break', 'formidable' ),
161 - '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',
162 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?',
163 159 ),
164 - 'form' => array(
160 + 'form' => array(
165 161 'name' => __( 'Embed Form', 'formidable' ),
166 162 'icon' => 'frm_icon_font frm_file_text_icon',
167 163 ),
168 - 'likert' => array(
164 + 'likert' => array(
169 165 'name' => __( 'Likert Scale', 'formidable' ),
170 166 'icon' => 'frm_icon_font frm_likert_scale frm_show_upgrade',
171 167 'addon' => 'surveys',
172 168 ),
173 - 'nps' => array(
169 + 'nps' => array(
174 170 'name' => __( 'NPS', 'formidable' ),
175 171 'icon' => 'frm_icon_font frm_nps frm_show_upgrade',
176 172 'addon' => 'surveys',
177 173 ),
178 - 'password' => array(
174 + 'password' => array(
179 175 'name' => __( 'Password', 'formidable' ),
180 176 'icon' => 'frm_icon_font frm_lock_open_icon',
181 177 ),
182 - 'tag' => array(
178 + 'tag' => array(
183 179 'name' => __( 'Tags', 'formidable' ),
184 180 'icon' => 'frm_icon_font frm_price_tags_icon',
185 181 ),
186 182 // This is no longer a Pro field, but without this here, Pro triggers "undefined index" notices.
187 183 // Right now it leaves a gap. Maybe we can skip anything without a name or something.
188 - 'credit_card' => array(
189 - 'name' => '',
190 - 'icon' => '',
184 + 'credit_card' => array(
185 + 'name' => '',
186 + 'icon' => '',
191 187 ),
192 - 'address' => array(
188 + 'address' => array(
193 189 'name' => __( 'Address', 'formidable' ),
194 190 'icon' => 'frm_icon_font frm_location_icon',
195 191 ),
196 - 'summary' => array(
197 - 'name' => __( 'Summary', 'formidable' ),
198 - 'icon' => 'frm_icon_font frm_file_text_icon',
192 + 'summary' => array(
193 + 'name' => __( 'Summary', 'formidable' ),
194 + 'icon' => 'frm_icon_font frm_file_text_icon',
199 195 'message' => 'Allow visitors to review their responses before a form is submitted. Upgrade to Pro to get Summary fields and more.',
200 196 ),
201 - 'signature' => array(
197 + 'signature' => array(
202 198 'name' => __( 'Signature', 'formidable' ),
203 199 'icon' => 'frm_icon_font frm_signature_icon frm_show_upgrade',
204 200 'addon' => 'signature',
205 201 ),
206 - 'ai' => array(
207 - 'name' => __( 'AI', 'formidable' ),
208 - 'icon' => 'frm_icon_font frm_eye_icon frm_show_upgrade',
209 - 'addon' => 'ai',
202 + 'ai' => array(
203 + 'name' => __( 'AI', 'formidable' ),
204 + 'icon' => 'frm_icon_font frm_eye_icon frm_show_upgrade',
205 + 'addon' => 'ai',
210 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.',
211 207 ),
212 208 'ssa-appointment' => array(
213 209 'name' => __( 'Appointment', 'formidable' ),
@@ -213,22 +209,22 @@
213 209 'name' => __( 'Appointment', 'formidable' ),
214 210 'icon' => 'frm_icon_font frm_calendar_icon frm_show_upgrade',
215 211 'require' => 'Simply Schedule Appointments',
216 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.
217 - <img src="' . esc_attr( $images_url ) . 'appointments.png" alt="Scheduling" />',
213 + <img src="' . esc_url( $images_url ) . 'appointments.png" alt="Scheduling" />',
218 214 'link' => 'https://simplyscheduleappointments.com/meet/formidable/',
219 215 ),
220 - 'product' => array(
216 + 'product' => array(
221 217 'name' => __( 'Product', 'formidable' ),
222 218 'icon' => 'frm_icon_font frm_product_icon',
223 219 'section' => 'pricing',
224 220 ),
225 - 'quantity' => array(
221 + 'quantity' => array(
226 222 'name' => __( 'Quantity', 'formidable' ),
227 223 'icon' => 'frm_icon_font frm_quantity_icon',
228 224 'section' => 'pricing',
229 225 ),
230 - 'total' => array(
226 + 'total' => array(
231 227 'name' => __( 'Total', 'formidable' ),
232 228 'icon' => 'frm_icon_font frm_total_icon',
233 229 'section' => 'pricing',
234 230 ),
@@ -233,8 +229,21 @@
233 229 'section' => 'pricing',
234 230 ),
235 231 );
236 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 +
237 246 if ( ! FrmAppHelper::show_new_feature( 'ai' ) ) {
238 247 unset( $fields['ai'] );
239 248 }
240 249
@@ -247,9 +256,102 @@
247 256 return apply_filters( 'frm_pro_available_fields', $fields );
248 257 }
249 258
250 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 + /**
251 351 * @since 4.0
352 + *
353 + * @return array
252 354 */
253 355 public static function all_field_selection() {
254 356 $pro_field_selection = self::pro_field_selection();
255 357 return array_merge( $pro_field_selection, self::field_selection() );
@@ -259,9 +361,9 @@
259 361 * Create a field.
260 362 *
261 363 * @param array $values
262 364 * @param bool $return
263 - * @return int|false
365 + * @return false|int
264 366 */
265 367 public static function create( $values, $return = true ) {
266 368 global $wpdb, $frm_duplicate_ids;
267 369
@@ -422,11 +524,16 @@
422 524 $new_id = self::create( $values );
423 525 $frm_duplicate_ids[ $field->id ] = $new_id;
424 526 $frm_duplicate_ids[ $field->field_key ] = $new_id;
425 527 unset( $field );
426 - }
528 + }//end foreach
427 529 }
428 530
531 + /**
532 + * @param int|string $id
533 + * @param array $values
534 + * @return false|int
535 + */
429 536 public static function update( $id, $values ) {
430 537 global $wpdb;
431 538
432 539 $id = absint( $id );
@@ -442,10 +549,22 @@
442 549
443 550 self::preserve_format_option_backslashes( $values );
444 551
445 552 if ( isset( $values['type'] ) ) {
446 - $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 + }
447 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 +
448 567 if ( $values['type'] === 'hidden' && isset( $values['field_options'] ) && isset( $values['field_options']['clear_on_focus'] ) ) {
449 568 // don't keep the old placeholder setting for hidden fields
450 569 $values['field_options']['clear_on_focus'] = 0;
451 570 }
@@ -492,9 +611,9 @@
492 611 * Keep backslashes in the phone format option
493 612 *
494 613 * @since 2.0.8
495 614 *
496 - * @param $values array - pass by reference
615 + * @param array $values Pass by reference.
497 616 */
498 617 private static function preserve_format_option_backslashes( &$values ) {
499 618 if ( isset( $values['field_options']['format'] ) ) {
500 619 $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
@@ -538,8 +657,11 @@
538 657 }
539 658
540 659 /**
541 660 * If $field is numeric, get the field object
661 + *
662 + * @param int|object|string $field
663 + * @return void
542 664 */
543 665 public static function maybe_get_field( &$field ) {
544 666 if ( ! is_object( $field ) ) {
545 667 $field = self::getOne( $field );
@@ -546,10 +668,10 @@
546 668 }
547 669 }
548 670
549 671 /**
550 - * @param string|int $id The field id or key.
551 - * @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.
552 674 */
553 675 public static function getOne( $id, $filter = false ) {
554 676 if ( empty( $id ) ) {
555 677 return null;
@@ -595,10 +717,10 @@
595 717
596 718 /**
597 719 * Get the field type by key or id
598 720 *
599 - * @param int|string The field id or key
600 - * @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.
601 723 */
602 724 public static function get_type( $id, $col = 'type' ) {
603 725 $field = FrmDb::check_cache( $id, 'frm_field' );
604 726 if ( $field ) {
@@ -614,8 +736,14 @@
614 736
615 737 return $type;
616 738 }
617 739
740 + /**
741 + * @param int|string $form_id
742 + * @param string $type
743 + * @param int|string $limit
744 + * @param string $inc_sub
745 + */
618 746 public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) {
619 747 if ( ! $form_id ) {
620 748 return array();
621 749 }
@@ -635,9 +763,9 @@
635 763 continue;
636 764 }
637 765
638 766 $fields[ $result->id ] = $result;
639 - $count ++;
767 + ++$count;
640 768 if ( $limit == 1 ) {
641 769 $fields = $result;
642 770 break;
643 771 }
@@ -649,9 +777,9 @@
649 777 unset( $result );
650 778 }
651 779
652 780 return wp_unslash( $fields );
653 - }
781 + }//end if
654 782
655 783 self::$use_cache = false;
656 784
657 785 $where = array(
@@ -665,8 +793,15 @@
665 793
666 794 return $results;
667 795 }
668 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 + */
669 804 public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) {
670 805 if ( ! (int) $form_id ) {
671 806 return array();
672 807 }
@@ -679,9 +814,9 @@
679 814
680 815 $fields = array();
681 816 $count = 0;
682 817 foreach ( $results as $result ) {
683 - $count ++;
818 + ++$count;
684 819 $fields[ $result->id ] = $result;
685 820 if ( ! empty( $limit ) && $count >= $limit ) {
686 821 break;
687 822 }
@@ -710,12 +845,12 @@
710 845 /**
711 846 * If repeating fields should be included, adjust $where accordingly
712 847 *
713 848 * @param string $inc_repeat
714 - * @param array $where - pass by reference
849 + * @param array $where Pass by reference.
715 850 */
716 851 private static function maybe_include_repeating_fields( $inc_repeat, &$where ) {
717 - if ( $inc_repeat == 'include' ) {
852 + if ( $inc_repeat === 'include' ) {
718 853 $form_id = $where['fi.form_id'];
719 854 $where[] = array(
720 855 'or' => 1,
721 856 'fi.form_id' => $form_id,
@@ -730,9 +865,9 @@
730 865 if ( 'include' != $inc_embed || $no_sub_forms ) {
731 866 return;
732 867 }
733 868
734 - $form_fields = $results;
869 + $form_fields = $results;
735 870 $should_get_subforms = ( $type !== 'all' && $type !== 'form' && ! empty( $form_id ) );
736 871 if ( $should_get_subforms ) {
737 872 $form_fields = self::get_all_types_in_form( $form_id, 'form' );
738 873 }
@@ -742,9 +877,9 @@
742 877 if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) {
743 878 continue;
744 879 }
745 880
746 - if ( $type == 'all' ) {
881 + if ( $type === 'all' ) {
747 882 $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
748 883 } else {
749 884 $sub_fields = self::get_all_types_in_form( $field->field_options['form_select'], $type );
750 885 }
@@ -749,9 +884,9 @@
749 884 $sub_fields = self::get_all_types_in_form( $field->field_options['form_select'], $type );
750 885 }
751 886
752 887 if ( ! empty( $sub_fields ) ) {
753 - $index = $k + $index_offset;
888 + $index = $k + $index_offset;
754 889 $index_offset += count( $sub_fields );
755 890 array_splice( $results, $index, 0, $sub_fields );
756 891 }
757 892 unset( $field, $sub_fields );
@@ -791,9 +926,9 @@
791 926
792 927 $limit = FrmDb::esc_limit( $limit );
793 928
794 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";
795 - $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
930 + $query_type = $limit === ' LIMIT 1' || $limit == 1 ? 'row' : 'results';
796 931
797 932 if ( is_array( $where ) ) {
798 933 $args = array(
799 934 'order_by' => $order_by,
@@ -803,9 +938,9 @@
803 938 } else {
804 939 // if the query is not an array, then it has already been prepared
805 940 $query .= FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
806 941
807 - $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
942 + $function_name = $query_type === 'row' ? 'get_row' : 'get_results';
808 943 $results = $wpdb->$function_name( $query );
809 944 }
810 945 unset( $where );
811 946
@@ -883,9 +1018,9 @@
883 1018 $fields = array_merge( $fields, $next_fields );
884 1019
885 1020 if ( count( $next_fields ) >= self::$transient_size ) {
886 1021 // if this transient is full, check for another
887 - $next ++;
1022 + ++$next;
888 1023 self::get_next_transient( $fields, $base_name, $next );
889 1024 }
890 1025 }
891 1026 }
@@ -911,18 +1046,25 @@
911 1046
912 1047 return;
913 1048 }
914 1049
915 - $next ++;
1050 + ++$next;
916 1051 }
917 1052 }
918 1053
1054 + /**
1055 + * @param string $type
1056 + * @return bool
1057 + */
919 1058 public static function is_no_save_field( $type ) {
920 - return in_array( $type, self::no_save_fields() );
1059 + return in_array( $type, self::no_save_fields(), true );
921 1060 }
922 1061
1062 + /**
1063 + * @return string[]
1064 + */
923 1065 public static function no_save_fields() {
924 - return array( 'divider', 'end_divider', 'captcha', 'break', 'html', 'form', 'summary' );
1066 + return array( 'divider', 'end_divider', 'captcha', 'break', 'html', 'form', 'summary', FrmSubmitHelper::FIELD_TYPE );
925 1067 }
926 1068
927 1069 /**
928 1070 * Check if this field can hold an array of values
@@ -930,9 +1072,9 @@
930 1072 * @since 2.0.9
931 1073 *
932 1074 * @param array|object $field
933 1075 *
934 - * @return boolean
1076 + * @return bool
935 1077 */
936 1078 public static function is_field_with_multiple_values( $field ) {
937 1079 if ( ! $field ) {
938 1080 return false;
@@ -941,9 +1083,9 @@
941 1083 $field_type = self::get_original_field_type( $field );
942 1084
943 1085 $is_multi_value_field = (
944 1086 self::is_checkbox( $field ) ||
945 - $field_type == 'address' ||
1087 + $field_type === 'address' ||
946 1088 self::is_multiple_select( $field )
947 1089 );
948 1090
949 1091 return $is_multi_value_field;
@@ -950,8 +1092,9 @@
950 1092 }
951 1093
952 1094 /**
953 1095 * @since 3.0
1096 + * @param array|object $field
954 1097 * @return string
955 1098 */
956 1099 public static function get_field_type( $field ) {
957 1100 return is_array( $field ) ? $field['type'] : $field->type;
@@ -965,9 +1108,10 @@
965 1108 $field_type = self::get_field_type( $field );
966 1109 $original_type = self::get_option( $field, 'original_type' );
967 1110
968 1111 if ( ! empty( $original_type ) && $original_type != $field_type ) {
969 - $field_type = $original_type; // check the original type for arrays
1112 + // Check the original type for arrays.
1113 + $field_type = $original_type;
970 1114 }
971 1115
972 1116 return $field_type;
973 1117 }
@@ -975,9 +1119,9 @@
975 1119 /**
976 1120 * Check if this is a multiselect dropdown field
977 1121 *
978 1122 * @since 2.0.9
979 - * @return boolean
1123 + * @return bool
980 1124 */
981 1125 public static function is_multiple_select( $field ) {
982 1126 $field_type = self::get_field_type( $field );
983 1127 $is_multiple = self::is_option_true( $field, 'multiple' ) && self::is_field_type( $field, 'select' ) && $field_type !== 'hidden';
@@ -989,63 +1133,104 @@
989 1133 * Check if a field is read only. Read only can be set in the field options,
990 1134 * but disabled with the shortcode options
991 1135 *
992 1136 * @since 2.0.9
1137 + *
1138 + * @param array|object $field
1139 + * @return bool
993 1140 */
994 1141 public static function is_read_only( $field ) {
995 1142 global $frm_vars;
996 -
997 - 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' );
998 1144 }
999 1145
1000 1146 /**
1001 1147 * @since 2.0.9
1148 + *
1149 + * @param array $field
1150 + * @return bool
1002 1151 */
1003 1152 public static function is_required( $field ) {
1004 - $required = ( $field['required'] != '0' );
1005 - $required = apply_filters( 'frm_is_field_required', $required, $field );
1153 + $required = $field['required'] != '0';
1006 1154
1155 + /**
1156 + * @param bool $required
1157 + * @param array $field
1158 + */
1159 + $required = (bool) apply_filters( 'frm_is_field_required', $required, $field );
1160 +
1007 1161 return $required;
1008 1162 }
1009 1163
1010 1164 /**
1011 1165 * @since 2.0.9
1166 + *
1167 + * @param array|object $field
1168 + * @param string $option
1169 + * @return bool
1012 1170 */
1013 1171 public static function is_option_true( $field, $option ) {
1014 1172 if ( is_array( $field ) ) {
1015 1173 return self::is_option_true_in_array( $field, $option );
1016 - } else {
1017 - return self::is_option_true_in_object( $field, $option );
1018 1174 }
1175 + return self::is_option_true_in_object( $field, $option );
1019 1176 }
1020 1177
1021 1178 /**
1022 1179 * @since 2.0.9
1180 + *
1181 + * @param array|object $field
1182 + * @param string $option
1183 + * @return bool
1023 1184 */
1024 1185 public static function is_option_empty( $field, $option ) {
1025 1186 if ( is_array( $field ) ) {
1026 1187 return self::is_option_empty_in_array( $field, $option );
1027 - } else {
1028 - return self::is_option_empty_in_object( $field, $option );
1029 1188 }
1189 + return self::is_option_empty_in_object( $field, $option );
1030 1190 }
1031 1191
1192 + /**
1193 + * @param array $field
1194 + * @param string $option
1195 + * @return bool
1196 + */
1032 1197 public static function is_option_true_in_array( $field, $option ) {
1033 - return isset( $field[ $option ] ) && $field[ $option ];
1198 + return ! empty( $field[ $option ] );
1034 1199 }
1035 1200
1201 + /**
1202 + * @param object $field
1203 + * @param string $option
1204 + * @return bool
1205 + */
1036 1206 public static function is_option_true_in_object( $field, $option ) {
1037 1207 return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ];
1038 1208 }
1039 1209
1210 + /**
1211 + * @param array $field
1212 + * @param string $option
1213 + * @return bool
1214 + */
1040 1215 public static function is_option_empty_in_array( $field, $option ) {
1041 - return ! isset( $field[ $option ] ) || empty( $field[ $option ] );
1216 + return empty( $field[ $option ] );
1042 1217 }
1043 1218
1219 + /**
1220 + * @param object $field
1221 + * @param string $option
1222 + * @return bool
1223 + */
1044 1224 public static function is_option_empty_in_object( $field, $option ) {
1045 - return ! isset( $field->field_options[ $option ] ) || empty( $field->field_options[ $option ] );
1225 + return empty( $field->field_options[ $option ] );
1046 1226 }
1047 1227
1228 + /**
1229 + * @param stdClass $field
1230 + * @param string $option
1231 + * @return bool
1232 + */
1048 1233 public static function is_option_value_in_object( $field, $option ) {
1049 1234 return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != '';
1050 1235 }
1051 1236
@@ -1050,8 +1235,12 @@
1050 1235 }
1051 1236
1052 1237 /**
1053 1238 * @since 2.0.18
1239 + *
1240 + * @param array|object $field
1241 + * @param string $option
1242 + * @return mixed
1054 1243 */
1055 1244 public static function get_option( $field, $option ) {
1056 1245 if ( is_array( $field ) ) {
1057 1246 $option = self::get_option_in_array( $field, $option );
@@ -1061,10 +1250,14 @@
1061 1250
1062 1251 return $option;
1063 1252 }
1064 1253
1254 + /**
1255 + * @param array $field
1256 + * @param string $option
1257 + * @return mixed
1258 + */
1065 1259 public static function get_option_in_array( $field, $option ) {
1066 -
1067 1260 if ( isset( $field[ $option ] ) ) {
1068 1261 $this_option = $field[ $option ];
1069 1262 } elseif ( isset( $field['field_options'] ) && is_array( $field['field_options'] ) && isset( $field['field_options'][ $option ] ) ) {
1070 1263 $this_option = $field['field_options'][ $option ];
@@ -1074,8 +1267,13 @@
1074 1267
1075 1268 return $this_option;
1076 1269 }
1077 1270
1271 + /**
1272 + * @param object $field
1273 + * @param string $option
1274 + * @return mixed
1275 + */
1078 1276 public static function get_option_in_object( $field, $option ) {
1079 1277 return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : '';
1080 1278 }
1081 1279
@@ -1080,17 +1278,20 @@
1080 1278 }
1081 1279
1082 1280 /**
1083 1281 * @since 2.0.09
1282 + *
1283 + * @param array|object $field
1284 + * @return bool
1084 1285 */
1085 1286 public static function is_repeating_field( $field ) {
1086 1287 if ( is_array( $field ) ) {
1087 - $is_repeating_field = ( 'divider' == $field['type'] );
1288 + $is_repeating_field = ( 'divider' === $field['type'] );
1088 1289 } else {
1089 - $is_repeating_field = ( 'divider' == $field->type );
1290 + $is_repeating_field = ( 'divider' === $field->type );
1090 1291 }
1091 1292
1092 - return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) );
1293 + return $is_repeating_field && self::is_option_true( $field, 'repeat' );
1093 1294 }
1094 1295
1095 1296 /**
1096 1297 * @param string $key
@@ -1105,9 +1306,9 @@
1105 1306
1106 1307 /**
1107 1308 * @param string $id
1108 1309 *
1109 - * @return null|string
1310 + * @return string|null
1110 1311 */
1111 1312 public static function get_key_by_id( $id ) {
1112 1313 return FrmDb::get_var( 'frm_fields', array( 'id' => $id ), 'field_key' );
1113 1314 }
@@ -1114,9 +1315,9 @@
1114 1315
1115 1316 public static function is_image( $field ) {
1116 1317 $type = self::get_field_type( $field );
1117 1318
1118 - return ( $type == 'url' && self::get_option( $field, 'show_image' ) );
1319 + return ( $type === 'url' && self::get_option( $field, 'show_image' ) );
1119 1320 }
1120 1321
1121 1322 /**
1122 1323 * Check if field is radio or Dynamic radio
@@ -1124,9 +1325,9 @@
1124 1325 * @since 3.0
1125 1326 *
1126 1327 * @param array|object $field
1127 1328 *
1128 - * @return boolean true if field type is radio or Dynamic radio
1329 + * @return bool true if field type is radio or Dynamic radio
1129 1330 */
1130 1331 public static function is_radio( $field ) {
1131 1332 return self::is_field_type( $field, 'radio' );
1132 1333 }
@@ -1137,9 +1338,9 @@
1137 1338 * @since 3.0
1138 1339 *
1139 1340 * @param array|object $field
1140 1341 *
1141 - * @return boolean true if field type is checkbox or Dynamic checkbox
1342 + * @return bool true if field type is checkbox or Dynamic checkbox
1142 1343 */
1143 1344 public static function is_checkbox( $field ) {
1144 1345 return self::is_field_type( $field, 'checkbox' );
1145 1346 }
@@ -1149,11 +1350,11 @@
1149 1350 *
1150 1351 * @since 3.0
1151 1352 *
1152 1353 * @param array|object $field
1153 - * @param string $is_type Options include radio, checkbox, text
1354 + * @param string $is_type Options include radio, checkbox, text.
1154 1355 *
1155 - * @return boolean true if field type is checkbox or Dynamic checkbox
1356 + * @return bool true if field type is checkbox or Dynamic checkbox
1156 1357 */
1157 1358 public static function is_field_type( $field, $is_type ) {
1158 1359 $field_type = self::get_original_field_type( $field );
1159 1360 $data_type = self::get_option( $field, 'data_type' );