PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.14
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.14
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 +408 -133 6.56.14 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,78 @@
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 + return $options;
331 447 }
332 448
333 449 /**
450 + * Prevent users who do not have permission to insert JavaScript attributes in input elements.
451 + * This is triggered when a field is updated.
452 + *
453 + * @since 6.11.2
454 + *
455 + * @param string $html
456 + * @return string
457 + */
458 + private static function maybe_filter_custom_html_input_attributes( $html ) {
459 + if ( FrmAppHelper::allow_unfiltered_html() ) {
460 + return $html;
461 + }
462 +
463 + $pattern = get_shortcode_regex( array( 'input' ) );
464 + return preg_replace_callback(
465 + "/$pattern/",
466 + /**
467 + * @param array $match Shortcode data.
468 + * @return string
469 + */
470 + function ( $match ) {
471 + $attr = shortcode_parse_atts( $match[3] );
472 +
473 + if ( ! is_array( $attr ) ) {
474 + // In old versions of WordPress (older than 6.5), this might not be an array.
475 + return '[input]';
476 + }
477 +
478 + $safe_atts = array();
479 + foreach ( $attr as $attr_key => $att ) {
480 + if ( ! is_numeric( $attr_key ) ) {
481 + // opt=1 without parentheses for example is mapped like 'opt' => 1.
482 + $key = $attr_key;
483 + $value = $att;
484 + } else {
485 + // Some data is mapped like 0 => 'placeholder="Placeholder"'.
486 + $split = explode( '=', $att, 2 );
487 + if ( 2 !== count( $split ) ) {
488 + continue;
489 + }
490 + $key = trim( $split[0] );
491 + $value = trim( $split[1], '"' );
492 + }
493 +
494 + if ( FrmAppHelper::input_key_is_safe( $key, 'update' ) ) {
495 + $safe_atts[ $key ] = $value;
496 + }
497 + }
498 +
499 + if ( ! $safe_atts ) {
500 + return '[input]';
501 + }
502 +
503 + return '[input ' . FrmAppHelper::array_to_html_params( $safe_atts ) . ']';
504 + },
505 + $html
506 + );
507 + }
508 +
509 + /**
334 510 * Process the field duplication.
335 511 *
336 512 * @since 5.0.05
337 513 */
@@ -422,11 +598,16 @@
422 598 $new_id = self::create( $values );
423 599 $frm_duplicate_ids[ $field->id ] = $new_id;
424 600 $frm_duplicate_ids[ $field->field_key ] = $new_id;
425 601 unset( $field );
426 - }
602 + }//end foreach
427 603 }
428 604
605 + /**
606 + * @param int|string $id
607 + * @param array $values
608 + * @return false|int
609 + */
429 610 public static function update( $id, $values ) {
430 611 global $wpdb;
431 612
432 613 $id = absint( $id );
@@ -442,10 +623,22 @@
442 623
443 624 self::preserve_format_option_backslashes( $values );
444 625
445 626 if ( isset( $values['type'] ) ) {
446 - $values = apply_filters( 'frm_clean_' . $values['type'] . '_field_options_before_update', $values );
627 + if ( 'dropdown' === $values['type'] ) {
628 + // To avoid conflicts with security plugins the value "dropdown" is sent for select fields.
629 + // This is because "select" gets matched for SQL injection attempts.
630 + $values['type'] = 'select';
631 + }
447 632
633 + /**
634 + * @since 6.9 The Field ID param was added.
635 + *
636 + * @param array $values
637 + * @param int $id Field ID.
638 + */
639 + $values = apply_filters( 'frm_clean_' . $values['type'] . '_field_options_before_update', $values, $id );
640 +
448 641 if ( $values['type'] === 'hidden' && isset( $values['field_options'] ) && isset( $values['field_options']['clear_on_focus'] ) ) {
449 642 // don't keep the old placeholder setting for hidden fields
450 643 $values['field_options']['clear_on_focus'] = 0;
451 644 }
@@ -492,9 +685,9 @@
492 685 * Keep backslashes in the phone format option
493 686 *
494 687 * @since 2.0.8
495 688 *
496 - * @param $values array - pass by reference
689 + * @param array $values Pass by reference.
497 690 */
498 691 private static function preserve_format_option_backslashes( &$values ) {
499 692 if ( isset( $values['field_options']['format'] ) ) {
500 693 $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
@@ -538,8 +731,11 @@
538 731 }
539 732
540 733 /**
541 734 * If $field is numeric, get the field object
735 + *
736 + * @param int|object|string $field
737 + * @return void
542 738 */
543 739 public static function maybe_get_field( &$field ) {
544 740 if ( ! is_object( $field ) ) {
545 741 $field = self::getOne( $field );
@@ -546,10 +742,10 @@
546 742 }
547 743 }
548 744
549 745 /**
550 - * @param string|int $id The field id or key.
551 - * @param bool $filter When true, run the frm_field filter.
746 + * @param int|string $id The field id or key.
747 + * @param bool $filter When true, run the frm_field filter.
552 748 */
553 749 public static function getOne( $id, $filter = false ) {
554 750 if ( empty( $id ) ) {
555 751 return null;
@@ -595,10 +791,10 @@
595 791
596 792 /**
597 793 * Get the field type by key or id
598 794 *
599 - * @param int|string The field id or key
600 - * @param mixed $col The name of the column in the fields database table
795 + * @param int|string $id The field id or key.
796 + * @param mixed $col The name of the column in the fields database table.
601 797 */
602 798 public static function get_type( $id, $col = 'type' ) {
603 799 $field = FrmDb::check_cache( $id, 'frm_field' );
604 800 if ( $field ) {
@@ -614,8 +810,14 @@
614 810
615 811 return $type;
616 812 }
617 813
814 + /**
815 + * @param int|string $form_id
816 + * @param string $type
817 + * @param int|string $limit
818 + * @param string $inc_sub
819 + */
618 820 public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) {
619 821 if ( ! $form_id ) {
620 822 return array();
621 823 }
@@ -635,9 +837,9 @@
635 837 continue;
636 838 }
637 839
638 840 $fields[ $result->id ] = $result;
639 - $count ++;
841 + ++$count;
640 842 if ( $limit == 1 ) {
641 843 $fields = $result;
642 844 break;
643 845 }
@@ -649,9 +851,9 @@
649 851 unset( $result );
650 852 }
651 853
652 854 return wp_unslash( $fields );
653 - }
855 + }//end if
654 856
655 857 self::$use_cache = false;
656 858
657 859 $where = array(
@@ -665,8 +867,15 @@
665 867
666 868 return $results;
667 869 }
668 870
871 + /**
872 + * @param int|string $form_id
873 + * @param int|string $limit
874 + * @param string $inc_embed
875 + * @param string $inc_repeat
876 + * @return array
877 + */
669 878 public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) {
670 879 if ( ! (int) $form_id ) {
671 880 return array();
672 881 }
@@ -679,9 +888,9 @@
679 888
680 889 $fields = array();
681 890 $count = 0;
682 891 foreach ( $results as $result ) {
683 - $count ++;
892 + ++$count;
684 893 $fields[ $result->id ] = $result;
685 894 if ( ! empty( $limit ) && $count >= $limit ) {
686 895 break;
687 896 }
@@ -710,12 +919,12 @@
710 919 /**
711 920 * If repeating fields should be included, adjust $where accordingly
712 921 *
713 922 * @param string $inc_repeat
714 - * @param array $where - pass by reference
923 + * @param array $where Pass by reference.
715 924 */
716 925 private static function maybe_include_repeating_fields( $inc_repeat, &$where ) {
717 - if ( $inc_repeat == 'include' ) {
926 + if ( $inc_repeat === 'include' ) {
718 927 $form_id = $where['fi.form_id'];
719 928 $where[] = array(
720 929 'or' => 1,
721 930 'fi.form_id' => $form_id,
@@ -730,9 +939,9 @@
730 939 if ( 'include' != $inc_embed || $no_sub_forms ) {
731 940 return;
732 941 }
733 942
734 - $form_fields = $results;
943 + $form_fields = $results;
735 944 $should_get_subforms = ( $type !== 'all' && $type !== 'form' && ! empty( $form_id ) );
736 945 if ( $should_get_subforms ) {
737 946 $form_fields = self::get_all_types_in_form( $form_id, 'form' );
738 947 }
@@ -742,9 +951,9 @@
742 951 if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) {
743 952 continue;
744 953 }
745 954
746 - if ( $type == 'all' ) {
955 + if ( $type === 'all' ) {
747 956 $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
748 957 } else {
749 958 $sub_fields = self::get_all_types_in_form( $field->field_options['form_select'], $type );
750 959 }
@@ -749,9 +958,9 @@
749 958 $sub_fields = self::get_all_types_in_form( $field->field_options['form_select'], $type );
750 959 }
751 960
752 961 if ( ! empty( $sub_fields ) ) {
753 - $index = $k + $index_offset;
962 + $index = $k + $index_offset;
754 963 $index_offset += count( $sub_fields );
755 964 array_splice( $results, $index, 0, $sub_fields );
756 965 }
757 966 unset( $field, $sub_fields );
@@ -791,9 +1000,9 @@
791 1000
792 1001 $limit = FrmDb::esc_limit( $limit );
793 1002
794 1003 $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';
1004 + $query_type = $limit === ' LIMIT 1' || $limit == 1 ? 'row' : 'results';
796 1005
797 1006 if ( is_array( $where ) ) {
798 1007 $args = array(
799 1008 'order_by' => $order_by,
@@ -803,9 +1012,9 @@
803 1012 } else {
804 1013 // if the query is not an array, then it has already been prepared
805 1014 $query .= FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
806 1015
807 - $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
1016 + $function_name = $query_type === 'row' ? 'get_row' : 'get_results';
808 1017 $results = $wpdb->$function_name( $query );
809 1018 }
810 1019 unset( $where );
811 1020
@@ -857,9 +1066,9 @@
857 1066 }
858 1067 }
859 1068
860 1069 /**
861 - * If a form has too many fields, thay won't all save into a single transient.
1070 + * If a form has too many fields, they won't all save into a single transient.
862 1071 * We'll break them into groups of 200
863 1072 *
864 1073 * @since 2.0.1
865 1074 */
@@ -883,9 +1092,9 @@
883 1092 $fields = array_merge( $fields, $next_fields );
884 1093
885 1094 if ( count( $next_fields ) >= self::$transient_size ) {
886 1095 // if this transient is full, check for another
887 - $next ++;
1096 + ++$next;
888 1097 self::get_next_transient( $fields, $base_name, $next );
889 1098 }
890 1099 }
891 1100 }
@@ -911,18 +1120,25 @@
911 1120
912 1121 return;
913 1122 }
914 1123
915 - $next ++;
1124 + ++$next;
916 1125 }
917 1126 }
918 1127
1128 + /**
1129 + * @param string $type
1130 + * @return bool
1131 + */
919 1132 public static function is_no_save_field( $type ) {
920 - return in_array( $type, self::no_save_fields() );
1133 + return in_array( $type, self::no_save_fields(), true );
921 1134 }
922 1135
1136 + /**
1137 + * @return string[]
1138 + */
923 1139 public static function no_save_fields() {
924 - return array( 'divider', 'end_divider', 'captcha', 'break', 'html', 'form', 'summary' );
1140 + return array( 'divider', 'end_divider', 'captcha', 'break', 'html', 'form', 'summary', FrmSubmitHelper::FIELD_TYPE );
925 1141 }
926 1142
927 1143 /**
928 1144 * Check if this field can hold an array of values
@@ -930,9 +1146,9 @@
930 1146 * @since 2.0.9
931 1147 *
932 1148 * @param array|object $field
933 1149 *
934 - * @return boolean
1150 + * @return bool
935 1151 */
936 1152 public static function is_field_with_multiple_values( $field ) {
937 1153 if ( ! $field ) {
938 1154 return false;
@@ -941,9 +1157,9 @@
941 1157 $field_type = self::get_original_field_type( $field );
942 1158
943 1159 $is_multi_value_field = (
944 1160 self::is_checkbox( $field ) ||
945 - $field_type == 'address' ||
1161 + $field_type === 'address' ||
946 1162 self::is_multiple_select( $field )
947 1163 );
948 1164
949 1165 return $is_multi_value_field;
@@ -950,8 +1166,9 @@
950 1166 }
951 1167
952 1168 /**
953 1169 * @since 3.0
1170 + * @param array|object $field
954 1171 * @return string
955 1172 */
956 1173 public static function get_field_type( $field ) {
957 1174 return is_array( $field ) ? $field['type'] : $field->type;
@@ -965,9 +1182,10 @@
965 1182 $field_type = self::get_field_type( $field );
966 1183 $original_type = self::get_option( $field, 'original_type' );
967 1184
968 1185 if ( ! empty( $original_type ) && $original_type != $field_type ) {
969 - $field_type = $original_type; // check the original type for arrays
1186 + // Check the original type for arrays.
1187 + $field_type = $original_type;
970 1188 }
971 1189
972 1190 return $field_type;
973 1191 }
@@ -975,9 +1193,9 @@
975 1193 /**
976 1194 * Check if this is a multiselect dropdown field
977 1195 *
978 1196 * @since 2.0.9
979 - * @return boolean
1197 + * @return bool
980 1198 */
981 1199 public static function is_multiple_select( $field ) {
982 1200 $field_type = self::get_field_type( $field );
983 1201 $is_multiple = self::is_option_true( $field, 'multiple' ) && self::is_field_type( $field, 'select' ) && $field_type !== 'hidden';
@@ -989,63 +1207,104 @@
989 1207 * Check if a field is read only. Read only can be set in the field options,
990 1208 * but disabled with the shortcode options
991 1209 *
992 1210 * @since 2.0.9
1211 + *
1212 + * @param array|object $field
1213 + * @return bool
993 1214 */
994 1215 public static function is_read_only( $field ) {
995 1216 global $frm_vars;
996 -
997 - return ( self::is_option_true( $field, 'read_only' ) && ( ! isset( $frm_vars['readonly'] ) || $frm_vars['readonly'] != 'disabled' ) );
1217 + return self::is_option_true( $field, 'read_only' ) && ( ! isset( $frm_vars['readonly'] ) || $frm_vars['readonly'] !== 'disabled' );
998 1218 }
999 1219
1000 1220 /**
1001 1221 * @since 2.0.9
1222 + *
1223 + * @param array $field
1224 + * @return bool
1002 1225 */
1003 1226 public static function is_required( $field ) {
1004 - $required = ( $field['required'] != '0' );
1005 - $required = apply_filters( 'frm_is_field_required', $required, $field );
1227 + $required = $field['required'] != '0';
1006 1228
1229 + /**
1230 + * @param bool $required
1231 + * @param array $field
1232 + */
1233 + $required = (bool) apply_filters( 'frm_is_field_required', $required, $field );
1234 +
1007 1235 return $required;
1008 1236 }
1009 1237
1010 1238 /**
1011 1239 * @since 2.0.9
1240 + *
1241 + * @param array|object $field
1242 + * @param string $option
1243 + * @return bool
1012 1244 */
1013 1245 public static function is_option_true( $field, $option ) {
1014 1246 if ( is_array( $field ) ) {
1015 1247 return self::is_option_true_in_array( $field, $option );
1016 - } else {
1017 - return self::is_option_true_in_object( $field, $option );
1018 1248 }
1249 + return self::is_option_true_in_object( $field, $option );
1019 1250 }
1020 1251
1021 1252 /**
1022 1253 * @since 2.0.9
1254 + *
1255 + * @param array|object $field
1256 + * @param string $option
1257 + * @return bool
1023 1258 */
1024 1259 public static function is_option_empty( $field, $option ) {
1025 1260 if ( is_array( $field ) ) {
1026 1261 return self::is_option_empty_in_array( $field, $option );
1027 - } else {
1028 - return self::is_option_empty_in_object( $field, $option );
1029 1262 }
1263 + return self::is_option_empty_in_object( $field, $option );
1030 1264 }
1031 1265
1266 + /**
1267 + * @param array $field
1268 + * @param string $option
1269 + * @return bool
1270 + */
1032 1271 public static function is_option_true_in_array( $field, $option ) {
1033 - return isset( $field[ $option ] ) && $field[ $option ];
1272 + return ! empty( $field[ $option ] );
1034 1273 }
1035 1274
1275 + /**
1276 + * @param object $field
1277 + * @param string $option
1278 + * @return bool
1279 + */
1036 1280 public static function is_option_true_in_object( $field, $option ) {
1037 1281 return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ];
1038 1282 }
1039 1283
1284 + /**
1285 + * @param array $field
1286 + * @param string $option
1287 + * @return bool
1288 + */
1040 1289 public static function is_option_empty_in_array( $field, $option ) {
1041 - return ! isset( $field[ $option ] ) || empty( $field[ $option ] );
1290 + return empty( $field[ $option ] );
1042 1291 }
1043 1292
1293 + /**
1294 + * @param object $field
1295 + * @param string $option
1296 + * @return bool
1297 + */
1044 1298 public static function is_option_empty_in_object( $field, $option ) {
1045 - return ! isset( $field->field_options[ $option ] ) || empty( $field->field_options[ $option ] );
1299 + return empty( $field->field_options[ $option ] );
1046 1300 }
1047 1301
1302 + /**
1303 + * @param stdClass $field
1304 + * @param string $option
1305 + * @return bool
1306 + */
1048 1307 public static function is_option_value_in_object( $field, $option ) {
1049 1308 return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != '';
1050 1309 }
1051 1310
@@ -1050,8 +1309,12 @@
1050 1309 }
1051 1310
1052 1311 /**
1053 1312 * @since 2.0.18
1313 + *
1314 + * @param array|object $field
1315 + * @param string $option
1316 + * @return mixed
1054 1317 */
1055 1318 public static function get_option( $field, $option ) {
1056 1319 if ( is_array( $field ) ) {
1057 1320 $option = self::get_option_in_array( $field, $option );
@@ -1061,10 +1324,14 @@
1061 1324
1062 1325 return $option;
1063 1326 }
1064 1327
1328 + /**
1329 + * @param array $field
1330 + * @param string $option
1331 + * @return mixed
1332 + */
1065 1333 public static function get_option_in_array( $field, $option ) {
1066 -
1067 1334 if ( isset( $field[ $option ] ) ) {
1068 1335 $this_option = $field[ $option ];
1069 1336 } elseif ( isset( $field['field_options'] ) && is_array( $field['field_options'] ) && isset( $field['field_options'][ $option ] ) ) {
1070 1337 $this_option = $field['field_options'][ $option ];
@@ -1074,8 +1341,13 @@
1074 1341
1075 1342 return $this_option;
1076 1343 }
1077 1344
1345 + /**
1346 + * @param object $field
1347 + * @param string $option
1348 + * @return mixed
1349 + */
1078 1350 public static function get_option_in_object( $field, $option ) {
1079 1351 return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : '';
1080 1352 }
1081 1353
@@ -1080,17 +1352,20 @@
1080 1352 }
1081 1353
1082 1354 /**
1083 1355 * @since 2.0.09
1356 + *
1357 + * @param array|object $field
1358 + * @return bool
1084 1359 */
1085 1360 public static function is_repeating_field( $field ) {
1086 1361 if ( is_array( $field ) ) {
1087 - $is_repeating_field = ( 'divider' == $field['type'] );
1362 + $is_repeating_field = ( 'divider' === $field['type'] );
1088 1363 } else {
1089 - $is_repeating_field = ( 'divider' == $field->type );
1364 + $is_repeating_field = ( 'divider' === $field->type );
1090 1365 }
1091 1366
1092 - return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) );
1367 + return $is_repeating_field && self::is_option_true( $field, 'repeat' );
1093 1368 }
1094 1369
1095 1370 /**
1096 1371 * @param string $key
@@ -1105,9 +1380,9 @@
1105 1380
1106 1381 /**
1107 1382 * @param string $id
1108 1383 *
1109 - * @return null|string
1384 + * @return string|null
1110 1385 */
1111 1386 public static function get_key_by_id( $id ) {
1112 1387 return FrmDb::get_var( 'frm_fields', array( 'id' => $id ), 'field_key' );
1113 1388 }
@@ -1114,9 +1389,9 @@
1114 1389
1115 1390 public static function is_image( $field ) {
1116 1391 $type = self::get_field_type( $field );
1117 1392
1118 - return ( $type == 'url' && self::get_option( $field, 'show_image' ) );
1393 + return ( $type === 'url' && self::get_option( $field, 'show_image' ) );
1119 1394 }
1120 1395
1121 1396 /**
1122 1397 * Check if field is radio or Dynamic radio
@@ -1124,9 +1399,9 @@
1124 1399 * @since 3.0
1125 1400 *
1126 1401 * @param array|object $field
1127 1402 *
1128 - * @return boolean true if field type is radio or Dynamic radio
1403 + * @return bool true if field type is radio or Dynamic radio
1129 1404 */
1130 1405 public static function is_radio( $field ) {
1131 1406 return self::is_field_type( $field, 'radio' );
1132 1407 }
@@ -1137,9 +1412,9 @@
1137 1412 * @since 3.0
1138 1413 *
1139 1414 * @param array|object $field
1140 1415 *
1141 - * @return boolean true if field type is checkbox or Dynamic checkbox
1416 + * @return bool true if field type is checkbox or Dynamic checkbox
1142 1417 */
1143 1418 public static function is_checkbox( $field ) {
1144 1419 return self::is_field_type( $field, 'checkbox' );
1145 1420 }
@@ -1149,11 +1424,11 @@
1149 1424 *
1150 1425 * @since 3.0
1151 1426 *
1152 1427 * @param array|object $field
1153 - * @param string $is_type Options include radio, checkbox, text
1428 + * @param string $is_type Options include radio, checkbox, text.
1154 1429 *
1155 - * @return boolean true if field type is checkbox or Dynamic checkbox
1430 + * @return bool true if field type is checkbox or Dynamic checkbox
1156 1431 */
1157 1432 public static function is_field_type( $field, $is_type ) {
1158 1433 $field_type = self::get_original_field_type( $field );
1159 1434 $data_type = self::get_option( $field, 'data_type' );