PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.16
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.16
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 +432 -133 6.56.16 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,152 +87,148 @@
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',
105 - 'message' => 'Add file uploads to save time and cut down on back-and-forth. Upgrade to Pro to get Upload fields and more.',
97 + 'file' => array(
98 + 'name' => __( 'File Upload', 'formidable' ),
99 + 'icon' => 'frm_icon_font frm_upload_icon',
100 + 'message' => __( 'Add file uploads to save time and cut down on back-and-forth. Upgrade to Pro to get Upload fields and more.', 'formidable' ),
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' => 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' ) . '" />',
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',
139 - 'message' => 'Create relationships between multiple forms. You can link a member to a team, a rating to a product, a comment to a submission, and much more.',
132 + 'data' => array(
133 + 'name' => __( 'Dynamic', 'formidable' ),
134 + 'icon' => 'frm_icon_font frm_sitemap_icon',
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.', 'formidable' ),
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' => 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' ) . '" />',
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' => 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' ) . '" />',
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',
162 - 'message' => 'Get multi-paged forms with progress bars. Did you know you can upgrade to PRO to unlock multi-step forms with more awesome features?',
155 + 'break' => array(
156 + 'name' => __( 'Page Break', 'formidable' ),
157 + 'icon' => 'frm_icon_font frm_page_break_icon',
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?', 'formidable' ),
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',
199 - 'message' => 'Allow visitors to review their responses before a form is submitted. Upgrade to Pro to get Summary fields and more.',
192 + 'summary' => array(
193 + 'name' => __( 'Summary', 'formidable' ),
194 + 'icon' => 'frm_icon_font frm_file_text_icon',
195 + 'message' => __( 'Allow visitors to review their responses before a form is submitted. Upgrade to Pro to get Summary fields and more.', 'formidable' ),
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',
210 - 'message' => 'Streamline workflows and reclaim valuable time with the power of AI. You can effortlessly respond to your visitors in real-time with ChatGPT as your automated assistant. Upgrade to Pro and unlock AI-powered fields.',
202 + 'ai' => array(
203 + 'name' => __( 'AI', 'formidable' ),
204 + 'icon' => 'frm_icon_font frm_eye_icon frm_show_upgrade',
205 + 'addon' => 'ai',
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.', 'formidable' ),
211 207 ),
212 208 'ssa-appointment' => array(
213 209 'name' => __( 'Appointment', 'formidable' ),
214 210 'icon' => 'frm_icon_font frm_calendar_icon frm_show_upgrade',
215 211 'require' => 'Simply Schedule Appointments',
216 - 'message' => 'Appointment fields are an integration with <a href="https://simplyscheduleappointments.com/meet/formidable/">Simply Schedule Appointments</a>. Get started now to schedule appointments directly from your forms.
217 - <img src="' . esc_attr( $images_url ) . 'appointments.png" alt="Scheduling" />',
212 + 'message' => sprintf(
213 + /* translators: %1$s: Link opening HTML, %2$s: Link tag closing */
214 + 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' ),
215 + '<a href="https://simplyscheduleappointments.com/meet/formidable/">',
216 + '</a>'
217 + ) . '<img src="' . esc_url( $images_url ) . 'appointments.png" alt="' . esc_attr__( 'Scheduling', 'formidable' ) . '" />',
218 218 'link' => 'https://simplyscheduleappointments.com/meet/formidable/',
219 219 ),
220 - 'product' => array(
220 + 'product' => array(
221 221 'name' => __( 'Product', 'formidable' ),
222 222 'icon' => 'frm_icon_font frm_product_icon',
223 223 'section' => 'pricing',
224 224 ),
225 - 'quantity' => array(
225 + 'quantity' => array(
226 226 'name' => __( 'Quantity', 'formidable' ),
227 227 'icon' => 'frm_icon_font frm_quantity_icon',
228 228 'section' => 'pricing',
229 229 ),
230 - 'total' => array(
230 + 'total' => array(
231 231 'name' => __( 'Total', 'formidable' ),
232 232 'icon' => 'frm_icon_font frm_total_icon',
233 233 'section' => 'pricing',
234 234 ),
@@ -233,8 +233,21 @@
233 233 'section' => 'pricing',
234 234 ),
235 235 );
236 236
237 + if ( self::include_ranking_fields() ) {
238 + $fields['ranking'] = array(
239 + 'name' => __( 'Ranking', 'formidable' ),
240 + 'icon' => 'frm_icon_font frm_chart_bar_icon frm_show_upgrade',
241 + 'message' => __( 'Now you can effortlessly gather insights, preferences, and opinions by allowing users to rank options.', 'formidable' ),
242 + 'upsell_image' => esc_url( $images_url ) . 'ranking-field.svg',
243 + 'addon' => 'surveys',
244 + 'is_new' => self::field_is_new( 'ranking' ),
245 + );
246 + } else {
247 + unset( $fields['ranking'] );
248 + }
249 +
237 250 if ( ! FrmAppHelper::show_new_feature( 'ai' ) ) {
238 251 unset( $fields['ai'] );
239 252 }
240 253
@@ -247,9 +260,102 @@
247 260 return apply_filters( 'frm_pro_available_fields', $fields );
248 261 }
249 262
250 263 /**
264 + * Check if we should show ranking fields in the builder.
265 + * This is based on the active version coming from our API data.
266 + * If Surveys v1.1 is not released yet, we don't want to display ranking fields yet.
267 + *
268 + * @since 6.8.3
269 + *
270 + * @return bool
271 + */
272 + private static function include_ranking_fields() {
273 + if ( class_exists( 'FrmSurveys\models\fields\Ranking' ) ) {
274 + // Always return true if Ranking fields exist.
275 + return true;
276 + }
277 +
278 + $plugin = 'formidable-surveys/formidable-surveys.php';
279 + $expected_version = '1.1';
280 +
281 + return self::installed_plugin_meets_version( $plugin, $expected_version ) || self::api_meets_version( $plugin, $expected_version );
282 + }
283 +
284 + /**
285 + * @since 6.8.3
286 + *
287 + * @param string $plugin
288 + * @param string $expected_version
289 + * @return bool
290 + */
291 + private static function installed_plugin_meets_version( $plugin, $expected_version ) {
292 + $installed_version = self::get_installed_version( $plugin );
293 + return $installed_version && version_compare( $installed_version, $expected_version, '>=' );
294 + }
295 +
296 + /**
297 + * @since 6.8.3
298 + *
299 + * @param string $plugin
300 + * @return false|string String version. False if the plugin is not installed.
301 + */
302 + private static function get_installed_version( $plugin ) {
303 + if ( ! function_exists( 'get_plugins' ) ) {
304 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
305 + }
306 + $plugins = get_plugins();
307 + if ( isset( $plugins[ $plugin ] ) && ! empty( $plugins[ $plugin ]['Version'] ) ) {
308 + return $plugins[ $plugin ]['Version'];
309 + }
310 + return false;
311 + }
312 +
313 + /**
314 + * @since 6.8.3
315 + *
316 + * @param string $plugin
317 + * @param string $expected_version
318 + * @return bool
319 + */
320 + private static function api_meets_version( $plugin, $expected_version ) {
321 + $api = new FrmFormApi();
322 + $addons = $api->get_api_info();
323 + $matches = wp_list_filter( $addons, array( 'plugin' => $plugin ) );
324 + if ( ! $matches ) {
325 + return false;
326 + }
327 +
328 + $match = reset( $matches );
329 + if ( empty( $match['new_version'] ) ) {
330 + return false;
331 + }
332 +
333 + $api_version = $match['new_version'];
334 + return version_compare( $api_version, $expected_version, '>=' );
335 + }
336 +
337 + /**
338 + * Consider a field new for 90 days after the release date.
339 + *
340 + * @since 6.8.3
341 + *
342 + * @param string $type
343 + * @return bool
344 + */
345 + private static function field_is_new( $type ) {
346 + if ( 'ranking' === $type ) {
347 + $ranking_release_date = '2024-03-12';
348 + $three_months_after_release = gmdate( 'Y-m-d', strtotime( $ranking_release_date . ' + 90 days' ) );
349 + return gmdate( 'Y-m-d' ) < $three_months_after_release;
350 + }
351 + return false;
352 + }
353 +
354 + /**
251 355 * @since 4.0
356 + *
357 + * @return array
252 358 */
253 359 public static function all_field_selection() {
254 360 $pro_field_selection = self::pro_field_selection();
255 361 return array_merge( $pro_field_selection, self::field_selection() );
@@ -259,9 +365,9 @@
259 365 * Create a field.
260 366 *
261 367 * @param array $values
262 368 * @param bool $return
263 - * @return int|false
369 + * @return false|int
264 370 */
265 371 public static function create( $values, $return = true ) {
266 372 global $wpdb, $frm_duplicate_ids;
267 373
@@ -320,8 +426,12 @@
320 426 return $new_id;
321 427 }
322 428
323 429 /**
430 + * Maybe filter HTML in field options data.
431 + * HTML is only filtered when unsafe HTML is disallowed.
432 + * See FrmAppHelper::allow_unfiltered_html.
433 + *
324 434 * @since 5.0.08
325 435 *
326 436 * @param array $options
327 437 * @return array
@@ -326,12 +436,82 @@
326 436 * @param array $options
327 437 * @return array
328 438 */
329 439 private static function maybe_filter_options( $options ) {
330 - return FrmAppHelper::maybe_filter_array( $options, array( 'custom_html' ) );
440 + $options = FrmAppHelper::maybe_filter_array( $options, array( 'custom_html' ) );
441 +
442 + if ( ! empty( $options['custom_html'] ) ) {
443 + $options['custom_html'] = self::maybe_filter_custom_html_input_attributes( $options['custom_html'] );
444 + }
445 +
446 + if ( ! empty( $options['classes'] ) ) {
447 + $options['classes'] = implode( ' ', array_map( 'FrmFormsHelper::sanitize_layout_class', explode( ' ', $options['classes'] ) ) );
448 + }
449 +
450 + return $options;
331 451 }
332 452
333 453 /**
454 + * Prevent users who do not have permission to insert JavaScript attributes in input elements.
455 + * This is triggered when a field is updated.
456 + *
457 + * @since 6.11.2
458 + *
459 + * @param string $html
460 + * @return string
461 + */
462 + private static function maybe_filter_custom_html_input_attributes( $html ) {
463 + if ( FrmAppHelper::allow_unfiltered_html() ) {
464 + return $html;
465 + }
466 +
467 + $pattern = get_shortcode_regex( array( 'input' ) );
468 + return preg_replace_callback(
469 + "/$pattern/",
470 + /**
471 + * @param array $match Shortcode data.
472 + * @return string
473 + */
474 + function ( $match ) {
475 + $attr = shortcode_parse_atts( $match[3] );
476 +
477 + if ( ! is_array( $attr ) ) {
478 + // In old versions of WordPress (older than 6.5), this might not be an array.
479 + return '[input]';
480 + }
481 +
482 + $safe_atts = array();
483 + foreach ( $attr as $attr_key => $att ) {
484 + if ( ! is_numeric( $attr_key ) ) {
485 + // opt=1 without parentheses for example is mapped like 'opt' => 1.
486 + $key = $attr_key;
487 + $value = $att;
488 + } else {
489 + // Some data is mapped like 0 => 'placeholder="Placeholder"'.
490 + $split = explode( '=', $att, 2 );
491 + if ( 2 !== count( $split ) ) {
492 + continue;
493 + }
494 + $key = trim( $split[0] );
495 + $value = trim( $split[1], '"' );
496 + }
497 +
498 + if ( FrmAppHelper::input_key_is_safe( $key, 'update' ) ) {
499 + $safe_atts[ $key ] = $value;
500 + }
501 + }
502 +
503 + if ( ! $safe_atts ) {
504 + return '[input]';
505 + }
506 +
507 + return '[input ' . FrmAppHelper::array_to_html_params( $safe_atts ) . ']';
508 + },
509 + $html
510 + );
511 + }
512 +
513 + /**
334 514 * Process the field duplication.
335 515 *
336 516 * @since 5.0.05
337 517 */
@@ -422,11 +602,16 @@
422 602 $new_id = self::create( $values );
423 603 $frm_duplicate_ids[ $field->id ] = $new_id;
424 604 $frm_duplicate_ids[ $field->field_key ] = $new_id;
425 605 unset( $field );
426 - }
606 + }//end foreach
427 607 }
428 608
609 + /**
610 + * @param int|string $id
611 + * @param array $values
612 + * @return false|int
613 + */
429 614 public static function update( $id, $values ) {
430 615 global $wpdb;
431 616
432 617 $id = absint( $id );
@@ -442,10 +627,22 @@
442 627
443 628 self::preserve_format_option_backslashes( $values );
444 629
445 630 if ( isset( $values['type'] ) ) {
446 - $values = apply_filters( 'frm_clean_' . $values['type'] . '_field_options_before_update', $values );
631 + if ( 'dropdown' === $values['type'] ) {
632 + // To avoid conflicts with security plugins the value "dropdown" is sent for select fields.
633 + // This is because "select" gets matched for SQL injection attempts.
634 + $values['type'] = 'select';
635 + }
447 636
637 + /**
638 + * @since 6.9 The Field ID param was added.
639 + *
640 + * @param array $values
641 + * @param int $id Field ID.
642 + */
643 + $values = apply_filters( 'frm_clean_' . $values['type'] . '_field_options_before_update', $values, $id );
644 +
448 645 if ( $values['type'] === 'hidden' && isset( $values['field_options'] ) && isset( $values['field_options']['clear_on_focus'] ) ) {
449 646 // don't keep the old placeholder setting for hidden fields
450 647 $values['field_options']['clear_on_focus'] = 0;
451 648 }
@@ -492,9 +689,9 @@
492 689 * Keep backslashes in the phone format option
493 690 *
494 691 * @since 2.0.8
495 692 *
496 - * @param $values array - pass by reference
693 + * @param array $values Pass by reference.
497 694 */
498 695 private static function preserve_format_option_backslashes( &$values ) {
499 696 if ( isset( $values['field_options']['format'] ) ) {
500 697 $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
@@ -538,8 +735,11 @@
538 735 }
539 736
540 737 /**
541 738 * If $field is numeric, get the field object
739 + *
740 + * @param int|object|string $field
741 + * @return void
542 742 */
543 743 public static function maybe_get_field( &$field ) {
544 744 if ( ! is_object( $field ) ) {
545 745 $field = self::getOne( $field );
@@ -546,10 +746,10 @@
546 746 }
547 747 }
548 748
549 749 /**
550 - * @param string|int $id The field id or key.
551 - * @param bool $filter When true, run the frm_field filter.
750 + * @param int|string $id The field id or key.
751 + * @param bool $filter When true, run the frm_field filter.
552 752 */
553 753 public static function getOne( $id, $filter = false ) {
554 754 if ( empty( $id ) ) {
555 755 return null;
@@ -595,10 +795,10 @@
595 795
596 796 /**
597 797 * Get the field type by key or id
598 798 *
599 - * @param int|string The field id or key
600 - * @param mixed $col The name of the column in the fields database table
799 + * @param int|string $id The field id or key.
800 + * @param mixed $col The name of the column in the fields database table.
601 801 */
602 802 public static function get_type( $id, $col = 'type' ) {
603 803 $field = FrmDb::check_cache( $id, 'frm_field' );
604 804 if ( $field ) {
@@ -614,8 +814,14 @@
614 814
615 815 return $type;
616 816 }
617 817
818 + /**
819 + * @param int|string $form_id
820 + * @param string $type
821 + * @param int|string $limit
822 + * @param string $inc_sub
823 + */
618 824 public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) {
619 825 if ( ! $form_id ) {
620 826 return array();
621 827 }
@@ -635,9 +841,9 @@
635 841 continue;
636 842 }
637 843
638 844 $fields[ $result->id ] = $result;
639 - $count ++;
845 + ++$count;
640 846 if ( $limit == 1 ) {
641 847 $fields = $result;
642 848 break;
643 849 }
@@ -649,9 +855,9 @@
649 855 unset( $result );
650 856 }
651 857
652 858 return wp_unslash( $fields );
653 - }
859 + }//end if
654 860
655 861 self::$use_cache = false;
656 862
657 863 $where = array(
@@ -665,8 +871,15 @@
665 871
666 872 return $results;
667 873 }
668 874
875 + /**
876 + * @param int|string $form_id
877 + * @param int|string $limit
878 + * @param string $inc_embed
879 + * @param string $inc_repeat
880 + * @return array
881 + */
669 882 public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) {
670 883 if ( ! (int) $form_id ) {
671 884 return array();
672 885 }
@@ -679,9 +892,9 @@
679 892
680 893 $fields = array();
681 894 $count = 0;
682 895 foreach ( $results as $result ) {
683 - $count ++;
896 + ++$count;
684 897 $fields[ $result->id ] = $result;
685 898 if ( ! empty( $limit ) && $count >= $limit ) {
686 899 break;
687 900 }
@@ -710,12 +923,12 @@
710 923 /**
711 924 * If repeating fields should be included, adjust $where accordingly
712 925 *
713 926 * @param string $inc_repeat
714 - * @param array $where - pass by reference
927 + * @param array $where Pass by reference.
715 928 */
716 929 private static function maybe_include_repeating_fields( $inc_repeat, &$where ) {
717 - if ( $inc_repeat == 'include' ) {
930 + if ( $inc_repeat === 'include' ) {
718 931 $form_id = $where['fi.form_id'];
719 932 $where[] = array(
720 933 'or' => 1,
721 934 'fi.form_id' => $form_id,
@@ -730,9 +943,9 @@
730 943 if ( 'include' != $inc_embed || $no_sub_forms ) {
731 944 return;
732 945 }
733 946
734 - $form_fields = $results;
947 + $form_fields = $results;
735 948 $should_get_subforms = ( $type !== 'all' && $type !== 'form' && ! empty( $form_id ) );
736 949 if ( $should_get_subforms ) {
737 950 $form_fields = self::get_all_types_in_form( $form_id, 'form' );
738 951 }
@@ -742,9 +955,9 @@
742 955 if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) {
743 956 continue;
744 957 }
745 958
746 - if ( $type == 'all' ) {
959 + if ( $type === 'all' ) {
747 960 $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
748 961 } else {
749 962 $sub_fields = self::get_all_types_in_form( $field->field_options['form_select'], $type );
750 963 }
@@ -749,9 +962,9 @@
749 962 $sub_fields = self::get_all_types_in_form( $field->field_options['form_select'], $type );
750 963 }
751 964
752 965 if ( ! empty( $sub_fields ) ) {
753 - $index = $k + $index_offset;
966 + $index = $k + $index_offset;
754 967 $index_offset += count( $sub_fields );
755 968 array_splice( $results, $index, 0, $sub_fields );
756 969 }
757 970 unset( $field, $sub_fields );
@@ -791,9 +1004,9 @@
791 1004
792 1005 $limit = FrmDb::esc_limit( $limit );
793 1006
794 1007 $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';
1008 + $query_type = $limit === ' LIMIT 1' || $limit == 1 ? 'row' : 'results';
796 1009
797 1010 if ( is_array( $where ) ) {
798 1011 $args = array(
799 1012 'order_by' => $order_by,
@@ -803,9 +1016,9 @@
803 1016 } else {
804 1017 // if the query is not an array, then it has already been prepared
805 1018 $query .= FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
806 1019
807 - $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
1020 + $function_name = $query_type === 'row' ? 'get_row' : 'get_results';
808 1021 $results = $wpdb->$function_name( $query );
809 1022 }
810 1023 unset( $where );
811 1024
@@ -821,8 +1034,10 @@
821 1034 */
822 1035 private static function format_field_results( &$results ) {
823 1036 if ( is_array( $results ) ) {
824 1037 foreach ( $results as $r_key => $result ) {
1038 + self::add_slashes_to_format_before_setting_field_cache( $result );
1039 +
825 1040 FrmDb::set_cache( $result->id, $result, 'frm_field' );
826 1041 FrmDb::set_cache( $result->field_key, $result, 'frm_field' );
827 1042
828 1043 self::prepare_options( $result );
@@ -840,8 +1055,26 @@
840 1055 }
841 1056 }
842 1057
843 1058 /**
1059 + * When $result->field_options is an array and not a serialized string there is only a single backslash.
1060 + * Cached results are unslashed in FrmField::getAll, so we need to make sure that the cached object has an extra backslash.
1061 + * Otherwise the backslash is stripped away on load.
1062 + *
1063 + * @since 6.15
1064 + *
1065 + * @param stdClass $result
1066 + * @return void
1067 + */
1068 + private static function add_slashes_to_format_before_setting_field_cache( $result ) {
1069 + if ( ! isset( $result->field_options ) || ! is_array( $result->field_options ) || empty( $result->field_options['format'] ) ) {
1070 + return;
1071 + }
1072 +
1073 + $result->field_options['format'] = addslashes( $result->field_options['format'] );
1074 + }
1075 +
1076 + /**
844 1077 * Unserialize all the serialized field data
845 1078 *
846 1079 * @since 2.0
847 1080 */
@@ -857,9 +1090,9 @@
857 1090 }
858 1091 }
859 1092
860 1093 /**
861 - * If a form has too many fields, thay won't all save into a single transient.
1094 + * If a form has too many fields, they won't all save into a single transient.
862 1095 * We'll break them into groups of 200
863 1096 *
864 1097 * @since 2.0.1
865 1098 */
@@ -883,9 +1116,9 @@
883 1116 $fields = array_merge( $fields, $next_fields );
884 1117
885 1118 if ( count( $next_fields ) >= self::$transient_size ) {
886 1119 // if this transient is full, check for another
887 - $next ++;
1120 + ++$next;
888 1121 self::get_next_transient( $fields, $base_name, $next );
889 1122 }
890 1123 }
891 1124 }
@@ -911,18 +1144,25 @@
911 1144
912 1145 return;
913 1146 }
914 1147
915 - $next ++;
1148 + ++$next;
916 1149 }
917 1150 }
918 1151
1152 + /**
1153 + * @param string $type
1154 + * @return bool
1155 + */
919 1156 public static function is_no_save_field( $type ) {
920 - return in_array( $type, self::no_save_fields() );
1157 + return in_array( $type, self::no_save_fields(), true );
921 1158 }
922 1159
1160 + /**
1161 + * @return string[]
1162 + */
923 1163 public static function no_save_fields() {
924 - return array( 'divider', 'end_divider', 'captcha', 'break', 'html', 'form', 'summary' );
1164 + return array( 'divider', 'end_divider', 'captcha', 'break', 'html', 'form', 'summary', FrmSubmitHelper::FIELD_TYPE );
925 1165 }
926 1166
927 1167 /**
928 1168 * Check if this field can hold an array of values
@@ -930,9 +1170,9 @@
930 1170 * @since 2.0.9
931 1171 *
932 1172 * @param array|object $field
933 1173 *
934 - * @return boolean
1174 + * @return bool
935 1175 */
936 1176 public static function is_field_with_multiple_values( $field ) {
937 1177 if ( ! $field ) {
938 1178 return false;
@@ -941,9 +1181,9 @@
941 1181 $field_type = self::get_original_field_type( $field );
942 1182
943 1183 $is_multi_value_field = (
944 1184 self::is_checkbox( $field ) ||
945 - $field_type == 'address' ||
1185 + $field_type === 'address' ||
946 1186 self::is_multiple_select( $field )
947 1187 );
948 1188
949 1189 return $is_multi_value_field;
@@ -950,8 +1190,9 @@
950 1190 }
951 1191
952 1192 /**
953 1193 * @since 3.0
1194 + * @param array|object $field
954 1195 * @return string
955 1196 */
956 1197 public static function get_field_type( $field ) {
957 1198 return is_array( $field ) ? $field['type'] : $field->type;
@@ -965,9 +1206,10 @@
965 1206 $field_type = self::get_field_type( $field );
966 1207 $original_type = self::get_option( $field, 'original_type' );
967 1208
968 1209 if ( ! empty( $original_type ) && $original_type != $field_type ) {
969 - $field_type = $original_type; // check the original type for arrays
1210 + // Check the original type for arrays.
1211 + $field_type = $original_type;
970 1212 }
971 1213
972 1214 return $field_type;
973 1215 }
@@ -975,9 +1217,9 @@
975 1217 /**
976 1218 * Check if this is a multiselect dropdown field
977 1219 *
978 1220 * @since 2.0.9
979 - * @return boolean
1221 + * @return bool
980 1222 */
981 1223 public static function is_multiple_select( $field ) {
982 1224 $field_type = self::get_field_type( $field );
983 1225 $is_multiple = self::is_option_true( $field, 'multiple' ) && self::is_field_type( $field, 'select' ) && $field_type !== 'hidden';
@@ -989,63 +1231,104 @@
989 1231 * Check if a field is read only. Read only can be set in the field options,
990 1232 * but disabled with the shortcode options
991 1233 *
992 1234 * @since 2.0.9
1235 + *
1236 + * @param array|object $field
1237 + * @return bool
993 1238 */
994 1239 public static function is_read_only( $field ) {
995 1240 global $frm_vars;
996 -
997 - return ( self::is_option_true( $field, 'read_only' ) && ( ! isset( $frm_vars['readonly'] ) || $frm_vars['readonly'] != 'disabled' ) );
1241 + return self::is_option_true( $field, 'read_only' ) && ( ! isset( $frm_vars['readonly'] ) || $frm_vars['readonly'] !== 'disabled' );
998 1242 }
999 1243
1000 1244 /**
1001 1245 * @since 2.0.9
1246 + *
1247 + * @param array $field
1248 + * @return bool
1002 1249 */
1003 1250 public static function is_required( $field ) {
1004 - $required = ( $field['required'] != '0' );
1005 - $required = apply_filters( 'frm_is_field_required', $required, $field );
1251 + $required = $field['required'] != '0';
1006 1252
1253 + /**
1254 + * @param bool $required
1255 + * @param array $field
1256 + */
1257 + $required = (bool) apply_filters( 'frm_is_field_required', $required, $field );
1258 +
1007 1259 return $required;
1008 1260 }
1009 1261
1010 1262 /**
1011 1263 * @since 2.0.9
1264 + *
1265 + * @param array|object $field
1266 + * @param string $option
1267 + * @return bool
1012 1268 */
1013 1269 public static function is_option_true( $field, $option ) {
1014 1270 if ( is_array( $field ) ) {
1015 1271 return self::is_option_true_in_array( $field, $option );
1016 - } else {
1017 - return self::is_option_true_in_object( $field, $option );
1018 1272 }
1273 + return self::is_option_true_in_object( $field, $option );
1019 1274 }
1020 1275
1021 1276 /**
1022 1277 * @since 2.0.9
1278 + *
1279 + * @param array|object $field
1280 + * @param string $option
1281 + * @return bool
1023 1282 */
1024 1283 public static function is_option_empty( $field, $option ) {
1025 1284 if ( is_array( $field ) ) {
1026 1285 return self::is_option_empty_in_array( $field, $option );
1027 - } else {
1028 - return self::is_option_empty_in_object( $field, $option );
1029 1286 }
1287 + return self::is_option_empty_in_object( $field, $option );
1030 1288 }
1031 1289
1290 + /**
1291 + * @param array $field
1292 + * @param string $option
1293 + * @return bool
1294 + */
1032 1295 public static function is_option_true_in_array( $field, $option ) {
1033 - return isset( $field[ $option ] ) && $field[ $option ];
1296 + return ! empty( $field[ $option ] );
1034 1297 }
1035 1298
1299 + /**
1300 + * @param object $field
1301 + * @param string $option
1302 + * @return bool
1303 + */
1036 1304 public static function is_option_true_in_object( $field, $option ) {
1037 1305 return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ];
1038 1306 }
1039 1307
1308 + /**
1309 + * @param array $field
1310 + * @param string $option
1311 + * @return bool
1312 + */
1040 1313 public static function is_option_empty_in_array( $field, $option ) {
1041 - return ! isset( $field[ $option ] ) || empty( $field[ $option ] );
1314 + return empty( $field[ $option ] );
1042 1315 }
1043 1316
1317 + /**
1318 + * @param object $field
1319 + * @param string $option
1320 + * @return bool
1321 + */
1044 1322 public static function is_option_empty_in_object( $field, $option ) {
1045 - return ! isset( $field->field_options[ $option ] ) || empty( $field->field_options[ $option ] );
1323 + return empty( $field->field_options[ $option ] );
1046 1324 }
1047 1325
1326 + /**
1327 + * @param stdClass $field
1328 + * @param string $option
1329 + * @return bool
1330 + */
1048 1331 public static function is_option_value_in_object( $field, $option ) {
1049 1332 return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != '';
1050 1333 }
1051 1334
@@ -1050,8 +1333,12 @@
1050 1333 }
1051 1334
1052 1335 /**
1053 1336 * @since 2.0.18
1337 + *
1338 + * @param array|object $field
1339 + * @param string $option
1340 + * @return mixed
1054 1341 */
1055 1342 public static function get_option( $field, $option ) {
1056 1343 if ( is_array( $field ) ) {
1057 1344 $option = self::get_option_in_array( $field, $option );
@@ -1061,10 +1348,14 @@
1061 1348
1062 1349 return $option;
1063 1350 }
1064 1351
1352 + /**
1353 + * @param array $field
1354 + * @param string $option
1355 + * @return mixed
1356 + */
1065 1357 public static function get_option_in_array( $field, $option ) {
1066 -
1067 1358 if ( isset( $field[ $option ] ) ) {
1068 1359 $this_option = $field[ $option ];
1069 1360 } elseif ( isset( $field['field_options'] ) && is_array( $field['field_options'] ) && isset( $field['field_options'][ $option ] ) ) {
1070 1361 $this_option = $field['field_options'][ $option ];
@@ -1074,8 +1365,13 @@
1074 1365
1075 1366 return $this_option;
1076 1367 }
1077 1368
1369 + /**
1370 + * @param object $field
1371 + * @param string $option
1372 + * @return mixed
1373 + */
1078 1374 public static function get_option_in_object( $field, $option ) {
1079 1375 return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : '';
1080 1376 }
1081 1377
@@ -1080,17 +1376,20 @@
1080 1376 }
1081 1377
1082 1378 /**
1083 1379 * @since 2.0.09
1380 + *
1381 + * @param array|object $field
1382 + * @return bool
1084 1383 */
1085 1384 public static function is_repeating_field( $field ) {
1086 1385 if ( is_array( $field ) ) {
1087 - $is_repeating_field = ( 'divider' == $field['type'] );
1386 + $is_repeating_field = ( 'divider' === $field['type'] );
1088 1387 } else {
1089 - $is_repeating_field = ( 'divider' == $field->type );
1388 + $is_repeating_field = ( 'divider' === $field->type );
1090 1389 }
1091 1390
1092 - return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) );
1391 + return $is_repeating_field && self::is_option_true( $field, 'repeat' );
1093 1392 }
1094 1393
1095 1394 /**
1096 1395 * @param string $key
@@ -1105,9 +1404,9 @@
1105 1404
1106 1405 /**
1107 1406 * @param string $id
1108 1407 *
1109 - * @return null|string
1408 + * @return string|null
1110 1409 */
1111 1410 public static function get_key_by_id( $id ) {
1112 1411 return FrmDb::get_var( 'frm_fields', array( 'id' => $id ), 'field_key' );
1113 1412 }
@@ -1114,9 +1413,9 @@
1114 1413
1115 1414 public static function is_image( $field ) {
1116 1415 $type = self::get_field_type( $field );
1117 1416
1118 - return ( $type == 'url' && self::get_option( $field, 'show_image' ) );
1417 + return ( $type === 'url' && self::get_option( $field, 'show_image' ) );
1119 1418 }
1120 1419
1121 1420 /**
1122 1421 * Check if field is radio or Dynamic radio
@@ -1124,9 +1423,9 @@
1124 1423 * @since 3.0
1125 1424 *
1126 1425 * @param array|object $field
1127 1426 *
1128 - * @return boolean true if field type is radio or Dynamic radio
1427 + * @return bool true if field type is radio or Dynamic radio
1129 1428 */
1130 1429 public static function is_radio( $field ) {
1131 1430 return self::is_field_type( $field, 'radio' );
1132 1431 }
@@ -1137,9 +1436,9 @@
1137 1436 * @since 3.0
1138 1437 *
1139 1438 * @param array|object $field
1140 1439 *
1141 - * @return boolean true if field type is checkbox or Dynamic checkbox
1440 + * @return bool true if field type is checkbox or Dynamic checkbox
1142 1441 */
1143 1442 public static function is_checkbox( $field ) {
1144 1443 return self::is_field_type( $field, 'checkbox' );
1145 1444 }
@@ -1149,11 +1448,11 @@
1149 1448 *
1150 1449 * @since 3.0
1151 1450 *
1152 1451 * @param array|object $field
1153 - * @param string $is_type Options include radio, checkbox, text
1452 + * @param string $is_type Options include radio, checkbox, text.
1154 1453 *
1155 - * @return boolean true if field type is checkbox or Dynamic checkbox
1454 + * @return bool true if field type is checkbox or Dynamic checkbox
1156 1455 */
1157 1456 public static function is_field_type( $field, $is_type ) {
1158 1457 $field_type = self::get_original_field_type( $field );
1159 1458 $data_type = self::get_option( $field, 'data_type' );