PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.23
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.23
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 +488 -155 6.36.23 View file →
@@ -4,214 +4,236 @@
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 + ),
77 + FrmFieldGdprHelper::FIELD_TYPE => array(
78 + 'name' => __( 'GDPR', 'formidable' ),
79 + 'icon' => 'frm_icon_font frm-gdpr-icon',
80 + 'hide' => FrmFieldGdprHelper::hide_gdpr_field(),
81 + ),
78 82 );
79 83
84 + /**
85 + * @param array $fields
86 + */
80 87 return apply_filters( 'frm_available_fields', $fields );
81 88 }
82 89
90 + /**
91 + * Get the name of the Captcha field based on the global Captcha setting.
92 + *
93 + * @return string
94 + */
95 + private static function get_captcha_field_name() {
96 + return 'Captcha';
97 + }
98 +
83 99 public static function pro_field_selection() {
84 100 $images_url = FrmAppHelper::plugin_url() . '/images/';
85 101 $fields = array(
86 - 'file' => array(
87 - 'name' => __( 'File Upload', 'formidable' ),
88 - 'icon' => 'frm_icon_font frm_upload_icon',
89 - 'message' => 'Add file uploads to save time and cut down on back-and-forth. Upgrade to Pro to get Upload fields and more.',
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.', 'formidable' ),
90 106 ),
91 - 'rte' => array(
107 + 'ranking' => array(),
108 + 'rte' => array(
92 109 'name' => __( 'Rich Text', 'formidable' ),
93 110 'icon' => 'frm_icon_font frm_align_right_icon',
94 111 ),
95 - 'date' => array(
112 + 'date' => array(
96 113 'name' => __( 'Date', 'formidable' ),
97 114 'icon' => 'frm_icon_font frm_calendar_icon',
98 115 ),
99 - 'time' => array(
116 + 'time' => array(
100 117 'name' => __( 'Time', 'formidable' ),
101 118 'icon' => 'frm_icon_font frm_clock_icon',
102 119 ),
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" />',
120 + 'scale' => array(
121 + 'name' => __( 'Scale', 'formidable' ),
122 + 'icon' => 'frm_icon_font frm_linear_scale_icon',
123 + 'message' => esc_html__( 'Add a set of radio buttons with whatever range you choose.', 'formidable' ) . '<img src="' . esc_url( $images_url ) . 'scale_field.png" alt="' . esc_attr__( 'Scale Field', 'formidable' ) . '" />',
107 124 ),
108 - 'star' => array(
125 + 'star' => array(
109 126 'name' => __( 'Star Rating', 'formidable' ),
110 127 'icon' => 'frm_icon_font frm_star_icon',
111 128 ),
112 - 'range' => array(
129 + 'range' => array(
113 130 'name' => __( 'Slider', 'formidable' ),
114 131 'icon' => 'frm_icon_font frm_code_commit_icon',
115 132 ),
116 - 'toggle' => array(
133 + 'toggle' => array(
117 134 'name' => __( 'Toggle', 'formidable' ),
118 135 'icon' => 'frm_icon_font frm_toggle_on_icon',
119 136 ),
120 - 'data' => array(
121 - 'name' => __( 'Dynamic', 'formidable' ),
122 - 'icon' => 'frm_icon_font frm_sitemap_icon',
123 - '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.',
137 + 'data' => array(
138 + 'name' => __( 'Dynamic', 'formidable' ),
139 + 'icon' => 'frm_icon_font frm_sitemap_icon',
140 + '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.', 'formidable' ),
124 141 ),
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" />',
142 + 'lookup' => array(
143 + 'name' => __( 'Lookup', 'formidable' ),
144 + 'icon' => 'frm_icon_font frm_search_icon',
145 + 'message' => esc_html__( 'Filter the options in the next field and automatically add values to other fields. Upgrade to Pro to get Lookup fields and more.', 'formidable' ) . ' <img src="' . esc_url( $images_url ) . 'look-up_year-make-model.gif" alt="' . esc_attr__( 'cascading lookup fields', 'formidable' ) . '" />',
129 146 ),
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" />',
147 + 'divider|repeat' => array(
148 + 'name' => __( 'Repeater', 'formidable' ),
149 + 'icon' => 'frm_icon_font frm_repeater_icon',
150 + 'message' => esc_html__( 'Allow your visitors to add new sets of fields while filling out forms. Increase conversions while saving building time and server resources.', 'formidable' ) . ' <img src="' . esc_url( $images_url ) . 'repeatable-section_frontend.gif" alt="' . esc_attr__( 'Dynamically Add Form Fields with repeatable sections', 'formidable' ) . '" />',
134 151 ),
135 - 'end_divider' => array(
152 + 'end_divider' => array(
136 153 'name' => __( 'Section Buttons', 'formidable' ),
137 154 'switch_from' => 'divider',
138 155 ),
139 - 'divider' => array(
156 + 'divider' => array(
140 157 'name' => __( 'Section', 'formidable' ),
141 158 'icon' => 'frm_icon_font frm_header_icon',
142 159 ),
143 - 'break' => array(
144 - 'name' => __( 'Page Break', 'formidable' ),
145 - 'icon' => 'frm_icon_font frm_page_break_icon',
146 - '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?',
160 + 'break' => array(
161 + 'name' => __( 'Page Break', 'formidable' ),
162 + 'icon' => 'frm_icon_font frm_page_break_icon',
163 + '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?', 'formidable' ),
147 164 ),
148 - 'form' => array(
165 + 'form' => array(
149 166 'name' => __( 'Embed Form', 'formidable' ),
150 167 'icon' => 'frm_icon_font frm_file_text_icon',
151 168 ),
152 - 'likert' => array(
169 + 'likert' => array(
153 170 'name' => __( 'Likert Scale', 'formidable' ),
154 171 'icon' => 'frm_icon_font frm_likert_scale frm_show_upgrade',
155 172 'addon' => 'surveys',
156 173 ),
157 - 'nps' => array(
174 + 'nps' => array(
158 175 'name' => __( 'NPS', 'formidable' ),
159 176 'icon' => 'frm_icon_font frm_nps frm_show_upgrade',
160 177 'addon' => 'surveys',
161 178 ),
162 - 'password' => array(
179 + 'password' => array(
163 180 'name' => __( 'Password', 'formidable' ),
164 181 'icon' => 'frm_icon_font frm_lock_open_icon',
165 182 ),
166 - 'tag' => array(
183 + 'tag' => array(
167 184 'name' => __( 'Tags', 'formidable' ),
168 185 'icon' => 'frm_icon_font frm_price_tags_icon',
169 186 ),
170 - 'credit_card' => array(
171 - 'name' => __( 'Credit Card', 'formidable' ),
172 - 'icon' => 'frm_icon_font frm_credit_card_icon frm_show_upgrade',
173 - 'addon' => 'stripe',
187 + // This is no longer a Pro field, but without this here, Pro triggers "undefined index" notices.
188 + // Right now it leaves a gap. Maybe we can skip anything without a name or something.
189 + 'credit_card' => array(
190 + 'name' => '',
191 + 'icon' => '',
174 192 ),
175 - 'address' => array(
193 + 'address' => array(
176 194 'name' => __( 'Address', 'formidable' ),
177 195 'icon' => 'frm_icon_font frm_location_icon',
178 196 ),
179 - 'summary' => array(
180 - 'name' => __( 'Summary', 'formidable' ),
181 - 'icon' => 'frm_icon_font frm_file_text_icon',
182 - 'message' => 'Allow visitors to review their responses before a form is submitted. Upgrade to Pro to get Summary fields and more.',
197 + 'summary' => array(
198 + 'name' => __( 'Summary', 'formidable' ),
199 + 'icon' => 'frm_icon_font frm_file_text_icon',
200 + 'message' => __( 'Allow visitors to review their responses before a form is submitted. Upgrade to Pro to get Summary fields and more.', 'formidable' ),
183 201 ),
184 - 'signature' => array(
202 + 'signature' => array(
185 203 'name' => __( 'Signature', 'formidable' ),
186 204 'icon' => 'frm_icon_font frm_signature_icon frm_show_upgrade',
187 205 'addon' => 'signature',
188 206 ),
189 - 'ai' => array(
190 - 'name' => __( 'AI', 'formidable' ),
191 - 'icon' => 'frm_icon_font frm_eye_icon frm_show_upgrade',
192 - 'addon' => 'ai',
193 - '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.',
207 + 'ai' => array(
208 + 'name' => __( 'AI', 'formidable' ),
209 + 'icon' => 'frm_icon_font frm_eye_icon frm_show_upgrade',
210 + 'addon' => 'ai',
211 + '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.', 'formidable' ),
194 212 ),
195 213 'ssa-appointment' => array(
196 214 'name' => __( 'Appointment', 'formidable' ),
197 215 'icon' => 'frm_icon_font frm_calendar_icon frm_show_upgrade',
198 216 'require' => 'Simply Schedule Appointments',
199 - '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" />',
217 + 'message' => sprintf(
218 + /* translators: %1$s: Link opening HTML, %2$s: Link tag closing */
219 + esc_html__( 'Appointment fields are an integration with %1$sSimply Schedule Appointments%2$s. Get started now to schedule appointments directly from your forms.', 'formidable' ),
220 + '<a href="https://simplyscheduleappointments.com/meet/formidable/">',
221 + '</a>'
222 + ) . '<img src="' . esc_url( $images_url ) . 'appointments.png" alt="' . esc_attr__( 'Scheduling', 'formidable' ) . '" />',
201 223 'link' => 'https://simplyscheduleappointments.com/meet/formidable/',
202 224 ),
203 - 'product' => array(
225 + 'product' => array(
204 226 'name' => __( 'Product', 'formidable' ),
205 227 'icon' => 'frm_icon_font frm_product_icon',
206 228 'section' => 'pricing',
207 229 ),
208 - 'quantity' => array(
230 + 'quantity' => array(
209 231 'name' => __( 'Quantity', 'formidable' ),
210 232 'icon' => 'frm_icon_font frm_quantity_icon',
211 233 'section' => 'pricing',
212 234 ),
213 - 'total' => array(
235 + 'total' => array(
214 236 'name' => __( 'Total', 'formidable' ),
215 237 'icon' => 'frm_icon_font frm_total_icon',
216 238 'section' => 'pricing',
217 239 ),
@@ -216,8 +238,21 @@
216 238 'section' => 'pricing',
217 239 ),
218 240 );
219 241
242 + if ( self::include_ranking_fields() ) {
243 + $fields['ranking'] = array(
244 + 'name' => __( 'Ranking', 'formidable' ),
245 + 'icon' => 'frm_icon_font frm_chart_bar_icon frm_show_upgrade',
246 + 'message' => __( 'Now you can effortlessly gather insights, preferences, and opinions by allowing users to rank options.', 'formidable' ),
247 + 'upsell_image' => esc_url( $images_url ) . 'ranking-field.svg',
248 + 'addon' => 'surveys',
249 + 'is_new' => self::field_is_new( 'ranking' ),
250 + );
251 + } else {
252 + unset( $fields['ranking'] );
253 + }
254 +
220 255 if ( ! FrmAppHelper::show_new_feature( 'ai' ) ) {
221 256 unset( $fields['ai'] );
222 257 }
223 258
@@ -230,9 +265,102 @@
230 265 return apply_filters( 'frm_pro_available_fields', $fields );
231 266 }
232 267
233 268 /**
269 + * Check if we should show ranking fields in the builder.
270 + * This is based on the active version coming from our API data.
271 + * If Surveys v1.1 is not released yet, we don't want to display ranking fields yet.
272 + *
273 + * @since 6.8.3
274 + *
275 + * @return bool
276 + */
277 + private static function include_ranking_fields() {
278 + if ( class_exists( 'FrmSurveys\models\fields\Ranking' ) ) {
279 + // Always return true if Ranking fields exist.
280 + return true;
281 + }
282 +
283 + $plugin = 'formidable-surveys/formidable-surveys.php';
284 + $expected_version = '1.1';
285 +
286 + return self::installed_plugin_meets_version( $plugin, $expected_version ) || self::api_meets_version( $plugin, $expected_version );
287 + }
288 +
289 + /**
290 + * @since 6.8.3
291 + *
292 + * @param string $plugin
293 + * @param string $expected_version
294 + * @return bool
295 + */
296 + private static function installed_plugin_meets_version( $plugin, $expected_version ) {
297 + $installed_version = self::get_installed_version( $plugin );
298 + return $installed_version && version_compare( $installed_version, $expected_version, '>=' );
299 + }
300 +
301 + /**
302 + * @since 6.8.3
303 + *
304 + * @param string $plugin
305 + * @return false|string String version. False if the plugin is not installed.
306 + */
307 + private static function get_installed_version( $plugin ) {
308 + if ( ! function_exists( 'get_plugins' ) ) {
309 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
310 + }
311 + $plugins = get_plugins();
312 + if ( isset( $plugins[ $plugin ] ) && ! empty( $plugins[ $plugin ]['Version'] ) ) {
313 + return $plugins[ $plugin ]['Version'];
314 + }
315 + return false;
316 + }
317 +
318 + /**
319 + * @since 6.8.3
320 + *
321 + * @param string $plugin
322 + * @param string $expected_version
323 + * @return bool
324 + */
325 + private static function api_meets_version( $plugin, $expected_version ) {
326 + $api = new FrmFormApi();
327 + $addons = $api->get_api_info();
328 + $matches = wp_list_filter( $addons, array( 'plugin' => $plugin ) );
329 + if ( ! $matches ) {
330 + return false;
331 + }
332 +
333 + $match = reset( $matches );
334 + if ( empty( $match['new_version'] ) ) {
335 + return false;
336 + }
337 +
338 + $api_version = $match['new_version'];
339 + return version_compare( $api_version, $expected_version, '>=' );
340 + }
341 +
342 + /**
343 + * Consider a field new for 90 days after the release date.
344 + *
345 + * @since 6.8.3
346 + *
347 + * @param string $type
348 + * @return bool
349 + */
350 + private static function field_is_new( $type ) {
351 + if ( 'ranking' === $type ) {
352 + $ranking_release_date = '2024-03-12';
353 + $three_months_after_release = gmdate( 'Y-m-d', strtotime( $ranking_release_date . ' + 90 days' ) );
354 + return gmdate( 'Y-m-d' ) < $three_months_after_release;
355 + }
356 + return false;
357 + }
358 +
359 + /**
234 360 * @since 4.0
361 + *
362 + * @return array
235 363 */
236 364 public static function all_field_selection() {
237 365 $pro_field_selection = self::pro_field_selection();
238 366 return array_merge( $pro_field_selection, self::field_selection() );
@@ -237,8 +365,15 @@
237 365 $pro_field_selection = self::pro_field_selection();
238 366 return array_merge( $pro_field_selection, self::field_selection() );
239 367 }
240 368
369 + /**
370 + * Create a field.
371 + *
372 + * @param array $values
373 + * @param bool $return
374 + * @return false|int
375 + */
241 376 public static function create( $values, $return = true ) {
242 377 global $wpdb, $frm_duplicate_ids;
243 378
244 379 $new_values = array();
@@ -247,9 +382,11 @@
247 382
248 383 $values = FrmAppHelper::maybe_filter_array( $values, array( 'name', 'description' ) );
249 384
250 385 foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) {
251 - $new_values[ $col ] = $values[ $col ];
386 + if ( isset( $values[ $col ] ) ) {
387 + $new_values[ $col ] = $values[ $col ];
388 + }
252 389 }
253 390
254 391 $new_values['options'] = self::maybe_filter_options( $values['options'] );
255 392 $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null;
@@ -276,30 +413,32 @@
276 413 unset( $k, $v );
277 414 }
278 415
279 416 $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;
417 +
418 + if ( ! $query_results ) {
419 + return false;
284 420 }
285 421
422 + self::delete_form_transient( $new_values['form_id'] );
423 + $new_id = $wpdb->insert_id;
424 +
286 425 if ( ! $return ) {
287 426 return false;
288 427 }
289 428
290 - if ( $query_results ) {
291 - if ( isset( $values['id'] ) ) {
292 - $frm_duplicate_ids[ $values['id'] ] = $new_id;
293 - }
429 + if ( isset( $values['id'] ) ) {
430 + $frm_duplicate_ids[ $values['id'] ] = $new_id;
431 + }
294 432
295 - return $new_id;
296 - } else {
297 - return false;
298 - }
433 + return $new_id;
299 434 }
300 435
301 436 /**
437 + * Maybe filter HTML in field options data.
438 + * HTML is only filtered when unsafe HTML is disallowed.
439 + * See FrmAppHelper::allow_unfiltered_html.
440 + *
302 441 * @since 5.0.08
303 442 *
304 443 * @param array $options
305 444 * @return array
@@ -304,12 +443,82 @@
304 443 * @param array $options
305 444 * @return array
306 445 */
307 446 private static function maybe_filter_options( $options ) {
308 - return FrmAppHelper::maybe_filter_array( $options, array( 'custom_html' ) );
447 + $options = FrmAppHelper::maybe_filter_array( $options, array( 'custom_html' ) );
448 +
449 + if ( ! empty( $options['custom_html'] ) ) {
450 + $options['custom_html'] = self::maybe_filter_custom_html_input_attributes( $options['custom_html'] );
451 + }
452 +
453 + if ( ! empty( $options['classes'] ) ) {
454 + $options['classes'] = implode( ' ', array_map( 'FrmFormsHelper::sanitize_layout_class', explode( ' ', $options['classes'] ) ) );
455 + }
456 +
457 + return $options;
309 458 }
310 459
311 460 /**
461 + * Prevent users who do not have permission to insert JavaScript attributes in input elements.
462 + * This is triggered when a field is updated.
463 + *
464 + * @since 6.11.2
465 + *
466 + * @param string $html
467 + * @return string
468 + */
469 + private static function maybe_filter_custom_html_input_attributes( $html ) {
470 + if ( FrmAppHelper::allow_unfiltered_html() ) {
471 + return $html;
472 + }
473 +
474 + $pattern = get_shortcode_regex( array( 'input' ) );
475 + return preg_replace_callback(
476 + "/$pattern/",
477 + /**
478 + * @param array $match Shortcode data.
479 + * @return string
480 + */
481 + function ( $match ) {
482 + $attr = shortcode_parse_atts( $match[3] );
483 +
484 + if ( ! is_array( $attr ) ) {
485 + // In old versions of WordPress (older than 6.5), this might not be an array.
486 + return '[input]';
487 + }
488 +
489 + $safe_atts = array();
490 + foreach ( $attr as $attr_key => $att ) {
491 + if ( ! is_numeric( $attr_key ) ) {
492 + // opt=1 without parentheses for example is mapped like 'opt' => 1.
493 + $key = $attr_key;
494 + $value = $att;
495 + } else {
496 + // Some data is mapped like 0 => 'placeholder="Placeholder"'.
497 + $split = explode( '=', $att, 2 );
498 + if ( 2 !== count( $split ) ) {
499 + continue;
500 + }
501 + $key = trim( $split[0] );
502 + $value = trim( $split[1], '"' );
503 + }
504 +
505 + if ( FrmAppHelper::input_key_is_safe( $key, 'update' ) ) {
506 + $safe_atts[ $key ] = $value;
507 + }
508 + }
509 +
510 + if ( ! $safe_atts ) {
511 + return '[input]';
512 + }
513 +
514 + return '[input ' . FrmAppHelper::array_to_html_params( $safe_atts ) . ']';
515 + },
516 + $html
517 + );
518 + }
519 +
520 + /**
312 521 * Process the field duplication.
313 522 *
314 523 * @since 5.0.05
315 524 */
@@ -400,11 +609,16 @@
400 609 $new_id = self::create( $values );
401 610 $frm_duplicate_ids[ $field->id ] = $new_id;
402 611 $frm_duplicate_ids[ $field->field_key ] = $new_id;
403 612 unset( $field );
404 - }
613 + }//end foreach
405 614 }
406 615
616 + /**
617 + * @param int|string $id
618 + * @param array $values
619 + * @return false|int
620 + */
407 621 public static function update( $id, $values ) {
408 622 global $wpdb;
409 623
410 624 $id = absint( $id );
@@ -420,10 +634,22 @@
420 634
421 635 self::preserve_format_option_backslashes( $values );
422 636
423 637 if ( isset( $values['type'] ) ) {
424 - $values = apply_filters( 'frm_clean_' . $values['type'] . '_field_options_before_update', $values );
638 + if ( 'dropdown' === $values['type'] ) {
639 + // To avoid conflicts with security plugins the value "dropdown" is sent for select fields.
640 + // This is because "select" gets matched for SQL injection attempts.
641 + $values['type'] = 'select';
642 + }
425 643
644 + /**
645 + * @since 6.9 The Field ID param was added.
646 + *
647 + * @param array $values
648 + * @param int $id Field ID.
649 + */
650 + $values = apply_filters( 'frm_clean_' . $values['type'] . '_field_options_before_update', $values, $id );
651 +
426 652 if ( $values['type'] === 'hidden' && isset( $values['field_options'] ) && isset( $values['field_options']['clear_on_focus'] ) ) {
427 653 // don't keep the old placeholder setting for hidden fields
428 654 $values['field_options']['clear_on_focus'] = 0;
429 655 }
@@ -470,9 +696,9 @@
470 696 * Keep backslashes in the phone format option
471 697 *
472 698 * @since 2.0.8
473 699 *
474 - * @param $values array - pass by reference
700 + * @param array $values Pass by reference.
475 701 */
476 702 private static function preserve_format_option_backslashes( &$values ) {
477 703 if ( isset( $values['field_options']['format'] ) ) {
478 704 $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
@@ -516,8 +742,11 @@
516 742 }
517 743
518 744 /**
519 745 * If $field is numeric, get the field object
746 + *
747 + * @param int|object|string $field
748 + * @return void
520 749 */
521 750 public static function maybe_get_field( &$field ) {
522 751 if ( ! is_object( $field ) ) {
523 752 $field = self::getOne( $field );
@@ -524,10 +753,10 @@
524 753 }
525 754 }
526 755
527 756 /**
528 - * @param string|int $id The field id or key.
529 - * @param bool $filter When true, run the frm_field filter.
757 + * @param int|string $id The field id or key.
758 + * @param bool $filter When true, run the frm_field filter.
530 759 */
531 760 public static function getOne( $id, $filter = false ) {
532 761 if ( empty( $id ) ) {
533 762 return null;
@@ -573,10 +802,10 @@
573 802
574 803 /**
575 804 * Get the field type by key or id
576 805 *
577 - * @param int|string The field id or key
578 - * @param mixed $col The name of the column in the fields database table
806 + * @param int|string $id The field id or key.
807 + * @param mixed $col The name of the column in the fields database table.
579 808 */
580 809 public static function get_type( $id, $col = 'type' ) {
581 810 $field = FrmDb::check_cache( $id, 'frm_field' );
582 811 if ( $field ) {
@@ -581,19 +810,25 @@
581 810 $field = FrmDb::check_cache( $id, 'frm_field' );
582 811 if ( $field ) {
583 812 $type = $field->{$col};
584 813 } else {
585 - $where = array(
586 - 'or' => 1,
587 - 'id' => $id,
588 - 'field_key' => $id,
589 - );
590 - $type = FrmDb::get_var( 'frm_fields', $where, $col );
814 + if ( is_numeric( $id ) ) {
815 + $where = array( 'id' => $id );
816 + } else {
817 + $where = array( 'field_key' => $id );
818 + }
819 + $type = FrmDb::get_var( 'frm_fields', $where, $col );
591 820 }
592 821
593 822 return $type;
594 823 }
595 824
825 + /**
826 + * @param int|string $form_id
827 + * @param string $type
828 + * @param int|string $limit
829 + * @param string $inc_sub
830 + */
596 831 public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) {
597 832 if ( ! $form_id ) {
598 833 return array();
599 834 }
@@ -613,9 +848,9 @@
613 848 continue;
614 849 }
615 850
616 851 $fields[ $result->id ] = $result;
617 - $count ++;
852 + ++$count;
618 853 if ( $limit == 1 ) {
619 854 $fields = $result;
620 855 break;
621 856 }
@@ -627,9 +862,9 @@
627 862 unset( $result );
628 863 }
629 864
630 865 return wp_unslash( $fields );
631 - }
866 + }//end if
632 867
633 868 self::$use_cache = false;
634 869
635 870 $where = array(
@@ -643,8 +878,15 @@
643 878
644 879 return $results;
645 880 }
646 881
882 + /**
883 + * @param int|string $form_id
884 + * @param int|string $limit
885 + * @param string $inc_embed
886 + * @param string $inc_repeat
887 + * @return array
888 + */
647 889 public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) {
648 890 if ( ! (int) $form_id ) {
649 891 return array();
650 892 }
@@ -657,9 +899,9 @@
657 899
658 900 $fields = array();
659 901 $count = 0;
660 902 foreach ( $results as $result ) {
661 - $count ++;
903 + ++$count;
662 904 $fields[ $result->id ] = $result;
663 905 if ( ! empty( $limit ) && $count >= $limit ) {
664 906 break;
665 907 }
@@ -688,12 +930,12 @@
688 930 /**
689 931 * If repeating fields should be included, adjust $where accordingly
690 932 *
691 933 * @param string $inc_repeat
692 - * @param array $where - pass by reference
934 + * @param array $where Pass by reference.
693 935 */
694 936 private static function maybe_include_repeating_fields( $inc_repeat, &$where ) {
695 - if ( $inc_repeat == 'include' ) {
937 + if ( $inc_repeat === 'include' ) {
696 938 $form_id = $where['fi.form_id'];
697 939 $where[] = array(
698 940 'or' => 1,
699 941 'fi.form_id' => $form_id,
@@ -708,9 +950,9 @@
708 950 if ( 'include' != $inc_embed || $no_sub_forms ) {
709 951 return;
710 952 }
711 953
712 - $form_fields = $results;
954 + $form_fields = $results;
713 955 $should_get_subforms = ( $type !== 'all' && $type !== 'form' && ! empty( $form_id ) );
714 956 if ( $should_get_subforms ) {
715 957 $form_fields = self::get_all_types_in_form( $form_id, 'form' );
716 958 }
@@ -720,9 +962,9 @@
720 962 if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) {
721 963 continue;
722 964 }
723 965
724 - if ( $type == 'all' ) {
966 + if ( $type === 'all' ) {
725 967 $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
726 968 } else {
727 969 $sub_fields = self::get_all_types_in_form( $field->field_options['form_select'], $type );
728 970 }
@@ -727,9 +969,9 @@
727 969 $sub_fields = self::get_all_types_in_form( $field->field_options['form_select'], $type );
728 970 }
729 971
730 972 if ( ! empty( $sub_fields ) ) {
731 - $index = $k + $index_offset;
973 + $index = $k + $index_offset;
732 974 $index_offset += count( $sub_fields );
733 975 array_splice( $results, $index, 0, $sub_fields );
734 976 }
735 977 unset( $field, $sub_fields );
@@ -768,10 +1010,10 @@
768 1010 }
769 1011
770 1012 $limit = FrmDb::esc_limit( $limit );
771 1013
772 - $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';
1014 + $query = "SELECT fi.*, fr.name as form_name FROM {$table_name} fi JOIN {$form_table_name} fr ON fi.form_id=fr.id";
1015 + $query_type = $limit === ' LIMIT 1' || $limit == 1 ? 'row' : 'results';
774 1016
775 1017 if ( is_array( $where ) ) {
776 1018 $args = array(
777 1019 'order_by' => $order_by,
@@ -776,14 +1018,14 @@
776 1018 $args = array(
777 1019 'order_by' => $order_by,
778 1020 'limit' => $limit,
779 1021 );
780 - $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 );
1022 + $results = FrmDb::get_var( $table_name . ' fi JOIN ' . $form_table_name . ' fr ON fi.form_id=fr.id', $where, 'fi.*, fr.name as form_name', $args, '', $query_type );
781 1023 } else {
782 1024 // if the query is not an array, then it has already been prepared
783 1025 $query .= FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
784 1026
785 - $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
1027 + $function_name = $query_type === 'row' ? 'get_row' : 'get_results';
786 1028 $results = $wpdb->$function_name( $query );
787 1029 }
788 1030 unset( $where );
789 1031
@@ -799,8 +1041,10 @@
799 1041 */
800 1042 private static function format_field_results( &$results ) {
801 1043 if ( is_array( $results ) ) {
802 1044 foreach ( $results as $r_key => $result ) {
1045 + self::add_slashes_to_format_before_setting_field_cache( $result );
1046 +
803 1047 FrmDb::set_cache( $result->id, $result, 'frm_field' );
804 1048 FrmDb::set_cache( $result->field_key, $result, 'frm_field' );
805 1049
806 1050 self::prepare_options( $result );
@@ -818,8 +1062,26 @@
818 1062 }
819 1063 }
820 1064
821 1065 /**
1066 + * When $result->field_options is an array and not a serialized string there is only a single backslash.
1067 + * Cached results are unslashed in FrmField::getAll, so we need to make sure that the cached object has an extra backslash.
1068 + * Otherwise the backslash is stripped away on load.
1069 + *
1070 + * @since 6.15
1071 + *
1072 + * @param stdClass $result
1073 + * @return void
1074 + */
1075 + private static function add_slashes_to_format_before_setting_field_cache( $result ) {
1076 + if ( ! isset( $result->field_options ) || ! is_array( $result->field_options ) || empty( $result->field_options['format'] ) ) {
1077 + return;
1078 + }
1079 +
1080 + $result->field_options['format'] = addslashes( $result->field_options['format'] );
1081 + }
1082 +
1083 + /**
822 1084 * Unserialize all the serialized field data
823 1085 *
824 1086 * @since 2.0
825 1087 */
@@ -828,16 +1090,21 @@
828 1090 FrmAppHelper::unserialize_or_decode( $results->options );
829 1091
830 1092 // Allow a single box to be checked for the default value.
831 1093 $before = $results->default_value;
832 - FrmAppHelper::unserialize_or_decode( $results->default_value );
833 - if ( $before === $results->default_value && ! is_array( $before ) && strpos( $before, '["' ) === 0 ) {
834 - $results->default_value = FrmAppHelper::maybe_json_decode( $results->default_value );
1094 +
1095 + $field_object = FrmFieldFactory::get_field_type( $results->type );
1096 +
1097 + if ( $field_object->should_unserialize_value() ) {
1098 + FrmAppHelper::unserialize_or_decode( $results->default_value );
1099 + if ( $before === $results->default_value && is_string( $before ) && strpos( $before, '["' ) === 0 ) {
1100 + $results->default_value = FrmAppHelper::maybe_json_decode( $results->default_value );
1101 + }
835 1102 }
836 1103 }
837 1104
838 1105 /**
839 - * If a form has too many fields, thay won't all save into a single transient.
1106 + * If a form has too many fields, they won't all save into a single transient.
840 1107 * We'll break them into groups of 200
841 1108 *
842 1109 * @since 2.0.1
843 1110 */
@@ -861,9 +1128,9 @@
861 1128 $fields = array_merge( $fields, $next_fields );
862 1129
863 1130 if ( count( $next_fields ) >= self::$transient_size ) {
864 1131 // if this transient is full, check for another
865 - $next ++;
1132 + ++$next;
866 1133 self::get_next_transient( $fields, $base_name, $next );
867 1134 }
868 1135 }
869 1136 }
@@ -882,9 +1149,9 @@
882 1149 $set = set_transient( $name, $field, 60 * 60 * 6 );
883 1150 if ( ! $set ) {
884 1151 // the transient didn't save
885 1152 if ( $name != $base_name ) {
886 - // if the first saved an others fail, this will show an incmoplete form
1153 + // if the first saved an others fail, this will show an incomplete form
887 1154 self::delete_form_transient( $form_id );
888 1155 }
889 1156
890 1157 return;
@@ -889,18 +1156,25 @@
889 1156
890 1157 return;
891 1158 }
892 1159
893 - $next ++;
1160 + ++$next;
894 1161 }
895 1162 }
896 1163
1164 + /**
1165 + * @param string $type
1166 + * @return bool
1167 + */
897 1168 public static function is_no_save_field( $type ) {
898 - return in_array( $type, self::no_save_fields() );
1169 + return in_array( $type, self::no_save_fields(), true );
899 1170 }
900 1171
1172 + /**
1173 + * @return string[]
1174 + */
901 1175 public static function no_save_fields() {
902 - return array( 'divider', 'end_divider', 'captcha', 'break', 'html', 'form', 'summary' );
1176 + return array( 'divider', 'end_divider', 'captcha', 'break', 'html', 'form', 'summary', FrmSubmitHelper::FIELD_TYPE );
903 1177 }
904 1178
905 1179 /**
906 1180 * Check if this field can hold an array of values
@@ -908,9 +1182,9 @@
908 1182 * @since 2.0.9
909 1183 *
910 1184 * @param array|object $field
911 1185 *
912 - * @return boolean
1186 + * @return bool
913 1187 */
914 1188 public static function is_field_with_multiple_values( $field ) {
915 1189 if ( ! $field ) {
916 1190 return false;
@@ -919,9 +1193,9 @@
919 1193 $field_type = self::get_original_field_type( $field );
920 1194
921 1195 $is_multi_value_field = (
922 1196 self::is_checkbox( $field ) ||
923 - $field_type == 'address' ||
1197 + $field_type === 'address' ||
924 1198 self::is_multiple_select( $field )
925 1199 );
926 1200
927 1201 return $is_multi_value_field;
@@ -928,8 +1202,9 @@
928 1202 }
929 1203
930 1204 /**
931 1205 * @since 3.0
1206 + * @param array|object $field
932 1207 * @return string
933 1208 */
934 1209 public static function get_field_type( $field ) {
935 1210 return is_array( $field ) ? $field['type'] : $field->type;
@@ -943,9 +1218,10 @@
943 1218 $field_type = self::get_field_type( $field );
944 1219 $original_type = self::get_option( $field, 'original_type' );
945 1220
946 1221 if ( ! empty( $original_type ) && $original_type != $field_type ) {
947 - $field_type = $original_type; // check the original type for arrays
1222 + // Check the original type for arrays.
1223 + $field_type = $original_type;
948 1224 }
949 1225
950 1226 return $field_type;
951 1227 }
@@ -953,9 +1229,9 @@
953 1229 /**
954 1230 * Check if this is a multiselect dropdown field
955 1231 *
956 1232 * @since 2.0.9
957 - * @return boolean
1233 + * @return bool
958 1234 */
959 1235 public static function is_multiple_select( $field ) {
960 1236 $field_type = self::get_field_type( $field );
961 1237 $is_multiple = self::is_option_true( $field, 'multiple' ) && self::is_field_type( $field, 'select' ) && $field_type !== 'hidden';
@@ -967,63 +1243,104 @@
967 1243 * Check if a field is read only. Read only can be set in the field options,
968 1244 * but disabled with the shortcode options
969 1245 *
970 1246 * @since 2.0.9
1247 + *
1248 + * @param array|object $field
1249 + * @return bool
971 1250 */
972 1251 public static function is_read_only( $field ) {
973 1252 global $frm_vars;
974 -
975 - return ( self::is_option_true( $field, 'read_only' ) && ( ! isset( $frm_vars['readonly'] ) || $frm_vars['readonly'] != 'disabled' ) );
1253 + return self::is_option_true( $field, 'read_only' ) && ( ! isset( $frm_vars['readonly'] ) || $frm_vars['readonly'] !== 'disabled' );
976 1254 }
977 1255
978 1256 /**
979 1257 * @since 2.0.9
1258 + *
1259 + * @param array $field
1260 + * @return bool
980 1261 */
981 1262 public static function is_required( $field ) {
982 - $required = ( $field['required'] != '0' );
983 - $required = apply_filters( 'frm_is_field_required', $required, $field );
1263 + $required = $field['required'] != '0';
984 1264
1265 + /**
1266 + * @param bool $required
1267 + * @param array $field
1268 + */
1269 + $required = (bool) apply_filters( 'frm_is_field_required', $required, $field );
1270 +
985 1271 return $required;
986 1272 }
987 1273
988 1274 /**
989 1275 * @since 2.0.9
1276 + *
1277 + * @param array|object $field
1278 + * @param string $option
1279 + * @return bool
990 1280 */
991 1281 public static function is_option_true( $field, $option ) {
992 1282 if ( is_array( $field ) ) {
993 1283 return self::is_option_true_in_array( $field, $option );
994 - } else {
995 - return self::is_option_true_in_object( $field, $option );
996 1284 }
1285 + return self::is_option_true_in_object( $field, $option );
997 1286 }
998 1287
999 1288 /**
1000 1289 * @since 2.0.9
1290 + *
1291 + * @param array|object $field
1292 + * @param string $option
1293 + * @return bool
1001 1294 */
1002 1295 public static function is_option_empty( $field, $option ) {
1003 1296 if ( is_array( $field ) ) {
1004 1297 return self::is_option_empty_in_array( $field, $option );
1005 - } else {
1006 - return self::is_option_empty_in_object( $field, $option );
1007 1298 }
1299 + return self::is_option_empty_in_object( $field, $option );
1008 1300 }
1009 1301
1302 + /**
1303 + * @param array $field
1304 + * @param string $option
1305 + * @return bool
1306 + */
1010 1307 public static function is_option_true_in_array( $field, $option ) {
1011 - return isset( $field[ $option ] ) && $field[ $option ];
1308 + return ! empty( $field[ $option ] );
1012 1309 }
1013 1310
1311 + /**
1312 + * @param object $field
1313 + * @param string $option
1314 + * @return bool
1315 + */
1014 1316 public static function is_option_true_in_object( $field, $option ) {
1015 1317 return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ];
1016 1318 }
1017 1319
1320 + /**
1321 + * @param array $field
1322 + * @param string $option
1323 + * @return bool
1324 + */
1018 1325 public static function is_option_empty_in_array( $field, $option ) {
1019 - return ! isset( $field[ $option ] ) || empty( $field[ $option ] );
1326 + return empty( $field[ $option ] );
1020 1327 }
1021 1328
1329 + /**
1330 + * @param object $field
1331 + * @param string $option
1332 + * @return bool
1333 + */
1022 1334 public static function is_option_empty_in_object( $field, $option ) {
1023 - return ! isset( $field->field_options[ $option ] ) || empty( $field->field_options[ $option ] );
1335 + return empty( $field->field_options[ $option ] );
1024 1336 }
1025 1337
1338 + /**
1339 + * @param stdClass $field
1340 + * @param string $option
1341 + * @return bool
1342 + */
1026 1343 public static function is_option_value_in_object( $field, $option ) {
1027 1344 return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != '';
1028 1345 }
1029 1346
@@ -1028,8 +1345,12 @@
1028 1345 }
1029 1346
1030 1347 /**
1031 1348 * @since 2.0.18
1349 + *
1350 + * @param array|object $field
1351 + * @param string $option
1352 + * @return mixed
1032 1353 */
1033 1354 public static function get_option( $field, $option ) {
1034 1355 if ( is_array( $field ) ) {
1035 1356 $option = self::get_option_in_array( $field, $option );
@@ -1039,10 +1360,14 @@
1039 1360
1040 1361 return $option;
1041 1362 }
1042 1363
1364 + /**
1365 + * @param array $field
1366 + * @param string $option
1367 + * @return mixed
1368 + */
1043 1369 public static function get_option_in_array( $field, $option ) {
1044 -
1045 1370 if ( isset( $field[ $option ] ) ) {
1046 1371 $this_option = $field[ $option ];
1047 1372 } elseif ( isset( $field['field_options'] ) && is_array( $field['field_options'] ) && isset( $field['field_options'][ $option ] ) ) {
1048 1373 $this_option = $field['field_options'][ $option ];
@@ -1052,8 +1377,13 @@
1052 1377
1053 1378 return $this_option;
1054 1379 }
1055 1380
1381 + /**
1382 + * @param object $field
1383 + * @param string $option
1384 + * @return mixed
1385 + */
1056 1386 public static function get_option_in_object( $field, $option ) {
1057 1387 return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : '';
1058 1388 }
1059 1389
@@ -1058,17 +1388,20 @@
1058 1388 }
1059 1389
1060 1390 /**
1061 1391 * @since 2.0.09
1392 + *
1393 + * @param array|object $field
1394 + * @return bool
1062 1395 */
1063 1396 public static function is_repeating_field( $field ) {
1064 1397 if ( is_array( $field ) ) {
1065 - $is_repeating_field = ( 'divider' == $field['type'] );
1398 + $is_repeating_field = ( 'divider' === $field['type'] );
1066 1399 } else {
1067 - $is_repeating_field = ( 'divider' == $field->type );
1400 + $is_repeating_field = ( 'divider' === $field->type );
1068 1401 }
1069 1402
1070 - return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) );
1403 + return $is_repeating_field && self::is_option_true( $field, 'repeat' );
1071 1404 }
1072 1405
1073 1406 /**
1074 1407 * @param string $key
@@ -1083,9 +1416,9 @@
1083 1416
1084 1417 /**
1085 1418 * @param string $id
1086 1419 *
1087 - * @return null|string
1420 + * @return string|null
1088 1421 */
1089 1422 public static function get_key_by_id( $id ) {
1090 1423 return FrmDb::get_var( 'frm_fields', array( 'id' => $id ), 'field_key' );
1091 1424 }
@@ -1092,9 +1425,9 @@
1092 1425
1093 1426 public static function is_image( $field ) {
1094 1427 $type = self::get_field_type( $field );
1095 1428
1096 - return ( $type == 'url' && self::get_option( $field, 'show_image' ) );
1429 + return ( $type === 'url' && self::get_option( $field, 'show_image' ) );
1097 1430 }
1098 1431
1099 1432 /**
1100 1433 * Check if field is radio or Dynamic radio
@@ -1102,9 +1435,9 @@
1102 1435 * @since 3.0
1103 1436 *
1104 1437 * @param array|object $field
1105 1438 *
1106 - * @return boolean true if field type is radio or Dynamic radio
1439 + * @return bool true if field type is radio or Dynamic radio
1107 1440 */
1108 1441 public static function is_radio( $field ) {
1109 1442 return self::is_field_type( $field, 'radio' );
1110 1443 }
@@ -1115,9 +1448,9 @@
1115 1448 * @since 3.0
1116 1449 *
1117 1450 * @param array|object $field
1118 1451 *
1119 - * @return boolean true if field type is checkbox or Dynamic checkbox
1452 + * @return bool true if field type is checkbox or Dynamic checkbox
1120 1453 */
1121 1454 public static function is_checkbox( $field ) {
1122 1455 return self::is_field_type( $field, 'checkbox' );
1123 1456 }
@@ -1127,11 +1460,11 @@
1127 1460 *
1128 1461 * @since 3.0
1129 1462 *
1130 1463 * @param array|object $field
1131 - * @param string $is_type Options include radio, checkbox, text
1464 + * @param string $is_type Options include radio, checkbox, text.
1132 1465 *
1133 - * @return boolean true if field type is checkbox or Dynamic checkbox
1466 + * @return bool true if field type is checkbox or Dynamic checkbox
1134 1467 */
1135 1468 public static function is_field_type( $field, $is_type ) {
1136 1469 $field_type = self::get_original_field_type( $field );
1137 1470 $data_type = self::get_option( $field, 'data_type' );