PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.0
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 +168 -511 6.256.0 View file →
@@ -4,259 +4,214 @@
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 + }
12 21 $fields = array(
13 - 'text' => array(
22 + 'text' => array(
14 23 'name' => __( 'Text', 'formidable' ),
15 24 'icon' => 'frm_icon_font frm_text2_icon',
16 25 ),
17 - 'textarea' => array(
26 + 'textarea' => array(
18 27 'name' => __( 'Paragraph', 'formidable' ),
19 28 'icon' => 'frm_icon_font frm_paragraph_icon',
20 29 ),
21 - 'checkbox' => array(
30 + 'checkbox' => array(
22 31 'name' => __( 'Checkboxes', 'formidable' ),
23 32 'icon' => 'frm_icon_font frm_check_square_icon',
24 33 ),
25 - 'radio' => array(
34 + 'radio' => array(
26 35 'name' => __( 'Radio Buttons', 'formidable' ),
27 36 'icon' => 'frm_icon_font frm_radio_checked_icon',
28 37 ),
29 - 'select' => array(
38 + 'select' => array(
30 39 'name' => __( 'Dropdown', 'formidable' ),
31 - 'icon' => 'frm_icon_font frm_dropdown_icon',
40 + 'icon' => 'frm_icon_font frm_caret_square_down_icon',
32 41 ),
33 - 'email' => array(
42 + 'email' => array(
34 43 'name' => __( 'Email', 'formidable' ),
35 - 'icon' => 'frm_icon_font frm_email2_icon',
44 + 'icon' => 'frm_icon_font frm_email_icon',
36 45 ),
37 - 'url' => array(
46 + 'url' => array(
38 47 'name' => __( 'Website/URL', 'formidable' ),
39 - 'icon' => 'frm_icon_font frm_link2_icon',
48 + 'icon' => 'frm_icon_font frm_link_icon',
40 49 ),
41 - 'number' => array(
50 + 'number' => array(
42 51 'name' => __( 'Number', 'formidable' ),
43 52 'icon' => 'frm_icon_font frm_hashtag_icon',
44 53 ),
45 - 'name' => array(
54 + 'name' => array(
46 55 'name' => __( 'Name', 'formidable' ),
47 56 'icon' => 'frm_icon_font frm_user_name_icon',
48 57 ),
49 - 'phone' => array(
58 + 'phone' => array(
50 59 'name' => __( 'Phone', 'formidable' ),
51 60 'icon' => 'frm_icon_font frm_phone_icon',
52 61 ),
53 - 'html' => array(
62 + 'html' => array(
54 63 'name' => __( 'HTML', 'formidable' ),
55 - 'icon' => 'frm_icon_font frm_code2_icon',
64 + 'icon' => 'frm_icon_font frm_code_icon',
56 65 ),
57 - 'hidden' => array(
66 + 'hidden' => array(
58 67 'name' => __( 'Hidden', 'formidable' ),
59 - 'icon' => 'frm_icon_font frm_eye_slash2_icon',
68 + 'icon' => 'frm_icon_font frm_eye_slash_icon',
60 69 ),
61 - 'user_id' => array(
70 + 'user_id' => array(
62 71 'name' => __( 'User ID', 'formidable' ),
63 - 'icon' => 'frm_icon_font frm_user2_icon',
72 + 'icon' => 'frm_icon_font frm_user_icon',
64 73 ),
65 - 'captcha' => array(
66 - 'name' => self::get_captcha_field_name(),
67 - 'icon' => 'frm_icon_font frm_shield_check2_icon',
74 + 'captcha' => array(
75 + 'name' => $captcha_name,
76 + 'icon' => 'frm_icon_font frm_shield_check_icon',
68 77 ),
69 - 'credit_card' => array(
70 - 'name' => __( 'Payment', 'formidable' ),
71 - 'icon' => 'frm_icon_font frm_credit_card2_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 - ),
82 78 );
83 79
84 - /**
85 - * @param array $fields
86 - */
87 80 return apply_filters( 'frm_available_fields', $fields );
88 81 }
89 82
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 -
99 83 public static function pro_field_selection() {
100 84 $images_url = FrmAppHelper::plugin_url() . '/images/';
101 85 $fields = array(
102 - 'file' => array(
103 - 'name' => __( 'File Upload', 'formidable' ),
104 - 'icon' => 'frm_icon_font frm_upload3_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' ),
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.',
106 90 ),
107 - 'ranking' => array(),
108 - 'rte' => array(
91 + 'rte' => array(
109 92 'name' => __( 'Rich Text', 'formidable' ),
110 93 'icon' => 'frm_icon_font frm_align_right_icon',
111 94 ),
112 - 'date' => array(
95 + 'date' => array(
113 96 'name' => __( 'Date', 'formidable' ),
114 - 'icon' => 'frm_icon_font frm_calendar2_icon',
97 + 'icon' => 'frm_icon_font frm_calendar_icon',
115 98 ),
116 - 'time' => array(
99 + 'time' => array(
117 100 'name' => __( 'Time', 'formidable' ),
118 101 'icon' => 'frm_icon_font frm_clock_icon',
119 102 ),
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' ) . '" />',
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" />',
124 107 ),
125 - 'star' => array(
108 + 'star' => array(
126 109 'name' => __( 'Star Rating', 'formidable' ),
127 - 'icon' => 'frm_icon_font frm_star2_icon',
110 + 'icon' => 'frm_icon_font frm_star_icon',
128 111 ),
129 - 'range' => array(
112 + 'range' => array(
130 113 'name' => __( 'Slider', 'formidable' ),
131 114 'icon' => 'frm_icon_font frm_code_commit_icon',
132 115 ),
133 - 'toggle' => array(
116 + 'toggle' => array(
134 117 'name' => __( 'Toggle', 'formidable' ),
135 118 'icon' => 'frm_icon_font frm_toggle_on_icon',
136 119 ),
137 - 'data' => array(
138 - 'name' => __( 'Dynamic', 'formidable' ),
139 - 'icon' => 'frm_icon_font frm_dynamic_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' ),
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.',
141 124 ),
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' ) . '" />',
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" />',
146 129 ),
147 - 'divider|repeat' => array(
148 - 'name' => __( 'Repeater', 'formidable' ),
149 - 'icon' => 'frm_icon_font frm_refresh_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' ) . '" />',
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" />',
151 134 ),
152 - 'end_divider' => array(
135 + 'end_divider' => array(
153 136 'name' => __( 'Section Buttons', 'formidable' ),
154 137 'switch_from' => 'divider',
155 138 ),
156 - 'divider' => array(
139 + 'divider' => array(
157 140 'name' => __( 'Section', 'formidable' ),
158 141 'icon' => 'frm_icon_font frm_header_icon',
159 142 ),
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' ),
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?',
164 147 ),
165 - 'form' => array(
148 + 'form' => array(
166 149 'name' => __( 'Embed Form', 'formidable' ),
167 - 'icon' => 'frm_icon_font frm_file_text2_icon',
150 + 'icon' => 'frm_icon_font frm_file_text_icon',
168 151 ),
169 - 'likert' => array(
152 + 'likert' => array(
170 153 'name' => __( 'Likert Scale', 'formidable' ),
171 154 'icon' => 'frm_icon_font frm_likert_scale frm_show_upgrade',
172 155 'addon' => 'surveys',
173 156 ),
174 - 'nps' => array(
157 + 'nps' => array(
175 158 'name' => __( 'NPS', 'formidable' ),
176 159 'icon' => 'frm_icon_font frm_nps frm_show_upgrade',
177 160 'addon' => 'surveys',
178 161 ),
179 - 'password' => array(
162 + 'password' => array(
180 163 'name' => __( 'Password', 'formidable' ),
181 - 'icon' => 'frm_icon_font frm_lock_closed2_icon',
164 + 'icon' => 'frm_icon_font frm_lock_open_icon',
182 165 ),
183 - 'tag' => array(
166 + 'tag' => array(
184 167 'name' => __( 'Tags', 'formidable' ),
185 - 'icon' => 'frm_icon_font frm_price_tags2_icon',
168 + 'icon' => 'frm_icon_font frm_price_tags_icon',
186 169 ),
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' => '',
170 + 'credit_card' => array(
171 + 'name' => __( 'Credit Card', 'formidable' ),
172 + 'icon' => 'frm_icon_font frm_credit_card_icon frm_show_upgrade',
173 + 'addon' => 'stripe',
192 174 ),
193 - 'address' => array(
175 + 'address' => array(
194 176 'name' => __( 'Address', 'formidable' ),
195 - 'icon' => 'frm_icon_font frm_location2_icon',
177 + 'icon' => 'frm_icon_font frm_location_icon',
196 178 ),
197 - 'summary' => array(
198 - 'name' => __( 'Summary', 'formidable' ),
199 - 'icon' => 'frm_icon_font frm_file_text3_icon',
200 - 'message' => __( 'Allow visitors to review their responses before a form is submitted. Upgrade to Pro to get Summary fields and more.', 'formidable' ),
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.',
201 183 ),
202 - 'signature' => array(
184 + 'signature' => array(
203 185 'name' => __( 'Signature', 'formidable' ),
204 186 'icon' => 'frm_icon_font frm_signature_icon frm_show_upgrade',
205 187 'addon' => 'signature',
206 188 ),
207 - 'ai' => array(
208 - 'name' => __( 'AI', 'formidable' ),
209 - 'icon' => 'frm_icon_font frm-ai-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' ),
212 - ),
213 189 'ssa-appointment' => array(
214 190 'name' => __( 'Appointment', 'formidable' ),
215 - 'icon' => 'frm_icon_font frm_schedule_icon frm_show_upgrade',
191 + 'icon' => 'frm_icon_font frm_calendar_icon frm_show_upgrade',
216 192 'require' => 'Simply Schedule Appointments',
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' ) . '" />',
193 + '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.
194 + <img src="' . esc_attr( $images_url ) . 'appointments.png" alt="Scheduling" />',
223 195 'link' => 'https://simplyscheduleappointments.com/meet/formidable/',
224 196 ),
225 - 'product' => array(
197 + 'product' => array(
226 198 'name' => __( 'Product', 'formidable' ),
227 - 'icon' => 'frm_icon_font frm_product2_icon',
199 + 'icon' => 'frm_icon_font frm_product_icon',
228 200 'section' => 'pricing',
229 201 ),
230 - 'quantity' => array(
202 + 'quantity' => array(
231 203 'name' => __( 'Quantity', 'formidable' ),
232 204 'icon' => 'frm_icon_font frm_quantity_icon',
233 205 'section' => 'pricing',
234 206 ),
235 - 'total' => array(
207 + 'total' => array(
236 208 'name' => __( 'Total', 'formidable' ),
237 - 'icon' => 'frm_icon_font frm_total2_icon',
209 + 'icon' => 'frm_icon_font frm_total_icon',
238 210 'section' => 'pricing',
239 211 ),
240 212 );
241 213
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 -
255 - if ( ! FrmAppHelper::show_new_feature( 'ai' ) ) {
256 - unset( $fields['ai'] );
257 - }
258 -
259 214 // Since the signature field may be in a different section, don't show it twice.
260 215 $lite_fields = self::field_selection();
261 216 if ( isset( $lite_fields['signature'] ) ) {
262 217 unset( $fields['signature'] );
@@ -265,102 +220,9 @@
265 220 return apply_filters( 'frm_pro_available_fields', $fields );
266 221 }
267 222
268 223 /**
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 - /**
360 224 * @since 4.0
361 - *
362 - * @return array
363 225 */
364 226 public static function all_field_selection() {
365 227 $pro_field_selection = self::pro_field_selection();
366 228 return array_merge( $pro_field_selection, self::field_selection() );
@@ -365,28 +227,19 @@
365 227 $pro_field_selection = self::pro_field_selection();
366 228 return array_merge( $pro_field_selection, self::field_selection() );
367 229 }
368 230
369 - /**
370 - * Create a field.
371 - *
372 - * @param array $values
373 - * @param bool $return
374 - * @return false|int
375 - */
376 231 public static function create( $values, $return = true ) {
377 232 global $wpdb, $frm_duplicate_ids;
378 233
379 234 $new_values = array();
380 - $key = $values['field_key'] ?? $values['name'];
235 + $key = isset( $values['field_key'] ) ? $values['field_key'] : $values['name'];
381 236 $new_values['field_key'] = FrmAppHelper::get_unique_key( $key, $wpdb->prefix . 'frm_fields', 'field_key' );
382 237
383 238 $values = FrmAppHelper::maybe_filter_array( $values, array( 'name', 'description' ) );
384 239
385 240 foreach ( array( 'name', 'description', 'type', 'default_value' ) as $col ) {
386 - if ( isset( $values[ $col ] ) ) {
387 - $new_values[ $col ] = $values[ $col ];
388 - }
241 + $new_values[ $col ] = $values[ $col ];
389 242 }
390 243
391 244 $new_values['options'] = self::maybe_filter_options( $values['options'] );
392 245 $new_values['field_order'] = isset( $values['field_order'] ) ? (int) $values['field_order'] : null;
@@ -413,32 +266,30 @@
413 266 unset( $k, $v );
414 267 }
415 268
416 269 $query_results = $wpdb->insert( $wpdb->prefix . 'frm_fields', $new_values );
270 + $new_id = 0;
271 + if ( $query_results ) {
272 + self::delete_form_transient( $new_values['form_id'] );
273 + $new_id = $wpdb->insert_id;
274 + }
417 275
418 - if ( ! $query_results ) {
276 + if ( ! $return ) {
419 277 return false;
420 278 }
421 279
422 - self::delete_form_transient( $new_values['form_id'] );
423 - $new_id = $wpdb->insert_id;
280 + if ( $query_results ) {
281 + if ( isset( $values['id'] ) ) {
282 + $frm_duplicate_ids[ $values['id'] ] = $new_id;
283 + }
424 284
425 - if ( ! $return ) {
285 + return $new_id;
286 + } else {
426 287 return false;
427 288 }
428 -
429 - if ( isset( $values['id'] ) ) {
430 - $frm_duplicate_ids[ $values['id'] ] = $new_id;
431 - }
432 -
433 - return $new_id;
434 289 }
435 290
436 291 /**
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 - *
441 292 * @since 5.0.08
442 293 *
443 294 * @param array $options
444 295 * @return array
@@ -443,82 +294,12 @@
443 294 * @param array $options
444 295 * @return array
445 296 */
446 297 private static function maybe_filter_options( $options ) {
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;
298 + return FrmAppHelper::maybe_filter_array( $options, array( 'custom_html' ) );
458 299 }
459 300
460 301 /**
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 - /**
521 302 * Process the field duplication.
522 303 *
523 304 * @since 5.0.05
524 305 */
@@ -609,16 +390,11 @@
609 390 $new_id = self::create( $values );
610 391 $frm_duplicate_ids[ $field->id ] = $new_id;
611 392 $frm_duplicate_ids[ $field->field_key ] = $new_id;
612 393 unset( $field );
613 - }//end foreach
394 + }
614 395 }
615 396
616 - /**
617 - * @param int|string $id
618 - * @param array $values
619 - * @return false|int
620 - */
621 397 public static function update( $id, $values ) {
622 398 global $wpdb;
623 399
624 400 $id = absint( $id );
@@ -634,22 +410,10 @@
634 410
635 411 self::preserve_format_option_backslashes( $values );
636 412
637 413 if ( isset( $values['type'] ) ) {
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 - }
414 + $values = apply_filters( 'frm_clean_' . $values['type'] . '_field_options_before_update', $values );
643 415
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 -
652 416 if ( $values['type'] === 'hidden' && isset( $values['field_options'] ) && isset( $values['field_options']['clear_on_focus'] ) ) {
653 417 // don't keep the old placeholder setting for hidden fields
654 418 $values['field_options']['clear_on_focus'] = 0;
655 419 }
@@ -696,9 +460,9 @@
696 460 * Keep backslashes in the phone format option
697 461 *
698 462 * @since 2.0.8
699 463 *
700 - * @param array $values Pass by reference.
464 + * @param $values array - pass by reference
701 465 */
702 466 private static function preserve_format_option_backslashes( &$values ) {
703 467 if ( isset( $values['field_options']['format'] ) ) {
704 468 $values['field_options']['format'] = FrmAppHelper::preserve_backslashes( $values['field_options']['format'] );
@@ -742,11 +506,8 @@
742 506 }
743 507
744 508 /**
745 509 * If $field is numeric, get the field object
746 - *
747 - * @param int|object|string $field
748 - * @return void
749 510 */
750 511 public static function maybe_get_field( &$field ) {
751 512 if ( ! is_object( $field ) ) {
752 513 $field = self::getOne( $field );
@@ -753,10 +514,10 @@
753 514 }
754 515 }
755 516
756 517 /**
757 - * @param int|string $id The field id or key.
758 - * @param bool $filter When true, run the frm_field filter.
518 + * @param string|int $id The field id or key.
519 + * @param bool $filter When true, run the frm_field filter.
759 520 */
760 521 public static function getOne( $id, $filter = false ) {
761 522 if ( empty( $id ) ) {
762 523 return null;
@@ -802,10 +563,10 @@
802 563
803 564 /**
804 565 * Get the field type by key or id
805 566 *
806 - * @param int|string $id The field id or key.
807 - * @param mixed $col The name of the column in the fields database table.
567 + * @param int|string The field id or key
568 + * @param mixed $col The name of the column in the fields database table
808 569 */
809 570 public static function get_type( $id, $col = 'type' ) {
810 571 $field = FrmDb::check_cache( $id, 'frm_field' );
811 572 if ( $field ) {
@@ -810,25 +571,19 @@
810 571 $field = FrmDb::check_cache( $id, 'frm_field' );
811 572 if ( $field ) {
812 573 $type = $field->{$col};
813 574 } else {
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 );
575 + $where = array(
576 + 'or' => 1,
577 + 'id' => $id,
578 + 'field_key' => $id,
579 + );
580 + $type = FrmDb::get_var( 'frm_fields', $where, $col );
820 581 }
821 582
822 583 return $type;
823 584 }
824 585
825 - /**
826 - * @param int|string $form_id
827 - * @param string $type
828 - * @param int|string $limit
829 - * @param string $inc_sub
830 - */
831 586 public static function get_all_types_in_form( $form_id, $type, $limit = '', $inc_sub = 'exclude' ) {
832 587 if ( ! $form_id ) {
833 588 return array();
834 589 }
@@ -848,9 +603,9 @@
848 603 continue;
849 604 }
850 605
851 606 $fields[ $result->id ] = $result;
852 - ++$count;
607 + $count ++;
853 608 if ( $limit == 1 ) {
854 609 $fields = $result;
855 610 break;
856 611 }
@@ -862,9 +617,9 @@
862 617 unset( $result );
863 618 }
864 619
865 620 return wp_unslash( $fields );
866 - }//end if
621 + }
867 622
868 623 self::$use_cache = false;
869 624
870 625 $where = array(
@@ -878,15 +633,8 @@
878 633
879 634 return $results;
880 635 }
881 636
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 - */
889 637 public static function get_all_for_form( $form_id, $limit = '', $inc_embed = 'exclude', $inc_repeat = 'include' ) {
890 638 if ( ! (int) $form_id ) {
891 639 return array();
892 640 }
@@ -899,9 +647,9 @@
899 647
900 648 $fields = array();
901 649 $count = 0;
902 650 foreach ( $results as $result ) {
903 - ++$count;
651 + $count ++;
904 652 $fields[ $result->id ] = $result;
905 653 if ( ! empty( $limit ) && $count >= $limit ) {
906 654 break;
907 655 }
@@ -930,12 +678,12 @@
930 678 /**
931 679 * If repeating fields should be included, adjust $where accordingly
932 680 *
933 681 * @param string $inc_repeat
934 - * @param array $where Pass by reference.
682 + * @param array $where - pass by reference
935 683 */
936 684 private static function maybe_include_repeating_fields( $inc_repeat, &$where ) {
937 - if ( $inc_repeat === 'include' ) {
685 + if ( $inc_repeat == 'include' ) {
938 686 $form_id = $where['fi.form_id'];
939 687 $where[] = array(
940 688 'or' => 1,
941 689 'fi.form_id' => $form_id,
@@ -950,9 +698,9 @@
950 698 if ( 'include' != $inc_embed || $no_sub_forms ) {
951 699 return;
952 700 }
953 701
954 - $form_fields = $results;
702 + $form_fields = $results;
955 703 $should_get_subforms = ( $type !== 'all' && $type !== 'form' && ! empty( $form_id ) );
956 704 if ( $should_get_subforms ) {
957 705 $form_fields = self::get_all_types_in_form( $form_id, 'form' );
958 706 }
@@ -962,9 +710,9 @@
962 710 if ( 'form' != $field->type || ! isset( $field->field_options['form_select'] ) ) {
963 711 continue;
964 712 }
965 713
966 - if ( $type === 'all' ) {
714 + if ( $type == 'all' ) {
967 715 $sub_fields = self::get_all_for_form( $field->field_options['form_select'] );
968 716 } else {
969 717 $sub_fields = self::get_all_types_in_form( $field->field_options['form_select'], $type );
970 718 }
@@ -969,9 +717,9 @@
969 717 $sub_fields = self::get_all_types_in_form( $field->field_options['form_select'], $type );
970 718 }
971 719
972 720 if ( ! empty( $sub_fields ) ) {
973 - $index = $k + $index_offset;
721 + $index = $k + $index_offset;
974 722 $index_offset += count( $sub_fields );
975 723 array_splice( $results, $index, 0, $sub_fields );
976 724 }
977 725 unset( $field, $sub_fields );
@@ -1010,10 +758,10 @@
1010 758 }
1011 759
1012 760 $limit = FrmDb::esc_limit( $limit );
1013 761
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';
762 + $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";
763 + $query_type = ( $limit == ' LIMIT 1' || $limit == 1 ) ? 'row' : 'results';
1016 764
1017 765 if ( is_array( $where ) ) {
1018 766 $args = array(
1019 767 'order_by' => $order_by,
@@ -1018,14 +766,14 @@
1018 766 $args = array(
1019 767 'order_by' => $order_by,
1020 768 'limit' => $limit,
1021 769 );
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 );
770 + $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 );
1023 771 } else {
1024 772 // if the query is not an array, then it has already been prepared
1025 773 $query .= FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
1026 774
1027 - $function_name = $query_type === 'row' ? 'get_row' : 'get_results';
775 + $function_name = ( $query_type == 'row' ) ? 'get_row' : 'get_results';
1028 776 $results = $wpdb->$function_name( $query );
1029 777 }
1030 778 unset( $where );
1031 779
@@ -1041,10 +789,8 @@
1041 789 */
1042 790 private static function format_field_results( &$results ) {
1043 791 if ( is_array( $results ) ) {
1044 792 foreach ( $results as $r_key => $result ) {
1045 - self::add_slashes_to_format_before_setting_field_cache( $result );
1046 -
1047 793 FrmDb::set_cache( $result->id, $result, 'frm_field' );
1048 794 FrmDb::set_cache( $result->field_key, $result, 'frm_field' );
1049 795
1050 796 self::prepare_options( $result );
@@ -1062,26 +808,8 @@
1062 808 }
1063 809 }
1064 810
1065 811 /**
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 - /**
1084 812 * Unserialize all the serialized field data
1085 813 *
1086 814 * @since 2.0
1087 815 */
@@ -1090,21 +818,16 @@
1090 818 FrmAppHelper::unserialize_or_decode( $results->options );
1091 819
1092 820 // Allow a single box to be checked for the default value.
1093 821 $before = $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 - }
822 + FrmAppHelper::unserialize_or_decode( $results->default_value );
823 + if ( $before === $results->default_value && ! is_array( $before ) && strpos( $before, '["' ) === 0 ) {
824 + $results->default_value = FrmAppHelper::maybe_json_decode( $results->default_value );
1102 825 }
1103 826 }
1104 827
1105 828 /**
1106 - * If a form has too many fields, they won't all save into a single transient.
829 + * If a form has too many fields, thay won't all save into a single transient.
1107 830 * We'll break them into groups of 200
1108 831 *
1109 832 * @since 2.0.1
1110 833 */
@@ -1128,9 +851,9 @@
1128 851 $fields = array_merge( $fields, $next_fields );
1129 852
1130 853 if ( count( $next_fields ) >= self::$transient_size ) {
1131 854 // if this transient is full, check for another
1132 - ++$next;
855 + $next ++;
1133 856 self::get_next_transient( $fields, $base_name, $next );
1134 857 }
1135 858 }
1136 859 }
@@ -1149,9 +872,9 @@
1149 872 $set = set_transient( $name, $field, 60 * 60 * 6 );
1150 873 if ( ! $set ) {
1151 874 // the transient didn't save
1152 875 if ( $name != $base_name ) {
1153 - // if the first saved an others fail, this will show an incomplete form
876 + // if the first saved an others fail, this will show an incmoplete form
1154 877 self::delete_form_transient( $form_id );
1155 878 }
1156 879
1157 880 return;
@@ -1156,25 +879,18 @@
1156 879
1157 880 return;
1158 881 }
1159 882
1160 - ++$next;
883 + $next ++;
1161 884 }
1162 885 }
1163 886
1164 - /**
1165 - * @param string $type
1166 - * @return bool
1167 - */
1168 887 public static function is_no_save_field( $type ) {
1169 - return in_array( $type, self::no_save_fields(), true );
888 + return in_array( $type, self::no_save_fields() );
1170 889 }
1171 890
1172 - /**
1173 - * @return string[]
1174 - */
1175 891 public static function no_save_fields() {
1176 - return array( 'divider', 'end_divider', 'captcha', 'break', 'html', 'form', 'summary', FrmSubmitHelper::FIELD_TYPE );
892 + return array( 'divider', 'end_divider', 'captcha', 'break', 'html', 'form', 'summary' );
1177 893 }
1178 894
1179 895 /**
1180 896 * Check if this field can hold an array of values
@@ -1182,9 +898,9 @@
1182 898 * @since 2.0.9
1183 899 *
1184 900 * @param array|object $field
1185 901 *
1186 - * @return bool
902 + * @return boolean
1187 903 */
1188 904 public static function is_field_with_multiple_values( $field ) {
1189 905 if ( ! $field ) {
1190 906 return false;
@@ -1193,9 +909,9 @@
1193 909 $field_type = self::get_original_field_type( $field );
1194 910
1195 911 $is_multi_value_field = (
1196 912 self::is_checkbox( $field ) ||
1197 - $field_type === 'address' ||
913 + $field_type == 'address' ||
1198 914 self::is_multiple_select( $field )
1199 915 );
1200 916
1201 917 return $is_multi_value_field;
@@ -1202,9 +918,8 @@
1202 918 }
1203 919
1204 920 /**
1205 921 * @since 3.0
1206 - * @param array|object $field
1207 922 * @return string
1208 923 */
1209 924 public static function get_field_type( $field ) {
1210 925 return is_array( $field ) ? $field['type'] : $field->type;
@@ -1218,10 +933,9 @@
1218 933 $field_type = self::get_field_type( $field );
1219 934 $original_type = self::get_option( $field, 'original_type' );
1220 935
1221 936 if ( ! empty( $original_type ) && $original_type != $field_type ) {
1222 - // Check the original type for arrays.
1223 - $field_type = $original_type;
937 + $field_type = $original_type; // check the original type for arrays
1224 938 }
1225 939
1226 940 return $field_type;
1227 941 }
@@ -1229,9 +943,9 @@
1229 943 /**
1230 944 * Check if this is a multiselect dropdown field
1231 945 *
1232 946 * @since 2.0.9
1233 - * @return bool
947 + * @return boolean
1234 948 */
1235 949 public static function is_multiple_select( $field ) {
1236 950 $field_type = self::get_field_type( $field );
1237 951 $is_multiple = self::is_option_true( $field, 'multiple' ) && self::is_field_type( $field, 'select' ) && $field_type !== 'hidden';
@@ -1243,104 +957,63 @@
1243 957 * Check if a field is read only. Read only can be set in the field options,
1244 958 * but disabled with the shortcode options
1245 959 *
1246 960 * @since 2.0.9
1247 - *
1248 - * @param array|object $field
1249 - * @return bool
1250 961 */
1251 962 public static function is_read_only( $field ) {
1252 963 global $frm_vars;
1253 - return self::is_option_true( $field, 'read_only' ) && ( ! isset( $frm_vars['readonly'] ) || $frm_vars['readonly'] !== 'disabled' );
964 +
965 + return ( self::is_option_true( $field, 'read_only' ) && ( ! isset( $frm_vars['readonly'] ) || $frm_vars['readonly'] != 'disabled' ) );
1254 966 }
1255 967
1256 968 /**
1257 969 * @since 2.0.9
1258 - *
1259 - * @param array $field
1260 - * @return bool
1261 970 */
1262 971 public static function is_required( $field ) {
1263 - $required = $field['required'] != '0';
972 + $required = ( $field['required'] != '0' );
973 + $required = apply_filters( 'frm_is_field_required', $required, $field );
1264 974
1265 - /**
1266 - * @param bool $required
1267 - * @param array $field
1268 - */
1269 - $required = (bool) apply_filters( 'frm_is_field_required', $required, $field );
1270 -
1271 975 return $required;
1272 976 }
1273 977
1274 978 /**
1275 979 * @since 2.0.9
1276 - *
1277 - * @param array|object $field
1278 - * @param string $option
1279 - * @return bool
1280 980 */
1281 981 public static function is_option_true( $field, $option ) {
1282 982 if ( is_array( $field ) ) {
1283 983 return self::is_option_true_in_array( $field, $option );
984 + } else {
985 + return self::is_option_true_in_object( $field, $option );
1284 986 }
1285 - return self::is_option_true_in_object( $field, $option );
1286 987 }
1287 988
1288 989 /**
1289 990 * @since 2.0.9
1290 - *
1291 - * @param array|object $field
1292 - * @param string $option
1293 - * @return bool
1294 991 */
1295 992 public static function is_option_empty( $field, $option ) {
1296 993 if ( is_array( $field ) ) {
1297 994 return self::is_option_empty_in_array( $field, $option );
995 + } else {
996 + return self::is_option_empty_in_object( $field, $option );
1298 997 }
1299 - return self::is_option_empty_in_object( $field, $option );
1300 998 }
1301 999
1302 - /**
1303 - * @param array $field
1304 - * @param string $option
1305 - * @return bool
1306 - */
1307 1000 public static function is_option_true_in_array( $field, $option ) {
1308 - return ! empty( $field[ $option ] );
1001 + return isset( $field[ $option ] ) && $field[ $option ];
1309 1002 }
1310 1003
1311 - /**
1312 - * @param object $field
1313 - * @param string $option
1314 - * @return bool
1315 - */
1316 1004 public static function is_option_true_in_object( $field, $option ) {
1317 1005 return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ];
1318 1006 }
1319 1007
1320 - /**
1321 - * @param array $field
1322 - * @param string $option
1323 - * @return bool
1324 - */
1325 1008 public static function is_option_empty_in_array( $field, $option ) {
1326 - return empty( $field[ $option ] );
1009 + return ! isset( $field[ $option ] ) || empty( $field[ $option ] );
1327 1010 }
1328 1011
1329 - /**
1330 - * @param object $field
1331 - * @param string $option
1332 - * @return bool
1333 - */
1334 1012 public static function is_option_empty_in_object( $field, $option ) {
1335 - return empty( $field->field_options[ $option ] );
1013 + return ! isset( $field->field_options[ $option ] ) || empty( $field->field_options[ $option ] );
1336 1014 }
1337 1015
1338 - /**
1339 - * @param stdClass $field
1340 - * @param string $option
1341 - * @return bool
1342 - */
1343 1016 public static function is_option_value_in_object( $field, $option ) {
1344 1017 return isset( $field->field_options[ $option ] ) && $field->field_options[ $option ] != '';
1345 1018 }
1346 1019
@@ -1345,12 +1018,8 @@
1345 1018 }
1346 1019
1347 1020 /**
1348 1021 * @since 2.0.18
1349 - *
1350 - * @param array|object $field
1351 - * @param string $option
1352 - * @return mixed
1353 1022 */
1354 1023 public static function get_option( $field, $option ) {
1355 1024 if ( is_array( $field ) ) {
1356 1025 $option = self::get_option_in_array( $field, $option );
@@ -1360,14 +1029,10 @@
1360 1029
1361 1030 return $option;
1362 1031 }
1363 1032
1364 - /**
1365 - * @param array $field
1366 - * @param string $option
1367 - * @return mixed
1368 - */
1369 1033 public static function get_option_in_array( $field, $option ) {
1034 +
1370 1035 if ( isset( $field[ $option ] ) ) {
1371 1036 $this_option = $field[ $option ];
1372 1037 } elseif ( isset( $field['field_options'] ) && is_array( $field['field_options'] ) && isset( $field['field_options'][ $option ] ) ) {
1373 1038 $this_option = $field['field_options'][ $option ];
@@ -1377,31 +1042,23 @@
1377 1042
1378 1043 return $this_option;
1379 1044 }
1380 1045
1381 - /**
1382 - * @param object $field
1383 - * @param string $option
1384 - * @return mixed
1385 - */
1386 1046 public static function get_option_in_object( $field, $option ) {
1387 - return $field->field_options[ $option ] ?? '';
1047 + return isset( $field->field_options[ $option ] ) ? $field->field_options[ $option ] : '';
1388 1048 }
1389 1049
1390 1050 /**
1391 1051 * @since 2.0.09
1392 - *
1393 - * @param array|object $field
1394 - * @return bool
1395 1052 */
1396 1053 public static function is_repeating_field( $field ) {
1397 1054 if ( is_array( $field ) ) {
1398 - $is_repeating_field = ( 'divider' === $field['type'] );
1055 + $is_repeating_field = ( 'divider' == $field['type'] );
1399 1056 } else {
1400 - $is_repeating_field = ( 'divider' === $field->type );
1057 + $is_repeating_field = ( 'divider' == $field->type );
1401 1058 }
1402 1059
1403 - return $is_repeating_field && self::is_option_true( $field, 'repeat' );
1060 + return ( $is_repeating_field && self::is_option_true( $field, 'repeat' ) );
1404 1061 }
1405 1062
1406 1063 /**
1407 1064 * @param string $key
@@ -1416,9 +1073,9 @@
1416 1073
1417 1074 /**
1418 1075 * @param string $id
1419 1076 *
1420 - * @return string|null
1077 + * @return string
1421 1078 */
1422 1079 public static function get_key_by_id( $id ) {
1423 1080 return FrmDb::get_var( 'frm_fields', array( 'id' => $id ), 'field_key' );
1424 1081 }
@@ -1425,9 +1082,9 @@
1425 1082
1426 1083 public static function is_image( $field ) {
1427 1084 $type = self::get_field_type( $field );
1428 1085
1429 - return ( $type === 'url' && self::get_option( $field, 'show_image' ) );
1086 + return ( $type == 'url' && self::get_option( $field, 'show_image' ) );
1430 1087 }
1431 1088
1432 1089 /**
1433 1090 * Check if field is radio or Dynamic radio
@@ -1435,9 +1092,9 @@
1435 1092 * @since 3.0
1436 1093 *
1437 1094 * @param array|object $field
1438 1095 *
1439 - * @return bool true if field type is radio or Dynamic radio
1096 + * @return boolean true if field type is radio or Dynamic radio
1440 1097 */
1441 1098 public static function is_radio( $field ) {
1442 1099 return self::is_field_type( $field, 'radio' );
1443 1100 }
@@ -1448,9 +1105,9 @@
1448 1105 * @since 3.0
1449 1106 *
1450 1107 * @param array|object $field
1451 1108 *
1452 - * @return bool true if field type is checkbox or Dynamic checkbox
1109 + * @return boolean true if field type is checkbox or Dynamic checkbox
1453 1110 */
1454 1111 public static function is_checkbox( $field ) {
1455 1112 return self::is_field_type( $field, 'checkbox' );
1456 1113 }
@@ -1460,11 +1117,11 @@
1460 1117 *
1461 1118 * @since 3.0
1462 1119 *
1463 1120 * @param array|object $field
1464 - * @param string $is_type Options include radio, checkbox, text.
1121 + * @param string $is_type Options include radio, checkbox, text
1465 1122 *
1466 - * @return bool true if field type is checkbox or Dynamic checkbox
1123 + * @return boolean true if field type is checkbox or Dynamic checkbox
1467 1124 */
1468 1125 public static function is_field_type( $field, $is_type ) {
1469 1126 $field_type = self::get_original_field_type( $field );
1470 1127 $data_type = self::get_option( $field, 'data_type' );