PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.5.3
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.5.3
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/helpers/FrmAppHelper.php +796 -2154 6.355.5.3 View file →
@@ -3,43 +3,27 @@
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 6 class FrmAppHelper {
7 + public static $db_version = 98; // Version of the database we are moving to.
8 + public static $pro_db_version = 37; //deprecated
9 + public static $font_version = 7;
7 10
8 11 /**
9 - * Version of the database we are moving to.
10 - *
11 - * @var int
12 + * @var bool $added_gmt_offset_filter
12 13 */
13 - public static $db_version = 106;
14 -
15 - /**
16 - * Used by the API add-on.
17 - *
18 - * @var float
19 - */
20 - public static $font_version = 7;
21 -
22 - /**
23 - * @var bool
24 - */
25 14 private static $added_gmt_offset_filter = false;
26 15
27 16 /**
28 17 * @since 2.0
29 - *
30 - * @var string
31 18 */
32 - public static $plug_version = '6.35';
19 + public static $plug_version = '5.5.2';
33 20
34 21 /**
35 - * @var bool
36 - */
37 - private static $included_svg = false;
38 -
39 - /**
40 22 * @since 1.07.02
41 23 *
24 + * @param none
25 + *
42 26 * @return string The version of this plugin
43 27 */
44 28 public static function plugin_version() {
45 29 return self::$plug_version;
@@ -44,33 +28,21 @@
44 28 public static function plugin_version() {
45 29 return self::$plug_version;
46 30 }
47 31
48 - /**
49 - * @return string
50 - */
51 32 public static function plugin_folder() {
52 33 return basename( self::plugin_path() );
53 34 }
54 35
55 - /**
56 - * @return string
57 - */
58 36 public static function plugin_path() {
59 - return dirname( __DIR__, 2 );
37 + return dirname( dirname( dirname( __FILE__ ) ) );
60 38 }
61 39
62 - /**
63 - * @return string
64 - */
65 40 public static function plugin_url() {
66 - // Previously FRM_URL constant.
41 + // Prevously FRM_URL constant.
67 42 return plugins_url( '', self::plugin_path() . '/formidable.php' );
68 43 }
69 44
70 - /**
71 - * @return string
72 - */
73 45 public static function relative_plugin_url() {
74 46 return str_replace( array( 'https:', 'http:' ), '', self::plugin_url() );
75 47 }
76 48
@@ -85,9 +57,8 @@
85 57 * Get the name of this site
86 58 * Used for [sitename] shortcode
87 59 *
88 60 * @since 2.0
89 - *
90 61 * @return string
91 62 */
92 63 public static function site_name() {
93 64 return get_option( 'blogname' );
@@ -92,17 +63,11 @@
92 63 public static function site_name() {
93 64 return get_option( 'blogname' );
94 65 }
95 66
96 - /**
97 - * @param string $url
98 - *
99 - * @return string
100 - */
101 67 public static function make_affiliate_url( $url ) {
102 68 $affiliate_id = self::get_affiliate();
103 -
104 - if ( $affiliate_id ) {
69 + if ( ! empty( $affiliate_id ) ) {
105 70 $url = str_replace( array( 'http://', 'https://' ), '', $url );
106 71 $url = 'http://www.shareasale.com/r.cfm?u=' . absint( $affiliate_id ) . '&b=841990&m=64739&afftrack=plugin&urllink=' . urlencode( $url );
107 72 }
108 73
@@ -108,11 +73,8 @@
108 73
109 74 return $url;
110 75 }
111 76
112 - /**
113 - * @return int
114 - */
115 77 public static function get_affiliate() {
116 78 return absint( apply_filters( 'frm_affiliate_id', 0 ) );
117 79 }
118 80
@@ -117,167 +79,65 @@
117 79 }
118 80
119 81 /**
120 82 * @since 3.04.02
121 - *
122 - * @param array|string $args If a string is passed, it is used for the utm_campaign attribute.
83 + * @param array|string $args
123 84 * @param string $page
124 85 */
125 86 public static function admin_upgrade_link( $args, $page = '' ) {
126 - if ( $page ) {
87 + if ( empty( $page ) ) {
88 + $page = 'https://formidableforms.com/lite-upgrade/';
89 + } else {
127 90 $page = str_replace( 'https://formidableforms.com/', '', $page );
128 91 $page = 'https://formidableforms.com/' . $page;
92 + }
93 +
94 + $anchor = '';
95 + if ( is_array( $args ) ) {
96 + $medium = $args['medium'];
97 + if ( isset( $args['content'] ) ) {
98 + $content = $args['content'];
99 + }
100 + if ( isset( $args['anchor'] ) ) {
101 + $anchor = '#' . $args['anchor'];
102 + }
129 103 } else {
130 - $page = 'https://formidableforms.com/lite-upgrade/';
104 + $medium = $args;
131 105 }
132 106
133 - $args = is_array( $args ) ? self::adjust_legacy_utm_args( $args ) : array( 'campaign' => $args );
134 -
135 107 $query_args = array(
136 - 'utm_source' => 'plugin',
137 - 'utm_medium' => self::get_utm_medium(),
108 + 'utm_source' => 'WordPress',
109 + 'utm_medium' => $medium,
110 + 'utm_campaign' => 'liteplugin',
138 111 );
139 - $query_args = self::maybe_add_utm_license( $query_args );
140 112
141 - if ( isset( $args['campaign'] ) ) {
142 - $query_args['utm_campaign'] = $args['campaign'];
113 + if ( isset( $content ) ) {
114 + $query_args['utm_content'] = $content;
143 115 }
144 116
145 - if ( isset( $args['content'] ) ) {
146 - $query_args['utm_content'] = $args['content'];
147 - }
148 -
149 - if ( isset( $args['param'] ) ) {
117 + if ( is_array( $args ) && isset( $args['param'] ) ) {
150 118 $query_args['f'] = $args['param'];
151 119 }
152 120
153 - if ( ! empty( $args['plan'] ) ) {
121 + if ( is_array( $args ) && ! empty( $args['plan'] ) ) {
154 122 $query_args['plan'] = $args['plan'];
155 123 }
156 124
157 - $link = add_query_arg( $query_args, $page );
158 -
159 - if ( isset( $args['anchor'] ) ) {
160 - $link .= '#' . $args['anchor'];
161 - }
162 -
125 + $link = add_query_arg( $query_args, $page ) . $anchor;
163 126 return self::make_affiliate_url( $link );
164 127 }
165 128
166 129 /**
167 - * If medium is "pro", add an additional utm_license param with their active license type.
168 - *
169 - * @since 6.25.1
170 - *
171 - * @param array $query_args
172 - * @param string $link
173 - *
174 - * @return array
175 - */
176 - private static function maybe_add_utm_license( $query_args, $link = '' ) {
177 - $medium = $query_args['utm_medium'] ?? self::pull_medium_from_link( $link );
178 -
179 - if ( 'pro' === $medium && is_callable( 'FrmProAddonsController::get_readable_license_type' ) ) {
180 - $query_args['utm_license'] = strtolower( FrmProAddonsController::get_readable_license_type() );
181 - }
182 -
183 - return $query_args;
184 - }
185 -
186 - /**
187 - * @since 6.26
188 - *
189 - * @param string $link
190 - *
191 - * @return string
192 - */
193 - private static function pull_medium_from_link( $link ) {
194 - if ( ! $link ) {
195 - return '';
196 - }
197 -
198 - $parsed = parse_url( $link );
199 -
200 - if ( ! is_array( $parsed ) || ! isset( $parsed['query'] ) ) {
201 - return '';
202 - }
203 -
204 - $query_args = wp_parse_args( $parsed['query'] );
205 -
206 - return ! empty( $query_args['utm_medium'] ) ? $query_args['utm_medium'] : '';
207 - }
208 -
209 - /**
210 - * @since 6.25.1
211 - *
212 - * @return string
213 - */
214 - private static function get_utm_medium() {
215 - return self::pro_is_connected() ? 'pro' : 'lite';
216 - }
217 -
218 - /**
219 - * Change campaign from "liteplugin" to what we're currently using for medium.
220 - *
221 - * @since 6.25.1
222 - *
223 - * @param array $args
224 - *
225 - * @return array
226 - */
227 - private static function adjust_legacy_utm_args( $args ) {
228 - if ( isset( $args['medium'] ) ) {
229 - $args['campaign'] = $args['medium'];
230 - unset( $args['medium'] );
231 - }
232 -
233 - return $args;
234 - }
235 -
236 - /**
237 - * @since 6.21
238 - *
239 - * @param string $cta_link
240 - * @param array $utm
241 - */
242 - public static function maybe_add_missing_utm( $cta_link, $utm ) {
243 - $utm = self::adjust_legacy_utm_args( $utm );
244 - $query_args = array();
245 -
246 - if ( ! str_contains( $cta_link, 'utm_source' ) ) {
247 - $query_args['utm_source'] = 'plugin';
248 - }
249 -
250 - if ( ! str_contains( $cta_link, 'utm_medium' ) ) {
251 - $query_args['utm_medium'] = self::get_utm_medium();
252 - }
253 -
254 - if ( ! str_contains( $cta_link, 'utm_campaign' ) && isset( $utm['campaign'] ) ) {
255 - $query_args['utm_campaign'] = $utm['campaign'];
256 - }
257 -
258 - if ( ! str_contains( $cta_link, 'utm_content' ) && isset( $utm['content'] ) ) {
259 - $query_args['utm_content'] = $utm['content'];
260 - }
261 -
262 - $query_args = self::maybe_add_utm_license( $query_args, $cta_link );
263 -
264 - return $query_args ? add_query_arg( $query_args, $cta_link ) : $cta_link;
265 - }
266 -
267 - /**
268 130 * Get the Formidable settings
269 131 *
270 132 * @since 2.0
271 133 *
272 134 * @param array $args - May include the form id when values need translation.
273 - *
274 - * @return FrmSettings
135 + * @return FrmSettings $frm_setings
275 136 */
276 137 public static function get_settings( $args = array() ) {
277 138 global $frm_settings;
278 -
279 - if ( ! $frm_settings ) {
139 + if ( empty( $frm_settings ) ) {
280 140 $frm_settings = new FrmSettings( $args );
281 141 } elseif ( isset( $args['current_form'] ) ) {
282 142 // If the global has already been set, allow strings to be filtered.
283 143 $frm_settings->maybe_filter_for_form( $args );
@@ -285,41 +145,16 @@
285 145
286 146 return $frm_settings;
287 147 }
288 148
289 - /**
290 - * @return string
291 - */
292 149 public static function get_menu_name() {
293 - if ( ! self::pro_is_installed() || FrmAddonsController::is_license_expired() ) {
294 - return 'Formidable';
295 - }
150 + $frm_settings = self::get_settings();
296 151
297 - return self::get_settings()->menu;
152 + return $frm_settings->menu;
298 153 }
299 154
300 155 /**
301 - * Determine if the current branding is set to 'formidable'.
302 - * Checks the menu icon, and verifies if it matches the formidable branding.
303 - *
304 - * @since 6.4.2
305 - *
306 - * @return bool True if the menu icon is the logo, false otherwise.
307 - */
308 - public static function is_formidable_branding() {
309 - if ( ! self::pro_is_installed() ) {
310 - return true;
311 - }
312 -
313 - return str_contains( self::get_menu_icon_class(), 'frm_logo_icon' );
314 - }
315 -
316 - /**
317 156 * @since 3.05
318 - *
319 - * @param array $atts
320 - *
321 - * @return string
322 157 */
323 158 public static function svg_logo( $atts = array() ) {
324 159 $defaults = array(
325 160 'height' => 18,
@@ -328,31 +163,23 @@
328 163 'orange' => '#f05a24',
329 164 );
330 165 $atts = array_merge( $defaults, $atts );
331 166
332 - // phpcs:disable SlevomatCodingStandard.Files.LineLength.LineTooLong
333 167 return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 599.68 601.37" width="' . esc_attr( $atts['width'] ) . '" height="' . esc_attr( $atts['height'] ) . '">
334 168 <path fill="' . esc_attr( $atts['orange'] ) . '" d="M289.6 384h140v76h-140z"/>
335 169 <path fill="' . esc_attr( $atts['fill'] ) . '" d="M400.2 147h-200c-17 0-30.6 12.2-30.6 29.3V218h260v-71zM397.9 264H169.6v196h75V340H398a32.2 32.2 0 0 0 30.1-21.4 24.3 24.3 0 0 0 1.7-8.7V264zM299.8 601.4A300.3 300.3 0 0 1 0 300.7a299.8 299.8 0 1 1 511.9 212.6 297.4 297.4 0 0 1-212 88zm0-563A262 262 0 0 0 38.3 300.7a261.6 261.6 0 1 0 446.5-185.5 259.5 259.5 0 0 0-185-76.8z"/>
336 170 </svg>';
337 - // phpcs:enable SlevomatCodingStandard.Files.LineLength.LineTooLong
338 171 }
339 172
340 173 /**
341 174 * @since 4.0
342 - *
343 - * @param array $atts
344 - *
345 - * @return void
346 175 */
347 176 public static function show_logo( $atts = array() ) {
348 - self::kses_echo( self::svg_logo( $atts ), 'all' );
177 + echo self::kses( self::svg_logo( $atts ), 'all' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
349 178 }
350 179
351 180 /**
352 181 * @since 4.03.02
353 - *
354 - * @return void
355 182 */
356 183 public static function show_header_logo() {
357 184 $icon = self::svg_logo(
358 185 array(
@@ -361,11 +188,10 @@
361 188 )
362 189 );
363 190
364 191 $new_icon = apply_filters( 'frm_icon', $icon, true );
365 -
366 192 if ( $new_icon !== $icon ) {
367 - if ( str_starts_with( $new_icon, '<svg' ) ) {
193 + if ( strpos( $new_icon, '<svg' ) === 0 ) {
368 194 $icon = str_replace( 'viewBox="0 0 20', 'width="30" height="35" style="color:#929699" viewBox="0 0 20', $new_icon );
369 195 } else {
370 196 // Show nothing if it isn't an SVG.
371 197 $icon = '<div style="height:39px"></div>';
@@ -370,43 +196,26 @@
370 196 // Show nothing if it isn't an SVG.
371 197 $icon = '<div style="height:39px"></div>';
372 198 }
373 199 }
374 - self::kses_echo( $icon, 'all' );
200 + echo self::kses( $icon, 'all' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
375 201 }
376 202
377 203 /**
378 204 * @since 2.02.04
379 - *
380 - * @return bool
381 205 */
382 206 public static function ips_saved() {
383 207 $frm_settings = self::get_settings();
208 +
384 209 return ! $frm_settings->no_ips;
385 210 }
386 211
387 - /**
388 - * @return bool
389 - */
390 212 public static function pro_is_installed() {
391 - return (bool) apply_filters( 'frm_pro_installed', false );
213 + return apply_filters( 'frm_pro_installed', false );
392 214 }
393 215
394 216 /**
395 - * Check if the Pro plugin is installed, whether authorized or not.
396 - *
397 - * @since 6.8.3
398 - *
399 - * @return bool
400 - */
401 - public static function pro_is_included() {
402 - return function_exists( 'load_formidable_pro' );
403 - }
404 -
405 - /**
406 217 * @since 4.06.02
407 - *
408 - * @return bool
409 218 */
410 219 public static function pro_is_connected() {
411 220 global $frm_vars;
412 221 return self::pro_is_installed() && $frm_vars['pro_is_authorized'];
@@ -413,100 +222,45 @@
413 222 }
414 223
415 224 /**
416 225 * @since 4.06
417 - * @since 6.16.2 Added $check_for_settings parameter
418 - *
419 - * @param bool $check_for_settings
420 - *
421 - * @return bool
422 226 */
423 - public static function is_form_builder_page( $check_for_settings = true ) {
424 - $action = self::simple_get( 'frm_action', 'sanitize_title' );
425 - $check_actions = array( 'edit', 'duplicate' );
426 -
427 - if ( $check_for_settings ) {
428 - $check_actions[] = 'settings';
429 - }
430 -
431 - return self::is_admin_page( 'formidable' ) && in_array( $action, $check_actions, true );
227 + public static function is_form_builder_page() {
228 + $action = self::simple_get( 'frm_action', 'sanitize_title' );
229 + return self::is_admin_page( 'formidable' ) && ( $action === 'edit' || $action === 'settings' || $action === 'duplicate' );
432 230 }
433 231
434 - /**
435 - * @return bool
436 - */
437 232 public static function is_formidable_admin() {
438 - $page = self::simple_get( 'page', 'sanitize_title' );
439 -
440 - if ( ! $page ) {
441 - return self::is_view_builder_page();
233 + $page = self::simple_get( 'page', 'sanitize_title' );
234 + $is_formidable = strpos( $page, 'formidable' ) !== false;
235 + if ( empty( $page ) ) {
236 + $is_formidable = self::is_view_builder_page();
442 237 }
443 238
444 - return str_contains( $page, 'formidable' );
239 + return $is_formidable;
445 240 }
446 241
447 242 /**
448 - * Checks if is a list page.
449 - *
450 - * @since 6.19
451 - *
452 - * @param string $page The name of the page to check.
453 - *
454 - * @return bool
455 - */
456 - public static function is_admin_list_page( $page = 'formidable' ) {
457 - if ( 'formidable' === $page ) {
458 - return self::on_form_listing_page();
459 - }
460 -
461 - if ( ! self::is_admin_page( $page ) ) {
462 - return false;
463 - }
464 -
465 - if ( 'formidable-entries' === $page ) {
466 - $action = self::simple_get( 'frm_action' );
467 -
468 - if ( ! $action || in_array( $action, self::get_entries_listing_page_form_actions(), true ) ) {
469 - return true;
470 - }
471 - }
472 -
473 - // Check edit or settings page.
474 - return ! self::simple_get( 'frm_action' );
475 - }
476 -
477 - /**
478 - * @since 6.20
479 - *
480 - * @return array<string>
481 - */
482 - private static function get_entries_listing_page_form_actions() {
483 - return array( 'list', 'destroy' );
484 - }
485 -
486 - /**
487 243 * Check for certain page in Formidable settings
488 244 *
489 245 * @since 2.0
490 246 *
491 - * @param string $page The name of the page to check.
247 + * @param string $page The name of the page to check
492 248 *
493 - * @return bool
249 + * @return boolean
494 250 */
495 251 public static function is_admin_page( $page = 'formidable' ) {
496 252 global $pagenow;
497 253 $get_page = self::simple_get( 'page', 'sanitize_title' );
498 -
499 254 if ( $pagenow ) {
500 - // Allow this to be true during ajax load i.e. ajax form builder loading
501 - $is_page = ( $pagenow === 'admin.php' || $pagenow === 'admin-ajax.php' ) && $get_page === $page;
502 -
255 + // allow this to be true during ajax load i.e. ajax form builder loading
256 + $is_page = ( $pagenow == 'admin.php' || $pagenow == 'admin-ajax.php' ) && $get_page == $page;
503 257 if ( $is_page ) {
504 258 return true;
505 259 }
506 260 }
507 261
508 - return is_admin() && $get_page === $page;
262 + return is_admin() && $get_page == $page;
509 263 }
510 264
511 265 /**
512 266 * If the current page is for editing or creating a view.
@@ -512,23 +266,21 @@
512 266 * If the current page is for editing or creating a view.
513 267 * Returns false for the views listing page.
514 268 *
515 269 * @since 4.0
516 - *
517 - * @return bool
518 270 */
519 271 public static function is_view_builder_page() {
520 272 global $pagenow;
521 273
522 - if ( ! in_array( $pagenow, array( 'post.php', 'post-new.php', 'edit.php' ), true ) ) {
274 + if ( $pagenow !== 'post.php' && $pagenow !== 'post-new.php' && $pagenow !== 'edit.php' ) {
523 275 return false;
524 276 }
525 277
526 278 $post_type = self::simple_get( 'post_type', 'sanitize_title' );
527 279
528 - if ( ! $post_type ) {
529 - $post_id = self::simple_get( 'post', 'absint' );
530 - $post = get_post( $post_id );
280 + if ( empty( $post_type ) ) {
281 + $post_id = self::simple_get( 'post', 'absint' );
282 + $post = get_post( $post_id );
531 283 $post_type = $post ? $post->post_type : '';
532 284 }
533 285
534 286 return $post_type === 'frm_display';
@@ -538,15 +290,17 @@
538 290 * Check for the form preview page
539 291 *
540 292 * @since 2.0
541 293 *
542 - * @return bool
294 + * @param None
295 + *
296 + * @return boolean
543 297 */
544 298 public static function is_preview_page() {
545 299 global $pagenow;
546 300 $action = self::simple_get( 'action', 'sanitize_title' );
547 301
548 - return $pagenow === 'admin-ajax.php' && $action === 'frm_forms_preview';
302 + return $pagenow && $pagenow == 'admin-ajax.php' && $action == 'frm_forms_preview';
549 303 }
550 304
551 305 /**
552 306 * Check for ajax except the form preview page
@@ -552,17 +306,16 @@
552 306 * Check for ajax except the form preview page
553 307 *
554 308 * @since 2.0
555 309 *
556 - * @return bool
310 + * @param None
311 + *
312 + * @return boolean
557 313 */
558 314 public static function doing_ajax() {
559 315 return wp_doing_ajax() && ! self::is_preview_page();
560 316 }
561 317
562 - /**
563 - * @return string
564 - */
565 318 public static function js_suffix() {
566 319 return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
567 320 }
568 321
@@ -567,14 +320,13 @@
567 320 }
568 321
569 322 /**
570 323 * @since 2.0.8
571 - *
572 - * @return bool
573 324 */
574 325 public static function prevent_caching() {
575 326 global $frm_vars;
576 - return ! empty( $frm_vars['prevent_caching'] );
327 +
328 + return isset( $frm_vars['prevent_caching'] ) && $frm_vars['prevent_caching'];
577 329 }
578 330
579 331 /**
580 332 * Check if on an admin page
@@ -580,19 +332,14 @@
580 332 * Check if on an admin page
581 333 *
582 334 * @since 2.0
583 335 *
584 - * @return bool
336 + * @param None
337 + *
338 + * @return boolean
585 339 */
586 340 public static function is_admin() {
587 - $is_admin = is_admin() && ! wp_doing_ajax();
588 -
589 - /**
590 - * @since 6.0
591 - *
592 - * @param bool $is_admin
593 - */
594 - return apply_filters( 'frm_is_admin', $is_admin );
341 + return is_admin() && ! wp_doing_ajax();
595 342 }
596 343
597 344 /**
598 345 * Check if value contains blank value or empty array
@@ -598,23 +345,17 @@
598 345 * Check if value contains blank value or empty array
599 346 *
600 347 * @since 2.0
601 348 *
602 - * @param mixed $value Value to check.
603 - * @param string $empty
349 + * @param mixed $value - value to check
350 + * @param string
604 351 *
605 - * @return bool
352 + * @return boolean
606 353 */
607 354 public static function is_empty_value( $value, $empty = '' ) {
608 - return $value === array() || $value === $empty;
355 + return ( is_array( $value ) && empty( $value ) ) || $value === $empty;
609 356 }
610 357
611 - /**
612 - * @param mixed $value
613 - * @param string $empty
614 - *
615 - * @return bool
616 - */
617 358 public static function is_not_empty_value( $value, $empty = '' ) {
618 359 return ! self::is_empty_value( $value, $empty );
619 360 }
620 361
@@ -631,37 +372,26 @@
631 372 return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( wp_unslash( $_SERVER[ $value ] ) ) : '';
632 373 }
633 374
634 375 /**
635 - * Get the server OS
376 + * Check for the IP address in several places
377 + * Used by [ip] shortcode
636 378 *
637 - * @since 6.4.2
638 - *
639 - * @return string
640 - */
641 - public static function get_server_os() {
642 - if ( function_exists( 'php_uname' ) ) {
643 - return php_uname( 's' );
644 - }
645 -
646 - if ( ! defined( 'PHP_OS' ) ) {
647 - return '';
648 - }
649 -
650 - // match the same response for Windows server as php_uname('s')
651 - return in_array( PHP_OS, array( 'WIN32', 'WINNT', 'Windows_NT' ), true ) ? 'Windows NT' : PHP_OS;
652 - }
653 -
654 - /**
655 - * Check for the IP address in several places (when custom headers are enabled).
656 - * Used by [ip] shortcode.
657 - *
658 379 * @return string The IP address of the current user
659 380 */
660 381 public static function get_ip_address() {
661 - $ip_options = self::should_use_custom_header_ip() ? self::get_custom_header_keys_for_ip() : array( 'REMOTE_ADDR' );
662 - $ip = '';
663 -
382 + $ip_options = array(
383 + 'HTTP_CLIENT_IP',
384 + 'HTTP_CF_CONNECTING_IP',
385 + 'HTTP_X_FORWARDED_FOR',
386 + 'HTTP_X_FORWARDED',
387 + 'HTTP_X_CLUSTER_CLIENT_IP',
388 + 'HTTP_X_REAL_IP',
389 + 'HTTP_FORWARDED_FOR',
390 + 'HTTP_FORWARDED',
391 + 'REMOTE_ADDR',
392 + );
393 + $ip = '';
664 394 foreach ( $ip_options as $key ) {
665 395 if ( ! isset( $_SERVER[ $key ] ) ) {
666 396 continue;
667 397 }
@@ -666,12 +396,10 @@
666 396 continue;
667 397 }
668 398
669 399 $key = self::get_server_value( $key );
670 -
671 400 foreach ( explode( ',', $key ) as $ip ) {
672 - // Just to be safe.
673 - $ip = trim( $ip );
401 + $ip = trim( $ip ); // just to be safe.
674 402
675 403 if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false ) {
676 404 return sanitize_text_field( $ip );
677 405 }
@@ -680,70 +408,16 @@
680 408
681 409 return sanitize_text_field( $ip );
682 410 }
683 411
684 - /**
685 - * @since 6.1
686 - *
687 - * @return array
688 - */
689 - public static function get_custom_header_keys_for_ip() {
690 - return array(
691 - 'HTTP_CLIENT_IP',
692 - 'HTTP_CF_CONNECTING_IP',
693 - 'HTTP_X_FORWARDED_FOR',
694 - 'HTTP_X_FORWARDED',
695 - 'HTTP_X_CLUSTER_CLIENT_IP',
696 - 'HTTP_X_REAL_IP',
697 - 'HTTP_FORWARDED_FOR',
698 - 'HTTP_FORWARDED',
699 - 'REMOTE_ADDR',
700 - );
701 - }
702 -
703 - /**
704 - * Check if we should check every HTTP header or just $_SERVER['REMOTE_ADDR'].
705 - * The other HTTP headers can be spoofed so this isn't recommended.
706 - * But in some cases (like reverse proxies), the IP may be empty if you use $_SERVER['REMOTE_ADDR'].
707 - *
708 - * @since 6.1
709 - *
710 - * @return bool
711 - */
712 - private static function should_use_custom_header_ip() {
713 - $settings = self::get_settings();
714 - $should_use_custom_header_ip = ! $settings->no_ips && $settings->custom_header_ip;
715 -
716 - /**
717 - * Filter whether to check spoofable HTTP headers.
718 - * This uses the custom_header_ip setting, but it is hidden if the GDPR option is also on.
719 - * As the IP is still checked for blacklist checks, someone with the GDPR option may still want to enable this when behind a reverse proxy.
720 - *
721 - * @since 6.1
722 - *
723 - * @param bool $should_use_custom_header_ip
724 - */
725 - return apply_filters( 'frm_use_custom_header_ip', $should_use_custom_header_ip );
726 - }
727 -
728 - /**
729 - * @param string $param
730 - * @param mixed $default
731 - * @param string $src
732 - * @param callable|string $sanitize
733 - *
734 - * @return mixed
735 - */
736 412 public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) {
737 - if ( str_contains( $param, '[' ) ) {
413 + if ( strpos( $param, '[' ) ) {
738 414 $params = explode( '[', $param );
739 415 $param = $params[0];
740 416 }
741 417
742 418 if ( $src === 'get' ) {
743 - // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
744 - $value = isset( $_POST[ $param ] ) ? wp_unslash( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? wp_unslash( $_GET[ $param ] ) : $default );
745 -
419 + $value = isset( $_POST[ $param ] ) ? wp_unslash( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? wp_unslash( $_GET[ $param ] ) : $default ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
746 420 if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
747 421 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
748 422 $value = htmlspecialchars_decode( wp_unslash( $_GET[ $param ] ) );
749 423 }
@@ -758,41 +432,29 @@
758 432 )
759 433 );
760 434 }
761 435
762 - if ( ! isset( $params ) || ! is_array( $value ) || ! $value ) {
763 - return $value;
764 - }
436 + if ( isset( $params ) && is_array( $value ) && ! empty( $value ) ) {
437 + foreach ( $params as $k => $p ) {
438 + if ( ! $k || ! is_array( $value ) ) {
439 + continue;
440 + }
765 441
766 - foreach ( $params as $k => $p ) {
767 - if ( ! $k || ! is_array( $value ) ) {
768 - continue;
442 + $p = trim( $p, ']' );
443 + $value = isset( $value[ $p ] ) ? $value[ $p ] : $default;
769 444 }
770 -
771 - $p = trim( $p, ']' );
772 - $value = $value[ $p ] ?? $default;
773 445 }
774 446
775 447 return $value;
776 448 }
777 449
778 - /**
779 - * Get a value from $_POST data.
780 - *
781 - * @param string $param The key we are trying to access data from in $_POST.
782 - * @param mixed $default The default if nothing is being sent.
783 - * @param callable|string $sanitize Make sure to pass a sanitize method here. This function will NOT sanitize by default.
784 - * @param bool $serialized
785 - *
786 - * @return mixed
787 - */
788 450 public static function get_post_param( $param, $default = '', $sanitize = '', $serialized = false ) {
789 451 return self::get_simple_request(
790 452 array(
791 - 'type' => 'post',
792 - 'param' => $param,
793 - 'default' => $default,
794 - 'sanitize' => $sanitize,
453 + 'type' => 'post',
454 + 'param' => $param,
455 + 'default' => $default,
456 + 'sanitize' => $sanitize,
795 457 'serialized' => $serialized,
796 458 )
797 459 );
798 460 }
@@ -803,9 +465,9 @@
803 465 * @param string $param
804 466 * @param string $sanitize
805 467 * @param string $default
806 468 *
807 - * @return array|int|string
469 + * @return string|array
808 470 */
809 471 public static function simple_get( $param, $sanitize = 'sanitize_text_field', $default = '' ) {
810 472 return self::get_simple_request(
811 473 array(
@@ -823,38 +485,39 @@
823 485 * @since 2.0.6
824 486 *
825 487 * @param array $args
826 488 *
827 - * @return array|string
489 + * @return string|array
828 490 */
829 491 public static function get_simple_request( $args ) {
830 492 $defaults = array(
831 - 'param' => '',
832 - 'default' => '',
833 - 'type' => 'get',
834 - 'sanitize' => 'sanitize_text_field',
493 + 'param' => '',
494 + 'default' => '',
495 + 'type' => 'get',
496 + 'sanitize' => 'sanitize_text_field',
835 497 'serialized' => false,
836 498 );
837 499 $args = wp_parse_args( $args, $defaults );
838 - $value = $args['default'];
839 500
840 - if ( $args['type'] === 'get' ) {
501 + $value = $args['default'];
502 + if ( $args['type'] == 'get' ) {
841 503 if ( $_GET && isset( $_GET[ $args['param'] ] ) ) {
842 504 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
843 505 $value = wp_unslash( $_GET[ $args['param'] ] );
844 506 }
845 - } elseif ( $args['type'] === 'post' ) {
507 + } elseif ( $args['type'] == 'post' ) {
846 508 if ( isset( $_POST[ $args['param'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
847 509 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
848 510 $value = wp_unslash( $_POST[ $args['param'] ] );
849 -
850 511 if ( $args['serialized'] === true && is_serialized_string( $value ) && is_serialized( $value ) ) {
851 512 self::unserialize_or_decode( $value );
852 513 }
853 514 }
854 - } elseif ( isset( $_REQUEST[ $args['param'] ] ) ) {
855 - // phpcs:ignore phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
856 - $value = wp_unslash( $_REQUEST[ $args['param'] ] );
515 + } else {
516 + if ( isset( $_REQUEST[ $args['param'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
517 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
518 + $value = wp_unslash( $_REQUEST[ $args['param'] ] );
519 + }
857 520 }
858 521
859 522 self::sanitize_value( $args['sanitize'], $value );
860 523
@@ -867,56 +530,34 @@
867 530 * @since 2.0.8
868 531 *
869 532 * @param string $value
870 533 *
871 - * @return string Value.
534 + * @return string $value
872 535 */
873 536 public static function preserve_backslashes( $value ) {
874 537 // If backslashes have already been added, don't add them again
875 - return str_contains( $value, '\\\\' ) ? $value : addslashes( $value );
538 + if ( strpos( $value, '\\\\' ) === false ) {
539 + $value = addslashes( $value );
540 + }
541 +
542 + return $value;
876 543 }
877 544
878 - /**
879 - * Sanitize a value in-place.
880 - * If $value is an array, the sanitize function will get called for each item.
881 - *
882 - * @param callable $sanitize
883 - * @param mixed $value
884 - *
885 - * @return void
886 - */
887 545 public static function sanitize_value( $sanitize, &$value ) {
888 - if ( ! $sanitize ) {
889 - return;
890 - }
891 -
892 - if ( is_object( $value ) ) {
893 - $value = '';
894 - return;
895 - }
896 -
897 - if ( is_array( $value ) ) {
898 - $temp_values = $value;
899 -
900 - foreach ( $temp_values as $k => $v ) {
901 - self::sanitize_value( $sanitize, $value[ $k ] );
546 + if ( ! empty( $sanitize ) ) {
547 + if ( is_array( $value ) ) {
548 + $temp_values = $value;
549 + foreach ( $temp_values as $k => $v ) {
550 + self::sanitize_value( $sanitize, $value[ $k ] );
551 + }
552 + } else {
553 + $value = call_user_func( $sanitize, $value );
902 554 }
903 -
904 - return;
905 555 }
906 -
907 - $value = call_user_func( $sanitize, $value );
908 556 }
909 557
910 - /**
911 - * @param array $sanitize_method
912 - * @param array $values
913 - *
914 - * @return void
915 - */
916 558 public static function sanitize_request( $sanitize_method, &$values ) {
917 559 $temp_values = $values;
918 -
919 560 foreach ( $temp_values as $k => $val ) {
920 561 if ( isset( $sanitize_method[ $k ] ) ) {
921 562 $values[ $k ] = call_user_func( $sanitize_method[ $k ], $val );
922 563 }
@@ -924,69 +565,23 @@
924 565 }
925 566
926 567 /**
927 568 * @since 4.0.04
928 - *
929 - * @param mixed $value
930 - *
931 - * @return void
932 569 */
933 570 public static function sanitize_with_html( &$value ) {
934 - if ( current_user_can( 'frm_edit_entries' ) || current_user_can( 'administrator' ) ) {
935 - // Only strip unsafe HTML like scripts for a privileged user submitting a form.
936 - self::sanitize_value( 'wp_kses_post', $value );
937 - } else {
938 - self::sanitize_value( self::class . '::strip_most_html', $value );
939 - }
571 + self::sanitize_value( 'wp_kses_post', $value );
940 572 self::decode_specialchars( $value );
941 - self::sanitize_value( 'FrmHtmlSanitizer::sanitize_url_attributes', $value );
942 573 }
943 574
944 575 /**
945 - * Allow only a small set of very basic HTML for unprivileged users.
946 - *
947 - * @since 6.7.1
948 - *
949 - * @param string $value
950 - */
951 - public static function strip_most_html( $value ) {
952 - if ( '' === $value ) {
953 - return $value;
954 - }
955 -
956 - $allowed_html = array(
957 - 'b' => array(),
958 - 'br' => array(),
959 - 'strong' => array(),
960 - 'p' => array(),
961 - 'i' => array(),
962 - 'ul' => array(),
963 - 'ol' => array(),
964 - 'li' => array(),
965 - );
966 -
967 - /**
968 - * @since 6.7.1
969 - *
970 - * @param array $allowed_html
971 - */
972 - $allowed_html = apply_filters( 'frm_allowed_form_input_html', $allowed_html );
973 -
974 - return wp_kses( $value, $allowed_html );
975 - }
976 -
977 - /**
978 576 * Do wp_specialchars_decode to get back '&' that wp_kses_post might have turned to '&amp;'
979 577 * this MUST be done, else we'll be back to the '& entity' problem.
980 578 *
981 579 * @since 4.0.04
982 - *
983 - * @param mixed $value Value to decode, passed by reference.
984 580 */
985 581 public static function decode_specialchars( &$value ) {
986 582 if ( is_array( $value ) ) {
987 583 $temp_values = $value;
988 -
989 584 foreach ( $temp_values as $k => $v ) {
990 585 self::decode_specialchars( $value[ $k ] );
991 586 }
992 587 } else {
@@ -1000,13 +595,13 @@
1000 595 * Adapted from wp_specialchars_decode().
1001 596 *
1002 597 * @since 4.03.01
1003 598 *
1004 - * @param string $string The string to prep, passed by reference.
599 + * @param string $string The string to prep.
1005 600 */
1006 601 private static function decode_amp( &$string ) {
1007 602 // Don't bother if there are no entities - saves a lot of processing
1008 - if ( ! $string || ! str_contains( $string, '&' ) ) {
603 + if ( empty( $string ) || strpos( $string, '&' ) === false ) {
1009 604 return;
1010 605 }
1011 606
1012 607 $translation = array(
@@ -1012,12 +607,10 @@
1012 607 $translation = array(
1013 608 '&quot;' => '"',
1014 609 '&#034;' => '"',
1015 610 '&#x22;' => '"',
1016 - // The space preserves the HTML.
1017 - '&lt; ' => '< ',
1018 - // The space preserves the HTML.
1019 - '&#060; ' => '< ',
611 + '&lt; ' => '< ', // The space preserves the HTML.
612 + '&#060; ' => '< ', // The space preserves the HTML.
1020 613 '&gt;' => '>',
1021 614 '&#062;' => '>',
1022 615 '&amp;' => '&',
1023 616 '&#038;' => '&',
@@ -1044,29 +637,17 @@
1044 637 * Sanitize the value, and allow some HTML
1045 638 *
1046 639 * @since 2.0
1047 640 *
1048 - * @param string $value The value to sanitize.
1049 - * @param array|string $allowed Allowed HTML tags and attributes, or 'all' for defaults.
641 + * @param string $value
642 + * @param array|string $allowed 'all' for everything included as defaults
1050 643 *
1051 644 * @return string
1052 645 */
1053 646 public static function kses( $value, $allowed = array() ) {
1054 - return wp_kses( $value, self::allowed_html( $allowed ) );
1055 - }
647 + $allowed_html = self::allowed_html( $allowed );
1056 648
1057 - /**
1058 - * Sanitizes and echoes a given value.
1059 - *
1060 - * @since 6.18
1061 - *
1062 - * @param string $value The value to sanitize and output.
1063 - * @param array|string $allowed Allowed HTML tags and attributes.
1064 - *
1065 - * @return void
1066 - */
1067 - public static function kses_echo( $value, $allowed = array() ) {
1068 - echo self::kses( $value, $allowed ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
649 + return wp_kses( $value, $allowed_html );
1069 650 }
1070 651
1071 652 /**
1072 653 * The regular kses function strips [button_action] from submit button HTML.
@@ -1073,23 +654,21 @@
1073 654 *
1074 655 * @since 5.0.13
1075 656 *
1076 657 * @param string $html
1077 - *
1078 658 * @return string
1079 659 */
1080 660 public static function kses_submit_button( $html ) {
1081 - $included_button_action = str_contains( $html, '[button_action]' );
1082 - $included_back_hook = str_contains( $html, '[back_hook]' );
1083 - $included_draft_hook = str_contains( $html, '[draft_hook]' );
661 + $included_button_action = false !== strpos( $html, '[button_action]' );
662 + $included_back_hook = false !== strpos( $html, '[back_hook]' );
663 + $included_draft_hook = false !== strpos( $html, '[draft_hook]' );
1084 664 add_filter( 'safe_style_css', 'FrmAppHelper::allow_visibility_style' );
1085 665 add_filter( 'frm_striphtml_allowed_tags', 'FrmAppHelper::add_allowed_submit_button_tags' );
1086 666 $html = self::kses( $html, 'all' );
1087 667 remove_filter( 'safe_style_css', 'FrmAppHelper::allow_visibility_style' );
1088 668 remove_filter( 'frm_striphtml_allowed_tags', 'FrmAppHelper::add_allowed_submit_button_tags' );
1089 -
1090 669 if ( $included_button_action ) {
1091 - if ( str_contains( $html, '<input type="submit"' ) ) {
670 + if ( false !== strpos( $html, '<input type="submit"' ) ) {
1092 671 $pattern = '/(<input type="submit")([^>]*)(\/>)/';
1093 672 $html = preg_replace( $pattern, '$1$2[button_action] $3', $html, 1 );
1094 673 } else {
1095 674 $pattern = '/(<button)(.*)(class=")(.*)(frm_button_submit)(.*)(")(.*)([^>]+)(>)/';
@@ -1095,17 +674,14 @@
1095 674 $pattern = '/(<button)(.*)(class=")(.*)(frm_button_submit)(.*)(")(.*)([^>]+)(>)/';
1096 675 $html = preg_replace( $pattern, '$1$2$3$4$5$6$7 [button_action]$8$9$10', $html, 1 );
1097 676 }
1098 677 }
1099 -
1100 678 if ( $included_back_hook ) {
1101 679 $html = str_replace( 'class="frm_prev_page"', 'class="frm_prev_page" [back_hook]', $html );
1102 680 }
1103 -
1104 681 if ( $included_draft_hook ) {
1105 - return str_replace( 'class="frm_save_draft"', 'class="frm_save_draft" [draft_hook]', $html );
682 + $html = str_replace( 'class="frm_save_draft"', 'class="frm_save_draft" [draft_hook]', $html );
1106 683 }
1107 -
1108 684 return $html;
1109 685 }
1110 686
1111 687 /**
@@ -1111,9 +687,8 @@
1111 687 /**
1112 688 * @since 5.0.13
1113 689 *
1114 690 * @param array $allowed_attr
1115 - *
1116 691 * @return array
1117 692 */
1118 693 public static function allow_visibility_style( $allowed_attr ) {
1119 694 $allowed_attr[] = 'visibility';
@@ -1123,9 +698,8 @@
1123 698 /**
1124 699 * @since 5.0.13
1125 700 *
1126 701 * @param array $allowed_html
1127 - *
1128 702 * @return array
1129 703 */
1130 704 public static function add_allowed_submit_button_tags( $allowed_html ) {
1131 705 $allowed_html['input'] = array(
@@ -1142,22 +716,17 @@
1142 716 }
1143 717
1144 718 /**
1145 719 * @since 2.05.03
1146 - *
1147 - * @param array|string $allowed
1148 - *
1149 - * @return array
1150 720 */
1151 721 private static function allowed_html( $allowed ) {
1152 722 $html = self::safe_html();
1153 723 $allowed_html = array();
1154 -
1155 724 if ( $allowed === 'all' ) {
1156 725 $allowed_html = $html;
1157 - } elseif ( $allowed ) {
726 + } elseif ( ! empty( $allowed ) ) {
1158 727 foreach ( (array) $allowed as $a ) {
1159 - $allowed_html[ $a ] = $html[ $a ] ?? array();
728 + $allowed_html[ $a ] = isset( $html[ $a ] ) ? $html[ $a ] : array();
1160 729 }
1161 730 }
1162 731
1163 732 return apply_filters( 'frm_striphtml_allowed_tags', $allowed_html );
@@ -1164,10 +733,8 @@
1164 733 }
1165 734
1166 735 /**
1167 736 * @since 2.05.03
1168 - *
1169 - * @return array
1170 737 */
1171 738 private static function safe_html() {
1172 739 $allow_class = array(
1173 740 'class' => true,
@@ -1174,9 +741,9 @@
1174 741 'id' => true,
1175 742 );
1176 743
1177 744 return array(
1178 - 'a' => array(
745 + 'a' => array(
1179 746 'class' => true,
1180 747 'href' => true,
1181 748 'id' => true,
1182 749 'rel' => true,
@@ -1245,16 +812,16 @@
1245 812 'cite' => true,
1246 813 'title' => true,
1247 814 ),
1248 815 'rect' => array(
1249 - 'class' => true,
1250 - 'fill' => true,
1251 - 'height' => true,
1252 - 'width' => true,
1253 - 'x' => true,
1254 - 'y' => true,
1255 - 'rx' => true,
1256 - 'stroke' => true,
816 + 'class' => true,
817 + 'fill' => true,
818 + 'height' => true,
819 + 'width' => true,
820 + 'x' => true,
821 + 'y' => true,
822 + 'rx' => true,
823 + 'stroke' => true,
1257 824 'stroke-opacity' => true,
1258 825 'stroke-width' => true,
1259 826 ),
1260 827 'section' => $allow_class,
@@ -1289,9 +856,9 @@
1289 856 'xlink:href' => true,
1290 857 ),
1291 858 'ul' => $allow_class,
1292 859 'label' => array(
1293 - 'for' => true,
860 + 'for' => true,
1294 861 'class' => true,
1295 862 'id' => true,
1296 863 ),
1297 864 'button' => array(
@@ -1300,13 +867,8 @@
1300 867 ),
1301 868 'legend' => array(
1302 869 'class' => true,
1303 870 ),
1304 - 'option' => array(
1305 - 'class' => true,
1306 - 'value' => true,
1307 - 'selected' => true,
1308 - ),
1309 871 );
1310 872 }
1311 873
1312 874 /**
@@ -1314,21 +876,19 @@
1314 876 *
1315 877 * @since 2.0
1316 878 */
1317 879 public static function remove_get_action() {
1318 - if ( empty( $_GET ) ) {
880 + if ( ! isset( $_GET ) ) {
1319 881 return;
1320 882 }
1321 883
1322 884 $action_name = isset( $_GET['action'] ) ? 'action' : ( isset( $_GET['action2'] ) ? 'action2' : '' );
1323 -
1324 - if ( ! $action_name ) {
885 + if ( empty( $action_name ) ) {
1325 886 return;
1326 887 }
1327 888
1328 889 $new_action = self::get_param( $action_name, '', 'get', 'sanitize_text_field' );
1329 -
1330 - if ( $new_action ) {
890 + if ( ! empty( $new_action ) ) {
1331 891 $_SERVER['REQUEST_URI'] = str_replace( '&action=' . $new_action, '', self::get_server_value( 'REQUEST_URI' ) );
1332 892 }
1333 893 }
1334 894
@@ -1335,23 +895,21 @@
1335 895 /**
1336 896 * Check the WP query for a parameter
1337 897 *
1338 898 * @since 2.0
1339 - *
1340 - * @param array|string $value
1341 - * @param string $param
1342 - *
1343 - * @return array|string
899 + * @return string|array
1344 900 */
1345 901 public static function get_query_var( $value, $param ) {
1346 - // phpcs:ignore Universal.Operators.StrictComparisons
1347 902 if ( $value != '' ) {
1348 903 return $value;
1349 904 }
1350 905
1351 906 global $wp_query;
907 + if ( isset( $wp_query->query_vars[ $param ] ) ) {
908 + $value = $wp_query->query_vars[ $param ];
909 + }
1352 910
1353 - return $wp_query->query_vars[ $param ] ?? $value;
911 + return $value;
1354 912 }
1355 913
1356 914 /**
1357 915 * Try to show the SVG if possible. Otherwise, use the font icon.
@@ -1356,82 +914,38 @@
1356 914 /**
1357 915 * Try to show the SVG if possible. Otherwise, use the font icon.
1358 916 *
1359 917 * @since 4.0.02
1360 - *
1361 918 * @param string $class
1362 919 * @param array $atts
1363 - *
1364 - * @return string|null
1365 920 */
1366 921 public static function icon_by_class( $class, $atts = array() ) {
1367 922 $echo = ! isset( $atts['echo'] ) || $atts['echo'];
1368 -
1369 923 if ( isset( $atts['echo'] ) ) {
1370 924 unset( $atts['echo'] );
1371 925 }
1372 926
927 + $html_atts = self::array_to_html_params( $atts );
928 +
1373 929 $icon = trim( str_replace( array( 'frm_icon_font', 'frmfont ' ), '', $class ) );
1374 -
1375 - // Replace icons that have been removed or renamed.
1376 - $deprecated = array(
1377 - 'frm_clone_solid_icon' => 'frm_clone_icon',
1378 - 'frm_keyalt_icon' => 'frm_key_icon',
1379 - 'frm_keyalt_solid_icon' => 'frm_key_solid_icon',
1380 - );
1381 -
1382 - if ( isset( $deprecated[ $icon ] ) ) {
1383 - $icon = $deprecated[ $icon ];
1384 - $class = str_replace( $icon, $deprecated[ $icon ], $class );
1385 - }
1386 -
1387 - $is_font_icon = $icon === $class;
1388 -
1389 - if ( ! $is_font_icon ) {
1390 - $class = str_contains( $icon, ' ' ) ? ' ' . $icon : '';
1391 -
1392 - if ( str_contains( $icon, ' ' ) ) {
930 + if ( $icon === $class ) {
931 + $icon = '<i class="' . esc_attr( $class ) . '"' . $html_atts . '></i>';
932 + } else {
933 + $class = strpos( $icon, ' ' ) === false ? '' : ' ' . $icon;
934 + if ( strpos( $icon, ' ' ) ) {
1393 935 $icon = explode( ' ', $icon );
1394 936 $icon = reset( $icon );
1395 937 }
938 + $icon = '<svg class="frmsvg' . esc_attr( $class ) . '"' . $html_atts . '>
939 + <use xlink:href="#' . esc_attr( $icon ) . '" />
940 + </svg>';
1396 941 }
1397 942
1398 - if ( $atts ) {
1399 - // A caller passed attributes, so kses still has to decide which of them survive. Its
1400 - // allowlist comes from safe_html() through the frm_striphtml_allowed_tags filter, and
1401 - // add-ons widen it around their own icons, so there is no fixed list to check against.
1402 - $html_atts = self::array_to_html_params( $atts );
1403 - $markup = $is_font_icon
1404 - ? '<i class="' . esc_attr( $class ) . '"' . $html_atts . '></i>'
1405 - : '<svg class="frmsvg' . esc_attr( $class ) . '"' . $html_atts . '><use href="#' . esc_attr( $icon ) . '" /></svg>';
1406 -
1407 - if ( ! $echo ) {
1408 - return $markup;
1409 - }
1410 -
1411 - echo self::kses_icon( $markup ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1412 - return null;
943 + if ( $echo ) {
944 + echo self::kses_icon( $icon ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
945 + } else {
946 + return $icon;
1413 947 }
1414 -
1415 - /**
1416 - * With no attributes from the caller, the tag is nothing but this method's own markup
1417 - * around an escaped class and icon id, so there is nothing left for kses to decide and it
1418 - * can be skipped. Echoing the pieces rather than a finished string keeps that safe to the
1419 - * escaping sniff without an annotation.
1420 - *
1421 - * This is the path the form builder takes for most of the tens of thousands of icons it
1422 - * renders on a large form, and the kses pass was most of what each one cost.
1423 - */
1424 - $callback = function () use ( $is_font_icon, $class, $icon ) {
1425 - if ( $is_font_icon ) {
1426 - echo '<i class="' . esc_attr( $class ) . '"></i>';
1427 - return;
1428 - }
1429 -
1430 - echo '<svg class="frmsvg' . esc_attr( $class ) . '"><use href="#' . esc_attr( $icon ) . '" /></svg>';
1431 - };
1432 -
1433 - return self::clip( $callback, $echo );
1434 948 }
1435 949
1436 950 /**
1437 951 * Run kses for icons. It needs to add a few filters first in order to preserve some custom style values.
@@ -1438,9 +952,8 @@
1438 952 *
1439 953 * @since 5.0.13
1440 954 *
1441 955 * @param string $icon
1442 - *
1443 956 * @return string
1444 957 */
1445 958 public static function kses_icon( $icon ) {
1446 959 add_filter( 'safe_style_css', 'FrmAppHelper::allow_vars_in_styles' );
@@ -1456,15 +969,13 @@
1456 969 /**
1457 970 * @since 5.0.13.1
1458 971 *
1459 972 * @param array $allowed_html
1460 - *
1461 973 * @return array
1462 974 */
1463 975 public static function add_allowed_icon_tags( $allowed_html ) {
1464 976 $allowed_html['svg']['data-open'] = true;
1465 977 $allowed_html['svg']['title'] = true;
1466 - $allowed_html['svg']['tabindex'] = true;
1467 978 return $allowed_html;
1468 979 }
1469 980
1470 981 /**
@@ -1470,13 +981,12 @@
1470 981 /**
1471 982 * @since 5.0.13
1472 983 *
1473 984 * @param array $allowed_attr
1474 - *
1475 985 * @return array
1476 986 */
1477 987 public static function allow_vars_in_styles( $allowed_attr ) {
1478 - $allowed_attr[] = '--primary-700';
988 + $allowed_attr[] = '--primary-hover';
1479 989 return $allowed_attr;
1480 990 }
1481 991
1482 992 /**
@@ -1485,9 +995,9 @@
1485 995 * @param bool $allow_css
1486 996 * @param string $css_string
1487 997 */
1488 998 public static function allow_style( $allow_css, $css_string ) {
1489 - if ( ! $allow_css && str_starts_with( $css_string, '--primary-700:' ) ) {
999 + if ( ! $allow_css && 0 === strpos( $css_string, '--primary-hover:' ) ) {
1490 1000 $split = explode( ':', $css_string, 2 );
1491 1001 $allow_css = 2 === count( $split ) && self::is_a_valid_color( $split[1] );
1492 1002 }
1493 1003 return $allow_css;
@@ -1496,22 +1006,19 @@
1496 1006 /**
1497 1007 * @since 5.0.13
1498 1008 *
1499 1009 * @param string $value
1500 - *
1501 1010 * @return bool
1502 1011 */
1503 1012 private static function is_a_valid_color( $value ) {
1504 1013 $match = 0;
1505 -
1506 - if ( str_starts_with( $value, 'rgba(' ) ) {
1014 + if ( 0 === strpos( $value, 'rgba(' ) ) {
1507 1015 $match = preg_match( '/^rgba\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d*(?:\.\d+)?)\)$/', $value );
1508 - } elseif ( str_starts_with( $value, 'rgb(' ) ) {
1016 + } elseif ( 0 === strpos( $value, 'rgb(' ) ) {
1509 1017 $match = preg_match( '/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/', $value );
1510 - } elseif ( str_starts_with( $value, '#' ) ) {
1018 + } elseif ( 0 === strpos( $value, '#' ) ) {
1511 1019 $match = preg_match( '/^#([a-f0-9]{6}|[a-f0-9]{3})\b$/', $value );
1512 1020 }
1513 -
1514 1021 return (bool) $match;
1515 1022 }
1516 1023
1517 1024 /**
@@ -1517,19 +1024,11 @@
1517 1024 /**
1518 1025 * Include svg images.
1519 1026 *
1520 1027 * @since 4.0.02
1521 - *
1522 - * @return void
1523 1028 */
1524 1029 public static function include_svg() {
1525 - if ( self::$included_svg ) {
1526 - return;
1527 - }
1528 -
1529 - // Use readfile instead of include_once because of a default security rule in Snuffleupagus.
1530 - readfile( self::plugin_path() . '/images/icons.svg' );
1531 - self::$included_svg = true;
1030 + include_once self::plugin_path() . '/images/icons.svg';
1532 1031 }
1533 1032
1534 1033 /**
1535 1034 * Convert an associative array to HTML values.
@@ -1538,20 +1037,17 @@
1538 1037 * @since 5.0.13 added $echo parameter.
1539 1038 *
1540 1039 * @param array $atts
1541 1040 * @param bool $echo
1542 - *
1543 1041 * @return string|void
1544 1042 */
1545 1043 public static function array_to_html_params( $atts, $echo = false ) {
1546 - $callback = function () use ( $atts ) {
1547 - if ( ! $atts ) {
1548 - return;
1044 + $callback = function() use ( $atts ) {
1045 + if ( $atts ) {
1046 + foreach ( $atts as $key => $value ) {
1047 + echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
1048 + }
1549 1049 }
1550 -
1551 - foreach ( $atts as $key => $value ) {
1552 - echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
1553 - }
1554 1050 };
1555 1051 return self::clip( $callback, $echo );
1556 1052 }
1557 1053
@@ -1561,12 +1057,9 @@
1561 1057 * @since 5.0.13
1562 1058 *
1563 1059 * @param Closure $echo_function
1564 1060 * @param bool $echo
1565 - *
1566 - * @return string|null
1567 - *
1568 - * @psalm-return ($echo is true ? null : string)
1061 + * @return string|void
1569 1062 */
1570 1063 public static function clip( $echo_function, $echo = false ) {
1571 1064 if ( ! $echo ) {
1572 1065 ob_start();
@@ -1571,60 +1064,38 @@
1571 1064 if ( ! $echo ) {
1572 1065 ob_start();
1573 1066 }
1574 1067
1575 - if ( is_callable( $echo_function ) ) {
1576 - $echo_function();
1068 + $echo_function();
1069 +
1070 + if ( ! $echo ) {
1071 + $return = ob_get_contents();
1072 + ob_end_clean();
1073 + return $return;
1577 1074 }
1578 -
1579 - return $echo ? null : ob_get_clean();
1580 1075 }
1581 1076
1582 1077 /**
1583 1078 * @since 3.0
1584 - *
1585 - * @param array $atts
1586 - *
1587 - * @return void
1588 1079 */
1589 1080 public static function get_admin_header( $atts ) {
1590 - $has_nav = ! empty( $atts['form'] ) && empty( $atts['is_template'] );
1591 -
1592 - if ( empty( $atts['close'] ) ) {
1081 + $has_nav = ( isset( $atts['form'] ) && ! empty( $atts['form'] ) && ( ! isset( $atts['is_template'] ) || ! $atts['is_template'] ) );
1082 + if ( ! isset( $atts['close'] ) || empty( $atts['close'] ) ) {
1593 1083 $atts['close'] = admin_url( 'admin.php?page=formidable' );
1594 1084 }
1595 -
1596 1085 if ( ! isset( $atts['import_link'] ) ) {
1597 1086 $atts['import_link'] = false;
1598 1087 }
1599 1088
1600 - include self::plugin_path() . '/classes/views/shared/admin-header.php';
1089 + include( self::plugin_path() . '/classes/views/shared/admin-header.php' );
1601 1090 }
1602 1091
1603 1092 /**
1604 - * @since 6.0
1605 - *
1606 - * @param string $type
1607 - *
1608 - * @return void
1609 - */
1610 - public static function import_link( $type = 'secondary' ) {
1611 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1612 - ?>
1613 - <a href="<?php echo esc_url( admin_url( 'admin.php?page=formidable-import' ) ); ?>" class="button frm-button-<?php echo esc_attr( $type ); ?> frm_animate_bg">
1614 - <?php esc_html_e( 'Import', 'formidable' ); ?>
1615 - </a>
1616 - <?php
1617 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1618 - }
1619 -
1620 - /**
1621 1093 * Print applicable admin banner.
1622 1094 *
1623 1095 * @since 5.4.2
1624 1096 *
1625 1097 * @param bool $should_show_lite_upgrade
1626 - *
1627 1098 * @return void
1628 1099 */
1629 1100 public static function print_admin_banner( $should_show_lite_upgrade ) {
1630 1101 if ( ! current_user_can( 'administrator' ) ) {
@@ -1631,44 +1102,19 @@
1631 1102 FrmInbox::maybe_show_banner();
1632 1103 return;
1633 1104 }
1634 1105
1635 - if ( FrmSalesApi::maybe_show_banner() || self::maybe_show_license_warning() || FrmInbox::maybe_show_banner() || ! $should_show_lite_upgrade || self::pro_is_installed() ) {
1106 + if ( self::maybe_show_license_warning() || FrmInbox::maybe_show_banner() || ! $should_show_lite_upgrade || self::pro_is_installed() ) {
1636 1107 // Print license warning or inbox banner and exit if either prints.
1637 1108 // And exit before printing the upgrade bar if it shouldn't be shown.
1638 1109 return;
1639 1110 }
1640 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1641 1111 ?>
1642 1112 <div class="frm-upgrade-bar">
1643 - <div class="frm-upgrade-bar-inner">
1644 - <?php
1645 - $cta_text = FrmSalesApi::get_best_sale_value( 'lite_banner_cta_text' );
1646 -
1647 - if ( ! $cta_text ) {
1648 - $cta_text = __( 'upgrading to PRO', 'formidable' );
1649 - }
1650 -
1651 - $upgrade_link = FrmSalesApi::get_best_sale_value( 'lite_banner_cta_link' );
1652 - $utm = array(
1653 - 'campaign' => 'settings-license',
1654 - 'content' => 'lite-banner',
1655 - );
1656 -
1657 - $upgrade_link = $upgrade_link ? self::maybe_add_missing_utm( $upgrade_link, $utm ) : self::admin_upgrade_link( $utm );
1658 -
1659 - printf(
1660 - /* translators: %1$s: Start link HTML, %2$s: CTA text ("upgrading to PRO" by default), %3$s: End link HTML */
1661 - esc_html__( 'You\'re using Formidable Forms Lite. To unlock more features consider %1$s%2$s%3$s.', 'formidable' ),
1662 - '<a href="' . esc_url( $upgrade_link ) . '" target="_blank" rel="noopener">',
1663 - esc_html( $cta_text ),
1664 - '</a>'
1665 - );
1666 - ?>
1667 - </div>
1113 + <span>You're using Formidable Forms Lite. To unlock more features consider</span>
1114 + <a href="<?php echo esc_url( self::admin_upgrade_link( 'top-bar' ) ); ?>" target="_blank" rel="noopener">upgrading to Pro</a>.
1668 1115 </div>
1669 1116 <?php
1670 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1671 1117 }
1672 1118
1673 1119 /**
1674 1120 * @since 5.4.2
@@ -1682,18 +1128,14 @@
1682 1128 /**
1683 1129 * Render a button for a new item (Form, Application, etc).
1684 1130 *
1685 1131 * @since 3.0
1686 - *
1687 1132 * @param array $atts {
1688 - * Details about the button.
1689 - *
1690 1133 * @type array $link_hook Custom link hook, calls do_action and exits early.
1691 1134 * @type string $new_link Href value, default #.
1692 1135 * @type string $class Custom class names, space separated.
1693 1136 * @type string $button_text Button text. Default "Add New".
1694 1137 * }
1695 - *
1696 1138 * @return void
1697 1139 */
1698 1140 public static function add_new_item_link( $atts ) {
1699 1141 if ( isset( $atts['link_hook'] ) ) {
@@ -1700,16 +1142,20 @@
1700 1142 do_action( $atts['link_hook']['hook'], $atts['link_hook']['param'] );
1701 1143 return;
1702 1144 }
1703 1145
1704 - if ( empty( $atts['new_link'] ) && empty( $atts['create_form'] ) && empty( $atts['class'] ) ) {
1146 + if ( empty( $atts['new_link'] ) && empty( $atts['trigger_new_form_modal'] ) && empty( $atts['class'] ) ) {
1705 1147 // Do not render a button if none of these attributes are set.
1706 1148 return;
1707 1149 }
1708 1150
1709 1151 $href = ! empty( $atts['new_link'] ) ? esc_url( $atts['new_link'] ) : '#';
1710 - $class = 'button button-primary frm-button-primary';
1152 + $class = 'button button-primary frm-button-primary frm-with-plus';
1711 1153
1154 + if ( ! empty( $atts['trigger_new_form_modal'] ) ) {
1155 + $class .= ' frm-trigger-new-form-modal';
1156 + }
1157 +
1712 1158 if ( ! empty( $atts['class'] ) ) {
1713 1159 $class .= ' ' . $atts['class'];
1714 1160 }
1715 1161
@@ -1719,12 +1165,8 @@
1719 1165 }
1720 1166
1721 1167 /**
1722 1168 * @since 3.06
1723 - *
1724 - * @param array $atts
1725 - *
1726 - * @return void
1727 1169 */
1728 1170 public static function show_search_box( $atts ) {
1729 1171 $defaults = array(
1730 1172 'placeholder' => '',
@@ -1730,12 +1172,10 @@
1730 1172 'placeholder' => '',
1731 1173 'tosearch' => '',
1732 1174 'text' => __( 'Search', 'formidable' ),
1733 1175 'input_id' => '',
1734 - 'value' => false,
1735 - 'class' => '',
1736 1176 );
1737 - $atts = array_merge( $defaults, $atts );
1177 + $atts = array_merge( $defaults, $atts );
1738 1178
1739 1179 if ( $atts['input_id'] === 'template' && empty( $atts['tosearch'] ) ) {
1740 1180 $atts['tosearch'] = 'frm-card';
1741 1181 }
@@ -1740,9 +1180,8 @@
1740 1180 $atts['tosearch'] = 'frm-card';
1741 1181 }
1742 1182
1743 1183 $class = 'frm-search-input';
1744 -
1745 1184 if ( ! empty( $atts['tosearch'] ) ) {
1746 1185 $class .= ' frm-auto-search';
1747 1186 }
1748 1187
@@ -1747,35 +1186,21 @@
1747 1186 }
1748 1187
1749 1188 $input_id = $atts['input_id'] . '-search-input';
1750 1189
1751 - $input_atts = array(
1752 - 'type' => 'search',
1753 - 'id' => $input_id,
1754 - 'name' => 's',
1755 - 'placeholder' => $atts['placeholder'],
1756 - 'class' => $class,
1757 - 'data-tosearch' => $atts['tosearch'],
1758 - );
1759 -
1760 - if ( is_string( $atts['value'] ) ) {
1761 - $input_atts['value'] = $atts['value'];
1762 - } elseif ( isset( $_REQUEST['s'] ) ) {
1763 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1764 - $input_atts['value'] = wp_unslash( $_REQUEST['s'] );
1765 - }
1766 -
1767 - if ( ! empty( $atts['tosearch'] ) ) {
1768 - $input_atts['autocomplete'] = 'off';
1769 - }
1770 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1771 1190 ?>
1772 - <p class="frm-search <?php echo esc_attr( $atts['class'] ); ?>">
1191 + <p class="frm-search">
1773 1192 <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>">
1774 1193 <?php echo esc_html( $atts['text'] ); ?>:
1775 1194 </label>
1776 - <?php self::icon_by_class( 'frmfont frm_search_icon frm_svg20' ); ?>
1777 - <input <?php self::array_to_html_params( $input_atts, true ); ?> />
1195 + <span class="frmfont frm_search_icon"></span>
1196 + <input type="search" id="<?php echo esc_attr( $input_id ); ?>" name="s"
1197 + value="<?php _admin_search_query(); ?>" placeholder="<?php echo esc_attr( $atts['placeholder'] ); ?>"
1198 + class="<?php echo esc_attr( $class ); ?>" data-tosearch="<?php echo esc_attr( $atts['tosearch'] ); ?>"
1199 + <?php if ( ! empty( $atts['tosearch'] ) ) { ?>
1200 + autocomplete="off"
1201 + <?php } ?>
1202 + />
1778 1203 <?php
1779 1204 if ( empty( $atts['tosearch'] ) ) {
1780 1205 submit_button( $atts['text'], 'button-secondary', '', false, array( 'id' => 'search-submit' ) );
1781 1206 }
@@ -1781,21 +1206,16 @@
1781 1206 }
1782 1207 ?>
1783 1208 </p>
1784 1209 <?php
1785 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1786 1210 }
1787 1211
1788 1212 /**
1789 - * @param string $type Hook type slug.
1790 - * @param object|null $object Optional related object.
1791 - *
1792 - * @return void
1213 + * @param string $type
1793 1214 */
1794 1215 public static function trigger_hook_load( $type, $object = null ) {
1795 1216 // Only load the form hooks once.
1796 1217 $hooks_loaded = apply_filters( 'frm_' . $type . '_hooks_loaded', false, $object );
1797 -
1798 1218 if ( ! $hooks_loaded ) {
1799 1219 do_action( 'frm_load_' . $type . '_hooks' );
1800 1220 }
1801 1221 }
@@ -1800,14 +1220,11 @@
1800 1220 }
1801 1221 }
1802 1222
1803 1223 /**
1804 - * Save all front-end js scripts into a single file.
1805 - * And save an additional single file of all front-end Stripe JS scripts.
1224 + * Save all front-end js scripts into a single file
1806 1225 *
1807 1226 * @since 3.0
1808 - *
1809 - * @return void
1810 1227 */
1811 1228 public static function save_combined_js() {
1812 1229 $file_atts = apply_filters(
1813 1230 'frm_js_location',
@@ -1820,34 +1237,10 @@
1820 1237
1821 1238 $files = array(
1822 1239 self::plugin_path() . '/js/formidable.min.js',
1823 1240 );
1824 - /**
1825 - * @param array $files
1826 - */
1827 1241 $files = apply_filters( 'frm_combined_js_files', $files );
1828 1242 $new_file->combine_files( $files );
1829 -
1830 - // Create the minified Stripe Script.
1831 - $file_atts = apply_filters(
1832 - 'frm_stripe_js_location',
1833 - array(
1834 - 'file_name' => 'frmstrp.min.js',
1835 - 'new_file_path' => self::plugin_path() . '/js',
1836 - )
1837 - );
1838 - $new_file = new FrmCreateFile( $file_atts );
1839 - $files = array(
1840 - FrmStrpLiteAppHelper::plugin_path() . 'js/frmstrp.min.js',
1841 - );
1842 -
1843 - /**
1844 - * @since 6.5
1845 - *
1846 - * @param array $files
1847 - */
1848 - $files = apply_filters( 'frm_stripe_combined_js_files', $files );
1849 - $new_file->combine_files( $files );
1850 1243 }
1851 1244
1852 1245 /**
1853 1246 * Check a value from a shortcode to see if true or false.
@@ -1854,14 +1247,14 @@
1854 1247 * True when value is 1, true, 'true', 'yes'
1855 1248 *
1856 1249 * @since 1.07.10
1857 1250 *
1858 - * @param bool|int|string $value The value to compare.
1251 + * @param string $value The value to compare
1859 1252 *
1860 - * @return bool
1253 + * @return boolean True or False
1861 1254 */
1862 1255 public static function is_true( $value ) {
1863 - return true === $value || '1' === (string) $value || 'true' === $value || 'yes' === $value;
1256 + return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
1864 1257 }
1865 1258
1866 1259 /**
1867 1260 * Gets all post from a specific post type.
@@ -1869,9 +1262,8 @@
1869 1262 *
1870 1263 * @since 4.10.01 Add `$post_type` argument.
1871 1264 *
1872 1265 * @param string $post_type Post type to query. Default is `page`.
1873 - *
1874 1266 * @return WP_Post[]
1875 1267 */
1876 1268 public static function get_pages( $post_type = 'page' ) {
1877 1269 $query = array(
@@ -1890,9 +1282,8 @@
1890 1282 *
1891 1283 * @since 5.0.09
1892 1284 *
1893 1285 * @param string $post_type Post type to query. Default is `page`.
1894 - *
1895 1286 * @return array
1896 1287 */
1897 1288 public static function get_post_ids_and_titles( $post_type = 'page' ) {
1898 1289 return FrmDb::get_results(
@@ -1917,12 +1308,13 @@
1917 1308 *
1918 1309 * @param array $args Selection arguments.
1919 1310 */
1920 1311 public static function maybe_autocomplete_pages_options( $args ) {
1921 - $args = self::preformat_selection_args( $args );
1312 + $args = self::preformat_selection_args( $args );
1313 +
1922 1314 $pages_count = wp_count_posts( $args['post_type'] );
1923 1315
1924 - if ( ! isset( $pages_count->publish ) || $pages_count->publish <= 50 ) {
1316 + if ( $pages_count->publish <= 50 ) {
1925 1317 self::wp_pages_dropdown( $args );
1926 1318 return;
1927 1319 }
1928 1320
@@ -1928,9 +1320,9 @@
1928 1320
1929 1321 wp_enqueue_script( 'jquery-ui-autocomplete' );
1930 1322
1931 1323 $selected = self::get_post_param( $args['field_name'], $args['page_id'], 'absint' );
1932 - $title = '';
1324 + $title = '';
1933 1325
1934 1326 if ( $selected ) {
1935 1327 $title = get_the_title( $selected );
1936 1328 }
@@ -1946,119 +1338,18 @@
1946 1338 <?php
1947 1339 }
1948 1340
1949 1341 /**
1950 - * Maybe show an HTML select or autocomplete input based on the number of options.
1951 - *
1952 - * @since 6.21
1953 - *
1954 - * @param array $args Args. See the method for details.
1342 + * @param array $args
1343 + * @param string $page_id Deprecated.
1344 + * @param boolean $truncate Deprecated.
1955 1345 */
1956 - public static function maybe_autocomplete_options( $args ) {
1957 - $defaults = array(
1958 - 'truncate' => false,
1959 - 'placeholder' => ' ',
1960 - 'name' => '',
1961 - 'id' => '',
1962 - 'selected' => '',
1963 - 'source' => array(),
1964 - 'dropdown_limit' => 50,
1965 - 'autocomplete_placeholder' => __( 'Select an option', 'formidable' ),
1966 - 'value_key' => 'value',
1967 - 'label_key' => 'label',
1968 - );
1969 -
1970 - $args = wp_parse_args( $args, $defaults );
1971 - $html_attrs = array();
1972 -
1973 - if ( ! empty( $args['name'] ) ) {
1974 - $html_attrs['name'] = $args['name'];
1975 - }
1976 -
1977 - if ( ! empty( $args['id'] ) ) {
1978 - $html_attrs['id'] = $args['id'];
1979 - }
1980 -
1981 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1982 - if ( count( $args['source'] ) <= $args['dropdown_limit'] ) {
1983 - ?>
1984 - <select <?php self::array_to_html_params( $html_attrs, true ); ?>>
1985 - <option value=""><?php echo esc_html( $args['placeholder'] ); ?></option>
1986 - <?php
1987 - foreach ( $args['source'] as $key => $source ) :
1988 - $value_label = self::get_dropdown_value_and_label_from_option( $source, $key, $args );
1989 -
1990 - if ( ! empty( $args['truncate'] ) ) {
1991 - $value_label['label'] = self::truncate( $value_label['label'], $args['truncate'] );
1992 - }
1993 - ?>
1994 - <option value="<?php echo esc_attr( $value_label['value'] ); ?>" <?php selected( $value_label['value'], $args['selected'] ); ?>><?php echo esc_html( $value_label['label'] ); ?></option><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
1995 - <?php endforeach; ?>
1996 - </select>
1997 - <?php
1998 - return;
1999 - }
2000 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
2001 -
2002 - $options = array();
2003 - $autocomplete_value = '';
2004 -
2005 - foreach ( $args['source'] as $key => $source ) {
2006 - $value_label = self::get_dropdown_value_and_label_from_option( $source, $key, $args );
2007 -
2008 - if ( $value_label['value'] === $args['selected'] ) {
2009 - $autocomplete_value = $value_label['label'];
2010 - }
2011 -
2012 - $options[] = $value_label;
2013 - }
2014 -
2015 - $html_attrs['type'] = 'hidden';
2016 - $html_attrs['class'] = 'frm_autocomplete_value_input';
2017 - $html_attrs['value'] = $args['selected'];
2018 - ?>
2019 - <input type="text" class="frm-custom-search"
2020 - data-source="<?php echo esc_attr( wp_json_encode( $options ) ); ?>"
2021 - placeholder="<?php echo esc_attr( $args['autocomplete_placeholder'] ); ?>"
2022 - value="<?php echo esc_attr( $autocomplete_value ); ?>" />
2023 - <input <?php self::array_to_html_params( $html_attrs, true ); ?> />
2024 - <?php
2025 - }
2026 -
2027 - /**
2028 - * Gets dropdown value and label from autodropdown option.
2029 - *
2030 - * @since 6.21
2031 - *
2032 - * @param array|string $option Autocomplete option.
2033 - * @param string $key Array key of the option.
2034 - * @param array $args See {@see FrmAppHelper::maybe_autocomplete_options()}.
2035 - *
2036 - * @return array
2037 - */
2038 - private static function get_dropdown_value_and_label_from_option( $option, $key, $args ) {
2039 - if ( is_array( $option ) ) {
2040 - $value = $option[ $args['value_key'] ] ?? '';
2041 - $label = $option[ $args['label_key'] ] ?? '';
2042 - } else {
2043 - $value = $key;
2044 - $label = $option;
2045 - }
2046 -
2047 - return compact( 'value', 'label' );
2048 - }
2049 -
2050 - /**
2051 - * @param array $args
2052 - * @param string $page_id Deprecated.
2053 - * @param bool $truncate Deprecated.
2054 - */
2055 1346 public static function wp_pages_dropdown( $args = array(), $page_id = '', $truncate = false ) {
2056 1347 self::prep_page_dropdown_params( $page_id, $truncate, $args );
2057 1348
2058 1349 $pages = self::get_post_ids_and_titles( $args['post_type'] );
2059 1350 $selected = self::get_post_param( $args['field_name'], $args['page_id'], 'absint' );
2060 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1351 +
2061 1352 ?>
2062 1353 <select name="<?php echo esc_attr( $args['field_name'] ); ?>" id="<?php echo esc_attr( $args['field_name'] ); ?>" class="frm-pages-dropdown">
2063 1354 <option value=""><?php echo esc_html( $args['placeholder'] ); ?></option>
2064 1355 <?php foreach ( $pages as $page ) { ?>
@@ -2067,9 +1358,8 @@
2067 1358 </option>
2068 1359 <?php } ?>
2069 1360 </select>
2070 1361 <?php
2071 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
2072 1362 }
2073 1363
2074 1364 /**
2075 1365 * Fill in missing parameters passed to wp_pages_dropdown().
@@ -2075,14 +1365,8 @@
2075 1365 * Fill in missing parameters passed to wp_pages_dropdown().
2076 1366 * This is for reverse compatibility with switching 3 params to 1.
2077 1367 *
2078 1368 * @since 4.03.06
2079 - *
2080 - * @param string $page_id Deprecated.
2081 - * @param bool $truncate Deprecated.
2082 - * @param mixed $args
2083 - *
2084 - * @return void
2085 1369 */
2086 1370 private static function prep_page_dropdown_params( $page_id, $truncate, &$args ) {
2087 1371 if ( ! is_array( $args ) ) {
2088 1372 $args = array(
@@ -2099,20 +1383,16 @@
2099 1383 * Filter to format args for page dropdown or autocomplete
2100 1384 *
2101 1385 * @since 4.03.06
2102 1386 * @since 4.10.01 Added `post_type` and `autocomplete_placeholder` to the arguments array.
2103 - *
2104 - * @param array $args
2105 - *
2106 - * @return array
2107 1387 */
2108 1388 private static function preformat_selection_args( $args ) {
2109 1389 $defaults = array(
2110 - 'truncate' => false,
2111 - 'placeholder' => ' ',
2112 - 'field_name' => '',
2113 - 'page_id' => '',
2114 - 'post_type' => 'page',
1390 + 'truncate' => false,
1391 + 'placeholder' => ' ',
1392 + 'field_name' => '',
1393 + 'page_id' => '',
1394 + 'post_type' => 'page',
2115 1395 'autocomplete_placeholder' => __( 'Select a Page', 'formidable' ),
2116 1396 );
2117 1397
2118 1398 return array_merge( $defaults, $args );
@@ -2117,18 +1397,13 @@
2117 1397
2118 1398 return array_merge( $defaults, $args );
2119 1399 }
2120 1400
2121 - /**
2122 - * @param int $post_id
2123 - *
2124 - * @return string
2125 - */
2126 1401 public static function post_edit_link( $post_id ) {
2127 1402 $post = get_post( $post_id );
2128 -
2129 1403 if ( $post ) {
2130 1404 $post_url = admin_url( 'post.php?post=' . $post_id . '&action=edit' );
1405 +
2131 1406 return '<a href="' . esc_url( $post_url ) . '">' . self::truncate( $post->post_title, 50 ) . '</a>';
2132 1407 }
2133 1408
2134 1409 return '';
@@ -2141,42 +1416,24 @@
2141 1416 *
2142 1417 * @return bool
2143 1418 */
2144 1419 public static function is_full_screen() {
2145 - return self::is_form_builder_page() || self::is_style_editor_page() || self::is_full_screen_view_builder_page();
1420 + return self::is_form_builder_page() ||
1421 + self::is_style_editor_page() ||
1422 + self::is_full_screen_view_builder_page();
2146 1423 }
2147 1424
2148 1425 /**
2149 - * Check if user is on the style editor or its alternative URL.
1426 + * Check if user is on the style editor, or the alternative URL.
2150 1427 * The first URL is a submenu "Styles" in the Formidable menu /wp-admin/admin.php?page=formidable-styles.
2151 1428 * The alternative URL is linked as a submenu "Forms" item of the Appearance menu /wp-admin/themes.php?page=formidable-styles2.
2152 1429 *
2153 1430 * @since 5.5.3
2154 - * @since 6.0 Added the $view parameter. Previously there was only a 'edit' view.
2155 1431 *
2156 - * @param string $view Supports 'edit', 'list', and ''. If '', both 'edit' and 'list' will match.
2157 - *
2158 1432 * @return bool
2159 1433 */
2160 - public static function is_style_editor_page( $view = '' ) {
2161 - if ( ! self::is_admin_page( 'formidable-styles' ) && ! self::is_admin_page( 'formidable-styles2' ) ) {
2162 - return false;
2163 - }
2164 -
2165 - if ( ! in_array( $view, array( 'list', 'edit' ), true ) ) {
2166 - return true;
2167 - }
2168 -
2169 - $action = self::simple_get( 'frm_action' );
2170 - $is_edit_mode = 'edit' === $action || ( ! $action && ! self::simple_get( 'id' ) && ! self::simple_get( 'form' ) );
2171 -
2172 - if ( ! $is_edit_mode && class_exists( 'FrmProStylesController' ) && in_array( $action, array( 'new_style', 'duplicate' ), true ) ) {
2173 - $is_edit_mode = true;
2174 - }
2175 -
2176 - $checking_for_edit_mode = 'edit' === $view;
2177 -
2178 - return $is_edit_mode === $checking_for_edit_mode;
1434 + public static function is_style_editor_page() {
1435 + return self::is_admin_page( 'formidable-styles' ) || self::is_admin_page( 'formidable-styles2' );
2179 1436 }
2180 1437
2181 1438 /**
2182 1439 * @since 5.5.3
@@ -2187,29 +1444,35 @@
2187 1444 return self::is_admin_page( 'formidable-views-editor' );
2188 1445 }
2189 1446
2190 1447 /**
2191 - * @param string $field_name
2192 - * @param array|string $capability
2193 - * @param string $multiple 'single' and 'multiple'.
1448 + * @since 4.0
1449 + * @deprecated 5.5.3
2194 1450 */
1451 + public static function maybe_full_screen_link( $link ) {
1452 + _deprecated_function( __METHOD__, '5.5.3' );
1453 + return $link;
1454 + }
1455 +
1456 + /**
1457 + * @param string $field_name
1458 + * @param string|array $capability
1459 + * @param string $multiple 'single' and 'multiple'
1460 + */
2195 1461 public static function wp_roles_dropdown( $field_name, $capability, $multiple = 'single' ) {
2196 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
2197 1462 ?>
2198 1463 <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>"
2199 - <?php echo 'multiple' === $multiple ? 'multiple="multiple"' : ''; ?>
1464 + <?php echo ( 'multiple' === $multiple ) ? 'multiple="multiple"' : ''; ?>
2200 1465 class="frm_multiselect">
2201 1466 <?php self::roles_options( $capability ); ?>
2202 1467 </select>
2203 1468 <?php
2204 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
2205 1469 }
2206 1470
2207 1471 /**
2208 1472 * @since 4.07
2209 - *
2210 1473 * @param array|string $selected
2211 - * @param string $current
1474 + * @param string $current
2212 1475 */
2213 1476 private static function selected( $selected, $current ) {
2214 1477 if ( is_callable( 'FrmProAppHelper::selected' ) ) {
2215 1478 FrmProAppHelper::selected( $selected, $current );
@@ -2218,13 +1481,12 @@
2218 1481 }
2219 1482 }
2220 1483
2221 1484 /**
2222 - * @param array|string $capability
1485 + * @param string|array $capability
2223 1486 */
2224 1487 public static function roles_options( $capability ) {
2225 1488 global $frm_vars;
2226 -
2227 1489 if ( isset( $frm_vars['editable_roles'] ) ) {
2228 1490 $editable_roles = $frm_vars['editable_roles'];
2229 1491 } else {
2230 1492 $editable_roles = get_editable_roles();
@@ -2233,9 +1495,9 @@
2233 1495
2234 1496 foreach ( $editable_roles as $role => $details ) {
2235 1497 $name = translate_user_role( $details['name'] );
2236 1498 ?>
2237 - <option value="<?php echo esc_attr( $role ); ?>" <?php self::selected( $capability, $role ); ?>><?php echo esc_html( $name ); ?></option>
1499 + <option value="<?php echo esc_attr( $role ); ?>" <?php self::selected( $capability, $role ); ?>><?php echo esc_attr( $name ); ?> </option>
2238 1500 <?php
2239 1501 unset( $role, $details );
2240 1502 }
2241 1503 }
@@ -2245,9 +1507,8 @@
2245 1507 *
2246 1508 * @since 5.0 Parameter `$type` supports `pro_only` value.
2247 1509 *
2248 1510 * @param string $type Supports `auto`, `pro`, or `pro_only`.
2249 - *
2250 1511 * @return array
2251 1512 */
2252 1513 public static function frm_capabilities( $type = 'auto' ) {
2253 1514 if ( ! self::pro_is_installed() && ! in_array( $type, array( 'pro', 'pro_only' ), true ) ) {
@@ -2257,8 +1518,9 @@
2257 1518 $pro_cap = array(
2258 1519 'frm_create_entries' => __( 'Add Entries from Admin Area', 'formidable' ),
2259 1520 'frm_edit_entries' => __( 'Edit Entries from Admin Area', 'formidable' ),
2260 1521 'frm_view_reports' => __( 'View Reports', 'formidable' ),
1522 + 'frm_edit_displays' => __( 'Add/Edit Views', 'formidable' ),
2261 1523 );
2262 1524 /**
2263 1525 * @since 5.3.1
2264 1526 *
@@ -2281,9 +1543,9 @@
2281 1543 * @return array<string,string>
2282 1544 */
2283 1545 private static function get_lite_capabilities() {
2284 1546 return array(
2285 - 'frm_view_forms' => __( 'View Forms List', 'formidable' ),
1547 + 'frm_view_forms' => __( 'View Forms', 'formidable' ),
2286 1548 'frm_edit_forms' => __( 'Add and Edit Forms', 'formidable' ),
2287 1549 'frm_delete_forms' => __( 'Delete Forms', 'formidable' ),
2288 1550 'frm_change_settings' => __( 'Access this Settings Page', 'formidable' ),
2289 1551 'frm_view_entries' => __( 'View Entries from Admin Area', 'formidable' ),
@@ -2312,18 +1574,21 @@
2312 1574 if ( $role === 'loggedin' || ! $role ) {
2313 1575 return is_user_logged_in();
2314 1576 }
2315 1577
2316 - if ( (int) $role === 1 ) {
1578 + if ( $role == 1 ) {
2317 1579 $role = 'administrator';
2318 1580 }
2319 1581
2320 - return is_user_logged_in() ? current_user_can( $role ) : false;
1582 + if ( ! is_user_logged_in() ) {
1583 + return false;
1584 + }
1585 +
1586 + return current_user_can( $role );
2321 1587 }
2322 1588
2323 1589 /**
2324 - * @param array|string $needed_role
2325 - *
1590 + * @param string|array $needed_role
2326 1591 * @return bool
2327 1592 */
2328 1593 public static function user_has_permission( $needed_role ) {
2329 1594 if ( is_array( $needed_role ) ) {
@@ -2337,20 +1602,18 @@
2337 1602 }
2338 1603
2339 1604 $can = self::current_user_can( $needed_role );
2340 1605
2341 - if ( $can || in_array( $needed_role, array( '-1', 'loggedout' ), true ) ) {
1606 + if ( $can || in_array( $needed_role, array( '-1', 'loggedout' ) ) ) {
2342 1607 return $can;
2343 1608 }
2344 1609
2345 1610 $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
2346 -
2347 1611 foreach ( $roles as $role ) {
2348 1612 if ( current_user_can( $role ) ) {
2349 1613 return true;
2350 1614 }
2351 -
2352 - if ( $role === $needed_role ) {
1615 + if ( $role == $needed_role ) {
2353 1616 break;
2354 1617 }
2355 1618 }
2356 1619
@@ -2368,11 +1631,11 @@
2368 1631 if ( ! current_user_can( 'administrator' ) || current_user_can( 'frm_view_forms' ) ) {
2369 1632 return;
2370 1633 }
2371 1634
2372 - $user = new WP_User( get_current_user_id() );
1635 + $user_id = get_current_user_id();
1636 + $user = new WP_User( $user_id );
2373 1637 $frm_roles = self::frm_capabilities();
2374 -
2375 1638 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
2376 1639 $user->add_cap( $frm_role );
2377 1640 unset( $frm_role, $frm_role_description );
2378 1641 }
@@ -2381,47 +1644,35 @@
2381 1644 /**
2382 1645 * Make sure admins have permission to see the menu items
2383 1646 *
2384 1647 * @since 2.0.6
2385 - *
2386 - * @param string $cap
2387 - *
2388 - * @return void
2389 1648 */
2390 1649 public static function force_capability( $cap = 'frm_change_settings' ) {
2391 - if ( ! current_user_can( 'administrator' ) || current_user_can( $cap ) ) {
2392 - return;
1650 + if ( current_user_can( 'administrator' ) && ! current_user_can( $cap ) ) {
1651 + $role = get_role( 'administrator' );
1652 + $frm_roles = self::frm_capabilities();
1653 + foreach ( $frm_roles as $frm_role => $frm_role_description ) {
1654 + $role->add_cap( $frm_role );
1655 + }
2393 1656 }
2394 -
2395 - $role = get_role( 'administrator' );
2396 - $frm_roles = self::frm_capabilities();
2397 -
2398 - foreach ( $frm_roles as $frm_role => $frm_role_description ) {
2399 - $role->add_cap( $frm_role );
2400 - }
2401 1657 }
2402 1658
2403 1659 /**
2404 - * Check if the user has permission for action.
1660 + * Check if the user has permision for action.
2405 1661 * Return permission message and stop the action if no permission
2406 1662 *
2407 1663 * @since 2.0
2408 1664 *
2409 1665 * @param string $permission
2410 - * @param string $show_message
2411 1666 */
2412 1667 public static function permission_check( $permission, $show_message = 'show' ) {
2413 1668 $permission_error = self::permission_nonce_error( $permission );
2414 -
2415 - if ( $permission_error === false ) {
2416 - return;
1669 + if ( $permission_error !== false ) {
1670 + if ( 'hide' == $show_message ) {
1671 + $permission_error = '';
1672 + }
1673 + wp_die( esc_html( $permission_error ) );
2417 1674 }
2418 -
2419 - if ( 'hide' === $show_message ) {
2420 - $permission_error = '';
2421 - }
2422 -
2423 - wp_die( esc_html( $permission_error ) );
2424 1675 }
2425 1676
2426 1677 /**
2427 1678 * Check user permission and nonce
@@ -2428,27 +1679,24 @@
2428 1679 *
2429 1680 * @since 2.0
2430 1681 *
2431 1682 * @param string $permission
2432 - * @param string $nonce_name
2433 - * @param string $nonce
2434 1683 *
2435 1684 * @return false|string The permission message or false if allowed
2436 1685 */
2437 1686 public static function permission_nonce_error( $permission, $nonce_name = '', $nonce = '' ) {
2438 - if ( $permission && ! current_user_can( $permission ) && ! current_user_can( 'administrator' ) ) {
1687 + if ( ! empty( $permission ) && ! current_user_can( $permission ) && ! current_user_can( 'administrator' ) ) {
2439 1688 $frm_settings = self::get_settings();
1689 +
2440 1690 return $frm_settings->admin_permission;
2441 1691 }
2442 1692
2443 1693 $error = false;
2444 -
2445 - if ( ! $nonce_name ) {
1694 + if ( empty( $nonce_name ) ) {
2446 1695 return $error;
2447 1696 }
2448 1697
2449 - $nonce_value = $_REQUEST && isset( $_REQUEST[ $nonce_name ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ $nonce_name ] ) ) : '';
2450 -
1698 + $nonce_value = ( $_REQUEST && isset( $_REQUEST[ $nonce_name ] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST[ $nonce_name ] ) ) : '';
2451 1699 if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $nonce_value, $nonce ) ) ) {
2452 1700 $frm_settings = self::get_settings();
2453 1701 $error = $frm_settings->admin_permission;
2454 1702 }
@@ -2455,14 +1703,8 @@
2455 1703
2456 1704 return $error;
2457 1705 }
2458 1706
2459 - /**
2460 - * @param array|string $values
2461 - * @param string $current
2462 - *
2463 - * @return void
2464 - */
2465 1707 public static function checked( $values, $current ) {
2466 1708 if ( self::check_selected( $values, $current ) ) {
2467 1709 echo ' checked="checked"';
2468 1710 }
@@ -2467,74 +1709,40 @@
2467 1709 echo ' checked="checked"';
2468 1710 }
2469 1711 }
2470 1712
2471 - /**
2472 - * @param array|string $values
2473 - * @param string|null $current
2474 - *
2475 - * @return bool
2476 - */
2477 1713 public static function check_selected( $values, $current ) {
2478 1714 $values = self::recursive_function_map( $values, 'trim' );
2479 1715 $values = self::recursive_function_map( $values, 'htmlspecialchars_decode' );
2480 - $current = is_null( $current ) ? '' : htmlspecialchars_decode( trim( $current ) );
1716 + $current = htmlspecialchars_decode( trim( $current ) );
2481 1717
2482 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict, Universal.Operators.StrictComparisons
2483 - return is_array( $values ) ? in_array( $current, $values ) : $values == $current;
1718 + return ( is_array( $values ) && in_array( $current, $values ) ) || ( ! is_array( $values ) && $values == $current );
2484 1719 }
2485 1720
2486 - /**
2487 - * @param array|string $value
2488 - * @param callable|string $function
2489 - *
2490 - * @return array|string
2491 - */
2492 1721 public static function recursive_function_map( $value, $function ) {
2493 1722 if ( is_array( $value ) ) {
2494 1723 $original_function = $function;
2495 - $function = count( $value ) ? explode( ', ', FrmDb::prepare_array_values( $value, $function ) ) : array( $function );
2496 -
2497 - if ( self::is_assoc( $value ) ) {
1724 + if ( count( $value ) ) {
1725 + $function = explode( ', ', FrmDb::prepare_array_values( $value, $function ) );
1726 + } else {
1727 + $function = array( $function );
1728 + }
1729 + if ( ! self::is_assoc( $value ) ) {
1730 + $value = array_map( array( 'FrmAppHelper', 'recursive_function_map' ), $value, $function );
1731 + } else {
2498 1732 foreach ( $value as $k => $v ) {
2499 1733 if ( ! is_array( $v ) ) {
2500 1734 $value[ $k ] = call_user_func( $original_function, $v );
2501 1735 }
2502 1736 }
2503 - } else {
2504 - $value = array_map( array( 'FrmAppHelper', 'recursive_function_map' ), $value, $function );
2505 1737 }
2506 1738 } else {
2507 - $value = self::maybe_update_value_if_null( $value, $function );
2508 1739 $value = call_user_func( $function, $value );
2509 - }//end if
2510 -
2511 - return $value;
2512 - }
2513 -
2514 - /**
2515 - * Updates value to empty string if it is null and being passed to a string function.
2516 - *
2517 - * @since 6.8.4
2518 - *
2519 - * @param mixed $value
2520 - * @param string $function
2521 - *
2522 - * @return mixed
2523 - */
2524 - private static function maybe_update_value_if_null( $value, $function ) {
2525 - if ( null === $value && in_array( $function, array( 'trim', 'strlen' ), true ) ) {
2526 - return '';
2527 1740 }
2528 1741
2529 1742 return $value;
2530 1743 }
2531 1744
2532 - /**
2533 - * @param array $array
2534 - *
2535 - * @return bool
2536 - */
2537 1745 public static function is_assoc( $array ) {
2538 1746 return (bool) count( array_filter( array_keys( $array ), 'is_string' ) );
2539 1747 }
2540 1748
@@ -2539,24 +1747,20 @@
2539 1747 }
2540 1748
2541 1749 /**
2542 1750 * Flatten a multi-dimensional array
2543 - *
2544 - * @param array $array
2545 - * @param string $keys
2546 - *
2547 - * @return array
2548 1751 */
2549 1752 public static function array_flatten( $array, $keys = 'keep' ) {
2550 1753 $return = array();
2551 -
2552 1754 foreach ( $array as $key => $value ) {
2553 1755 if ( is_array( $value ) ) {
2554 1756 $return = array_merge( $return, self::array_flatten( $value, $keys ) );
2555 - } elseif ( $keys === 'keep' ) {
2556 - $return[ $key ] = $value;
2557 1757 } else {
2558 - $return[] = $value;
1758 + if ( $keys == 'keep' ) {
1759 + $return[ $key ] = $value;
1760 + } else {
1761 + $return[] = $value;
1762 + }
2559 1763 }
2560 1764 }
2561 1765
2562 1766 return $return;
@@ -2561,43 +1765,16 @@
2561 1765
2562 1766 return $return;
2563 1767 }
2564 1768
2565 - /**
2566 - * Flatten an array before imploding it to avoid Array to string conversion warnings.
2567 - *
2568 - * @since 6.16.1
2569 - *
2570 - * @param string $sep
2571 - * @param array $array
2572 - *
2573 - * @return string
2574 - */
2575 - public static function safe_implode( $sep, $array ) {
2576 - $array = self::array_flatten( $array );
2577 - return implode( $sep, $array );
2578 - }
2579 -
2580 - /**
2581 - * @param string $text
2582 - * @param bool $is_rich_text
2583 - *
2584 - * @return string
2585 - */
2586 1769 public static function esc_textarea( $text, $is_rich_text = false ) {
2587 1770 $safe_text = str_replace( '&quot;', '"', $text );
2588 -
2589 1771 if ( ! $is_rich_text ) {
2590 1772 $safe_text = htmlspecialchars( $safe_text, ENT_NOQUOTES );
2591 1773 }
2592 -
2593 1774 $safe_text = str_replace( '&amp; ', '& ', $safe_text );
2594 1775
2595 - /**
2596 - * @param string $safe_text
2597 - * @param string $text
2598 - */
2599 - return (string) apply_filters( 'esc_textarea', $safe_text, $text );
1776 + return apply_filters( 'esc_textarea', $safe_text, $text );
2600 1777 }
2601 1778
2602 1779 /**
2603 1780 * Add auto paragraphs to text areas
@@ -2602,59 +1779,44 @@
2602 1779 /**
2603 1780 * Add auto paragraphs to text areas
2604 1781 *
2605 1782 * @since 2.0
2606 - *
2607 - * @param mixed $content
2608 - *
2609 - * @return mixed
2610 1783 */
2611 1784 public static function use_wpautop( $content ) {
2612 - if ( apply_filters( 'frm_use_wpautop', true ) && is_string( $content ) ) {
2613 - return wpautop( str_replace( '<br>', '<br />', $content ) );
1785 + if ( apply_filters( 'frm_use_wpautop', true ) && ! is_array( $content ) ) {
1786 + $content = wpautop( str_replace( '<br>', '<br />', $content ) );
2614 1787 }
2615 1788
2616 1789 return $content;
2617 1790 }
2618 1791
2619 - /**
2620 - * Replace quotes with their HTML entities.
2621 - *
2622 - * @param string $val
2623 - *
2624 - * @return string
2625 - */
2626 1792 public static function replace_quotes( $val ) {
2627 1793 // Replace double quotes.
2628 1794 $val = str_replace( array( '&#8220;', '&#8221;', '&#8243;' ), '"', $val );
2629 1795
2630 1796 // Replace single quotes.
2631 - return str_replace( array( '&#8216;', '&#8217;', '&#8242;', '&prime;', '&rsquo;', '&lsquo;' ), "'", $val );
1797 + $val = str_replace( array( '&#8216;', '&#8217;', '&#8242;', '&prime;', '&rsquo;', '&lsquo;' ), "'", $val );
1798 +
1799 + return $val;
2632 1800 }
2633 1801
2634 1802 /**
2635 - * @param string $handle
2636 - * @param int|string $default
2637 - *
2638 - * @return int|string
1803 + * @param string $handle
2639 1804 */
2640 1805 public static function script_version( $handle, $default = 0 ) {
2641 1806 global $wp_scripts;
2642 -
2643 1807 if ( ! $wp_scripts ) {
2644 1808 return $default;
2645 1809 }
2646 1810
2647 1811 $ver = $default;
2648 -
2649 1812 if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
2650 1813 return $ver;
2651 1814 }
2652 1815
2653 1816 $query = $wp_scripts->registered[ $handle ];
2654 -
2655 1817 if ( is_object( $query ) && ! empty( $query->ver ) ) {
2656 - return $query->ver;
1818 + $ver = $query->ver;
2657 1819 }
2658 1820
2659 1821 return $ver;
2660 1822 }
@@ -2663,23 +1825,17 @@
2663 1825 * @since 5.0.13 added $echo param.
2664 1826 *
2665 1827 * @param string $url
2666 1828 * @param bool $echo
2667 - *
2668 - * @return string|null
1829 + * @return string|void
2669 1830 */
2670 1831 public static function js_redirect( $url, $echo = false ) {
2671 - $callback = function () use ( $url ) {
1832 + $callback = function() use ( $url ) {
2672 1833 echo '<script type="text/javascript">window.location="' . esc_url_raw( $url ) . '"</script>';
2673 1834 };
2674 1835 return self::clip( $callback, $echo );
2675 1836 }
2676 1837
2677 - /**
2678 - * @param int|string $user_id
2679 - *
2680 - * @return int|string
2681 - */
2682 1838 public static function get_user_id_param( $user_id ) {
2683 1839 if ( ! $user_id || is_numeric( $user_id ) ) {
2684 1840 return $user_id;
2685 1841 }
@@ -2684,13 +1840,16 @@
2684 1840 return $user_id;
2685 1841 }
2686 1842
2687 1843 $user_id = sanitize_text_field( $user_id );
2688 -
2689 - if ( $user_id === 'current' ) {
1844 + if ( $user_id == 'current' ) {
2690 1845 $user_id = get_current_user_id();
2691 1846 } else {
2692 - $user = is_email( $user_id ) ? get_user_by( 'email', $user_id ) : get_user_by( 'login', $user_id );
1847 + if ( is_email( $user_id ) ) {
1848 + $user = get_user_by( 'email', $user_id );
1849 + } else {
1850 + $user = get_user_by( 'login', $user_id );
1851 + }
2693 1852
2694 1853 if ( $user ) {
2695 1854 $user_id = $user->ID;
2696 1855 }
@@ -2699,14 +1858,8 @@
2699 1858
2700 1859 return $user_id;
2701 1860 }
2702 1861
2703 - /**
2704 - * @param string $filename
2705 - * @param array $atts
2706 - *
2707 - * @return false|string
2708 - */
2709 1862 public static function get_file_contents( $filename, $atts = array() ) {
2710 1863 if ( ! is_file( $filename ) ) {
2711 1864 return false;
2712 1865 }
@@ -2712,10 +1865,13 @@
2712 1865 }
2713 1866
2714 1867 extract( $atts ); // phpcs:ignore WordPress.PHP.DontExtract
2715 1868 ob_start();
2716 - include $filename;
2717 - return ob_get_clean();
1869 + include( $filename );
1870 + $contents = ob_get_contents();
1871 + ob_end_clean();
1872 +
1873 + return $contents;
2718 1874 }
2719 1875
2720 1876 /**
2721 1877 * @param string $name
@@ -2725,9 +1881,8 @@
2725 1881 * @param int $num_chars
2726 1882 */
2727 1883 public static function get_unique_key( $name, $table_name, $column, $id = 0, $num_chars = 5 ) {
2728 1884 $key = '';
2729 -
2730 1885 if ( $name ) {
2731 1886 $key = sanitize_key( $name );
2732 1887 $key = self::maybe_clear_long_key( $key, $column );
2733 1888 }
@@ -2747,31 +1902,31 @@
2747 1902 $column
2748 1903 );
2749 1904
2750 1905 // Create a unique field id if it has already been used.
2751 - if ( ! in_array( $key, $similar_keys, true ) ) {
2752 - return $key;
2753 - }
1906 + if ( in_array( $key, $similar_keys, true ) ) {
1907 + $key = self::maybe_truncate_key_before_appending( $column, $key );
2754 1908
2755 - $key = self::maybe_truncate_key_before_appending( $column, $key );
1909 + /**
1910 + * Allow for a custom separator between the attempted key and the generated suffix.
1911 + *
1912 + * @since 5.2.03
1913 + *
1914 + * @param string $separator. Default empty.
1915 + * @param string $key the key without the added suffix.
1916 + */
1917 + $separator = apply_filters( 'frm_unique_' . $column . '_separator', '', $key );
2756 1918
2757 - /**
2758 - * Allow for a custom separator between the attempted key and the generated suffix.
2759 - *
2760 - * @since 5.2.03
2761 - *
2762 - * @param string $separator. Default empty.
2763 - * @param string $key the key without the added suffix.
2764 - */
2765 - $separator = apply_filters( 'frm_unique_' . $column . '_separator', '', $key );
1919 + $suffix = 2;
1920 + do {
1921 + $key_check = $key . $separator . $suffix;
1922 + ++$suffix;
1923 + } while ( in_array( $key_check, $similar_keys, true ) );
2766 1924
2767 - $suffix = 2;
2768 - do {
2769 - $key_check = $key . $separator . $suffix;
2770 - ++$suffix;
2771 - } while ( in_array( $key_check, $similar_keys, true ) );
1925 + $key = $key_check;
1926 + }
2772 1927
2773 - return $key_check;
1928 + return $key;
2774 1929 }
2775 1930
2776 1931 /**
2777 1932 * Avoid trying to append to a really long key,
@@ -2778,26 +1933,20 @@
2778 1933 * The database limit is 100 for form and field keys so we want to avoid getting too close.
2779 1934 *
2780 1935 * @param string $column
2781 1936 * @param string $key
2782 - *
2783 1937 * @return string
2784 1938 */
2785 1939 private static function maybe_truncate_key_before_appending( $column, $key ) {
2786 - if ( ! in_array( $column, array( 'form_key', 'field_key' ), true ) ) {
2787 - return $key;
2788 - }
2789 -
2790 - $max_key_length_before_truncating = 60;
2791 -
2792 - if ( strlen( $key ) > $max_key_length_before_truncating ) {
2793 - $key = substr( $key, 0, $max_key_length_before_truncating );
2794 -
2795 - if ( is_numeric( $key ) ) {
2796 - $key .= 'a';
1940 + if ( in_array( $column, array( 'form_key', 'field_key' ), true ) ) {
1941 + $max_key_length_before_truncating = 60;
1942 + if ( strlen( $key ) > $max_key_length_before_truncating ) {
1943 + $key = substr( $key, 0, $max_key_length_before_truncating );
1944 + if ( is_numeric( $key ) ) {
1945 + $key .= 'a';
1946 + }
2797 1947 }
2798 1948 }
2799 -
2800 1949 return $key;
2801 1950 }
2802 1951
2803 1952 /**
@@ -2804,36 +1953,29 @@
2804 1953 * Possibly reset a key to avoid conflicts with column size limits.
2805 1954 *
2806 1955 * @param string $key
2807 1956 * @param string $column
2808 - *
2809 1957 * @return string either the original key value, or an empty string if the key was too long.
2810 1958 */
2811 1959 private static function maybe_clear_long_key( $key, $column ) {
2812 1960 if ( 'field_key' === $column && strlen( $key ) >= 70 ) {
2813 - return '';
1961 + $key = '';
2814 1962 }
2815 1963 return $key;
2816 1964 }
2817 1965
2818 1966 /**
2819 - * @since 6.21 This is changed from `private` to `public`.
2820 - *
2821 1967 * @param int $num_chars
2822 - *
2823 1968 * @return string
2824 1969 */
2825 - public static function generate_new_key( $num_chars ) {
2826 - $max_slug_value = 36 ** $num_chars;
2827 -
2828 - // We want to have at least 2 characters in the slug.
2829 - $min_slug_value = 37;
2830 - return base_convert( random_int( $min_slug_value, $max_slug_value ), 10, 36 );
1970 + private static function generate_new_key( $num_chars ) {
1971 + $max_slug_value = pow( 36, $num_chars );
1972 + $min_slug_value = 37; // we want to have at least 2 characters in the slug
1973 + return base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
2831 1974 }
2832 1975
2833 1976 /**
2834 1977 * @param string $key
2835 - *
2836 1978 * @return string
2837 1979 */
2838 1980 private static function prevent_numeric_and_reserved_keys( $key ) {
2839 1981 if ( is_numeric( $key ) ) {
@@ -2847,14 +1989,12 @@
2847 1989 'editlink',
2848 1990 'siteurl',
2849 1991 'evenodd',
2850 1992 );
2851 -
2852 1993 if ( in_array( $key, $not_allowed, true ) ) {
2853 1994 $key .= 'a';
2854 1995 }
2855 1996 }
2856 -
2857 1997 return $key;
2858 1998 }
2859 1999
2860 2000 /**
@@ -2859,16 +1999,11 @@
2859 1999
2860 2000 /**
2861 2001 * Editing a Form or Entry
2862 2002 *
2863 - * @param object $record
2864 - * @param string $table
2865 - * @param array|string $fields
2866 - * @param bool $default
2867 - * @param array $post_values
2868 - * @param array $args
2003 + * @param string $table
2869 2004 *
2870 - * @return array|bool
2005 + * @return bool|array
2871 2006 */
2872 2007 public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) {
2873 2008 if ( ! $record ) {
2874 2009 return false;
@@ -2873,9 +2008,9 @@
2873 2008 if ( ! $record ) {
2874 2009 return false;
2875 2010 }
2876 2011
2877 - if ( ! $post_values ) {
2012 + if ( empty( $post_values ) ) {
2878 2013 $post_values = wp_unslash( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
2879 2014 }
2880 2015
2881 2016 $values = array(
@@ -2883,9 +2018,9 @@
2883 2018 'fields' => array(),
2884 2019 );
2885 2020
2886 2021 foreach ( array( 'name', 'description' ) as $var ) {
2887 - $default_val = $record->{$var} ?? '';
2022 + $default_val = isset( $record->{$var} ) ? $record->{$var} : '';
2888 2023 $values[ $var ] = self::get_param( $var, $default_val, 'get', 'wp_kses_post' );
2889 2024 unset( $var, $default_val );
2890 2025 }
2891 2026
@@ -2903,67 +2038,48 @@
2903 2038
2904 2039 return $values;
2905 2040 }
2906 2041
2907 - /**
2908 - * @param array|string $fields
2909 - * @param object $record
2910 - * @param array $values
2911 - * @param array $args
2912 - *
2913 - * @return void
2914 - */
2915 2042 private static function prepare_field_arrays( $fields, $record, array &$values, $args ) {
2916 - if ( ! $fields ) {
2917 - return;
2918 - }
2919 -
2920 - foreach ( (array) $fields as $field ) {
2921 - if ( ! self::is_admin_page() ) {
2922 - // Don't prep default values on the form settings page.
2923 - $field->default_value = apply_filters( 'frm_get_default_value', $field->default_value, $field, true );
2043 + if ( ! empty( $fields ) ) {
2044 + foreach ( (array) $fields as $field ) {
2045 + if ( ! self::is_admin_page() ) {
2046 + // Don't prep default values on the form settings page.
2047 + $field->default_value = apply_filters( 'frm_get_default_value', $field->default_value, $field, true );
2048 + }
2049 + $args['parent_form_id'] = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id;
2050 + self::fill_field_defaults( $field, $record, $values, $args );
2924 2051 }
2925 -
2926 - $args['parent_form_id'] = $args['parent_form_id'] ?? $field->form_id;
2927 - self::fill_field_defaults( $field, $record, $values, $args );
2928 2052 }
2929 2053 }
2930 2054
2931 - /**
2932 - * @param object $field
2933 - * @param object $record
2934 - * @param array $values
2935 - * @param array $args
2936 - *
2937 - * @return void
2938 - */
2939 2055 private static function fill_field_defaults( $field, $record, array &$values, $args ) {
2940 2056 $post_values = $args['post_values'];
2941 2057
2942 2058 if ( $args['default'] ) {
2943 2059 $meta_value = $field->default_value;
2944 - } elseif ( $record->post_id && self::pro_is_installed() && ! empty( $field->field_options['post_field'] ) ) {
2945 - if ( ! isset( $field->field_options['custom_field'] ) ) {
2946 - $field->field_options['custom_field'] = '';
2060 + } else {
2061 + if ( $record->post_id && self::pro_is_installed() && isset( $field->field_options['post_field'] ) && $field->field_options['post_field'] ) {
2062 + if ( ! isset( $field->field_options['custom_field'] ) ) {
2063 + $field->field_options['custom_field'] = '';
2064 + }
2065 + $meta_value = FrmProEntryMetaHelper::get_post_value(
2066 + $record->post_id,
2067 + $field->field_options['post_field'],
2068 + $field->field_options['custom_field'],
2069 + array(
2070 + 'truncate' => false,
2071 + 'type' => $field->type,
2072 + 'form_id' => $field->form_id,
2073 + 'field' => $field,
2074 + )
2075 + );
2076 + } else {
2077 + $meta_value = FrmEntryMeta::get_meta_value( $record, $field->id );
2947 2078 }
2079 + }
2948 2080
2949 - $meta_value = FrmProEntryMetaHelper::get_post_value(
2950 - $record->post_id,
2951 - $field->field_options['post_field'],
2952 - $field->field_options['custom_field'],
2953 - array(
2954 - 'truncate' => false,
2955 - 'type' => $field->type,
2956 - 'form_id' => $field->form_id,
2957 - 'field' => $field,
2958 - )
2959 - );
2960 - } else {
2961 - $meta_value = FrmEntryMeta::get_meta_value( $record, $field->id );
2962 - }//end if
2963 -
2964 - $field_type = $post_values['field_options'][ 'type_' . $field->id ] ?? $field->type;
2965 -
2081 + $field_type = isset( $post_values['field_options'][ 'type_' . $field->id ] ) ? $post_values['field_options'][ 'type_' . $field->id ] : $field->type;
2966 2082 if ( isset( $post_values['item_meta'][ $field->id ] ) ) {
2967 2083 $new_value = $post_values['item_meta'][ $field->id ];
2968 2084 self::unserialize_or_decode( $new_value );
2969 2085 } else {
@@ -2978,9 +2094,9 @@
2978 2094 $args['field_type'] = $field_type;
2979 2095
2980 2096 FrmFieldsHelper::prepare_edit_front_field( $field_array, $field, $values['id'], $args );
2981 2097
2982 - if ( empty( $field_array['unique'] ) ) {
2098 + if ( ! isset( $field_array['unique'] ) || ! $field_array['unique'] ) {
2983 2099 $field_array['unique_msg'] = '';
2984 2100 }
2985 2101
2986 2102 $field_array = array_merge( (array) $field->field_options, $field_array );
@@ -3009,15 +2125,12 @@
3009 2125 );
3010 2126 }
3011 2127
3012 2128 /**
3013 - * @param object $record
3014 2129 * @param string $table
3015 - * @param array $post_values
3016 - * @param array $values
3017 2130 */
3018 2131 private static function fill_form_opts( $record, $table, $post_values, array &$values ) {
3019 - if ( $table === 'entries' ) {
2132 + if ( $table == 'entries' ) {
3020 2133 $form = $record->form_id;
3021 2134 FrmForm::maybe_get_form( $form );
3022 2135 } else {
3023 2136 $form = $record;
@@ -3047,21 +2160,15 @@
3047 2160 }
3048 2161
3049 2162 /**
3050 2163 * Set to POST value or default
3051 - *
3052 - * @param array $post_values
3053 - * @param array $values
3054 - *
3055 - * @return void
3056 2164 */
3057 2165 private static function fill_form_defaults( $post_values, array &$values ) {
3058 2166 $form_defaults = FrmFormsHelper::get_default_opts();
3059 2167
3060 2168 foreach ( $form_defaults as $opt => $default ) {
3061 - // phpcs:ignore Universal.Operators.StrictComparisons
3062 2169 if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
3063 - $values[ $opt ] = $post_values['options'][ $opt ] ?? $default;
2170 + $values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default;
3064 2171 }
3065 2172
3066 2173 unset( $opt, $default );
3067 2174 }
@@ -3071,9 +2178,9 @@
3071 2178 }
3072 2179
3073 2180 foreach ( array( 'before', 'after', 'submit' ) as $h ) {
3074 2181 if ( ! isset( $values[ $h . '_html' ] ) ) {
3075 - $values[ $h . '_html' ] = $post_values['options'][ $h . '_html' ] ?? FrmFormsHelper::get_default_html( $h );
2182 + $values[ $h . '_html' ] = ( isset( $post_values['options'][ $h . '_html' ] ) ? $post_values['options'][ $h . '_html' ] : FrmFormsHelper::get_default_html( $h ) );
3076 2183 }
3077 2184 unset( $h );
3078 2185 }
3079 2186 }
@@ -3082,70 +2189,46 @@
3082 2189 * @since 2.2.10
3083 2190 *
3084 2191 * @param array $post_values
3085 2192 *
3086 - * @return bool|int
2193 + * @return boolean|int
3087 2194 */
3088 2195 public static function custom_style_value( $post_values ) {
3089 - if ( $post_values && isset( $post_values['options']['custom_style'] ) ) {
3090 - return absint( $post_values['options']['custom_style'] );
2196 + if ( ! empty( $post_values ) && isset( $post_values['options']['custom_style'] ) ) {
2197 + $custom_style = absint( $post_values['options']['custom_style'] );
2198 + } else {
2199 + $frm_settings = self::get_settings();
2200 + $custom_style = ( $frm_settings->load_style != 'none' );
3091 2201 }
3092 2202
3093 - $frm_settings = self::get_settings();
3094 - return $frm_settings->load_style !== 'none';
2203 + return $custom_style;
3095 2204 }
3096 2205
3097 - /**
3098 - * Truncate a string.
3099 - *
3100 - * Note: By default, this function will allow for a few additional characters more than $length.
3101 - * If a string has no spaces, it allows up to 50 additional characters. To force a true length limit,
3102 - * use $force_length_limit = true.
3103 - *
3104 - * @param mixed $original_string
3105 - * @param int|string $length
3106 - * @param int $minword
3107 - * @param string $continue
3108 - * @param bool $force_length_limit Force the final string to never exceed the length limit.
3109 - *
3110 - * @return string
3111 - */
3112 - public static function truncate( $original_string, $length, $minword = 3, $continue = '...', $force_length_limit = false ) {
3113 - if ( ! is_string( $original_string ) && ! is_int( $original_string ) ) {
2206 + public static function truncate( $str, $length, $minword = 3, $continue = '...' ) {
2207 + if ( is_array( $str ) ) {
3114 2208 return '';
3115 2209 }
3116 2210
3117 - $length = (int) $length;
2211 + $length = (int) $length;
2212 + $str = wp_strip_all_tags( $str );
2213 + $original_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $str ) );
3118 2214
3119 - if ( $length === 0 ) {
2215 + if ( $length == 0 ) {
3120 2216 return '';
3121 - }
3122 -
3123 - $str = wp_strip_all_tags( (string) $original_string );
3124 - $original_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $str ) );
3125 -
3126 - if ( $length <= 10 ) {
2217 + } elseif ( $length <= 10 ) {
3127 2218 $sub = self::mb_function( array( 'mb_substr', 'substr' ), array( $str, 0, $length ) );
3128 2219
3129 - if ( $force_length_limit ) {
3130 - return $sub;
3131 - }
2220 + return $sub . ( ( $length < $original_len ) ? $continue : '' );
2221 + }
3132 2222
3133 - return $sub . ( $length < $original_len ? $continue : '' );
3134 - }
2223 + $sub = '';
2224 + $len = 0;
3135 2225
3136 - $sub = '';
3137 - $len = 0;
3138 2226 $words = self::mb_function( array( 'mb_split', 'explode' ), array( ' ', $str ) );
3139 2227
3140 - if ( ! is_array( $words ) ) {
3141 - return $original_string;
3142 - }
3143 -
3144 2228 foreach ( $words as $word ) {
3145 - $part = ( $sub !== '' ? ' ' : '' ) . $word;
2229 + $part = ( ( $sub != '' ) ? ' ' : '' ) . $word;
3146 2230 $total_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub . $part ) );
3147 -
3148 2231 if ( $total_len > $length && substr_count( $sub, ' ' ) ) {
3149 2232 break;
3150 2233 }
3151 2234
@@ -3158,72 +2241,14 @@
3158 2241
3159 2242 unset( $total_len, $word );
3160 2243 }
3161 2244
3162 - $sub = self::maybe_force_truncate_on_string_with_no_spaces( $sub, $length, $force_length_limit );
3163 -
3164 - if ( $force_length_limit ) {
3165 - // Ensure the final string doesn't exceed the length limit.
3166 - $final_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub ) );
3167 -
3168 - if ( $final_len > $length ) {
3169 - return self::mb_function( array( 'mb_substr', 'substr' ), array( $sub, 0, $length ) );
3170 - }
3171 -
3172 - return $sub;
3173 - }
3174 -
3175 - return $sub . ( $len < $original_len ? $continue : '' );
2245 + return $sub . ( ( $len < $original_len ) ? $continue : '' );
3176 2246 }
3177 2247
3178 - /**
3179 - * If the string is still too long because there may not have been any spaces, force truncate.
3180 - *
3181 - * @since 6.5.4
3182 - *
3183 - * @param string $sub Current substring.
3184 - * @param int $length The length limit.
3185 - * @param bool $force_length_limit Force the string to not exceed the length limit.
3186 - *
3187 - * @return string
3188 - */
3189 - private static function maybe_force_truncate_on_string_with_no_spaces( $sub, $length, $force_length_limit = false ) {
3190 - if ( ! $force_length_limit ) {
3191 - if ( strlen( $sub ) < $length + 50 ) {
3192 - // If the string isn't way over the limit, leave it.
3193 - return $sub;
3194 - }
3195 -
3196 - $first_space = strpos( $sub, ' ', $length );
3197 -
3198 - if ( false !== $first_space ) {
3199 - // Ignore anything with spaces.
3200 - return $sub;
3201 - }
3202 -
3203 - return substr( $sub, 0, $length + 10 );
3204 - }
3205 -
3206 - // When force_length_limit is true, ensure the string doesn't exceed the length.
3207 - $final_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub ) );
3208 -
3209 - if ( $final_len > $length ) {
3210 - return self::mb_function( array( 'mb_substr', 'substr' ), array( $sub, 0, $length ) );
3211 - }
3212 -
3213 - return $sub;
3214 - }
3215 -
3216 - /**
3217 - * @param array $function_names
3218 - * @param array $args
3219 - *
3220 - * @return mixed
3221 - */
3222 2248 public static function mb_function( $function_names, $args ) {
3223 2249 $mb_function_name = $function_names[0];
3224 2250 $function_name = $function_names[1];
3225 -
3226 2251 if ( function_exists( $mb_function_name ) ) {
3227 2252 $function_name = $mb_function_name;
3228 2253 }
3229 2254
@@ -3229,21 +2254,14 @@
3229 2254
3230 2255 return call_user_func_array( $function_name, $args );
3231 2256 }
3232 2257
3233 - /**
3234 - * @param string $date
3235 - * @param string $date_format
3236 - * @param string $time_format
3237 - *
3238 - * @return string
3239 - */
3240 2258 public static function get_formatted_time( $date, $date_format = '', $time_format = '' ) {
3241 - if ( ! $date ) {
2259 + if ( empty( $date ) ) {
3242 2260 return $date;
3243 2261 }
3244 2262
3245 - if ( ! $date_format ) {
2263 + if ( empty( $date_format ) ) {
3246 2264 $date_format = get_option( 'date_format' );
3247 2265 }
3248 2266
3249 2267 if ( preg_match( '/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date ) && self::pro_is_installed() ) {
@@ -3251,10 +2269,10 @@
3251 2269 $date = FrmProAppHelper::convert_date( $date, $frmpro_settings->date_format, 'Y-m-d' );
3252 2270 }
3253 2271
3254 2272 $formatted = self::get_localized_date( $date_format, $date );
3255 - $do_time = gmdate( 'H:i:s', strtotime( $date ) ) !== '00:00:00';
3256 2273
2274 + $do_time = ( gmdate( 'H:i:s', strtotime( $date ) ) != '00:00:00' );
3257 2275 if ( $do_time ) {
3258 2276 $formatted .= self::add_time_to_date( $time_format, $date );
3259 2277 }
3260 2278
@@ -3260,52 +2278,45 @@
3260 2278
3261 2279 return $formatted;
3262 2280 }
3263 2281
3264 - /**
3265 - * @param string $time_format
3266 - * @param string $date
3267 - *
3268 - * @return string
3269 - */
3270 2282 private static function add_time_to_date( $time_format, $date ) {
3271 - if ( ! $time_format ) {
2283 + if ( empty( $time_format ) ) {
3272 2284 $time_format = get_option( 'time_format' );
3273 2285 }
3274 2286
3275 2287 $trimmed_format = trim( $time_format );
3276 -
3277 - if ( $time_format && $trimmed_format ) {
3278 - return ' ' . __( 'at', 'formidable' ) . ' ' . self::get_localized_date( $time_format, $date );
2288 + $time = '';
2289 + if ( $time_format && ! empty( $trimmed_format ) ) {
2290 + $time = ' ' . __( 'at', 'formidable' ) . ' ' . self::get_localized_date( $time_format, $date );
3279 2291 }
3280 2292
3281 - return '';
2293 + return $time;
3282 2294 }
3283 2295
3284 2296 /**
3285 2297 * @since 2.0.8
3286 - *
3287 - * @param string $date_format
3288 - * @param string $date
3289 - *
3290 - * @return string
3291 2298 */
3292 2299 public static function get_localized_date( $date_format, $date ) {
3293 2300 $date = get_date_from_gmt( $date );
2301 +
3294 2302 return date_i18n( $date_format, strtotime( $date ) );
3295 2303 }
3296 2304
3297 2305 /**
3298 - * Gets the time ago in words.
2306 + * Gets the time ago in words
3299 2307 *
3300 - * @param int $from In seconds.
3301 - * @param int|string $to In seconds.
3302 - * @param int|string $levels Number of time units to include or a specific unit.
2308 + * @param int $from in seconds
2309 + * @param int|string $to in seconds
3303 2310 *
3304 - * @return string Time ago.
2311 + * @return string $time_ago
3305 2312 */
3306 2313 public static function human_time_diff( $from, $to = '', $levels = 1 ) {
3307 - $now = ! $to && 0 !== $to ? new DateTime() : new DateTime( '@' . $to );
2314 + if ( empty( $to ) ) {
2315 + $now = new DateTime();
2316 + } else {
2317 + $now = new DateTime( '@' . $to );
2318 + }
3308 2319 $ago = new DateTime( '@' . $from );
3309 2320
3310 2321 // Get the time difference
3311 2322 $diff_object = $now->diff( $ago );
@@ -3311,9 +2322,9 @@
3311 2322 $diff_object = $now->diff( $ago );
3312 2323 $diff = get_object_vars( $diff_object );
3313 2324
3314 2325 // Add week amount and update day amount
3315 - $diff['w'] = floor( $diff['d'] / 7 );
2326 + $diff['w'] = floor( $diff['d'] / 7 );
3316 2327 $diff['d'] -= $diff['w'] * 7;
3317 2328
3318 2329 $time_strings = self::get_time_strings();
3319 2330
@@ -3319,11 +2330,10 @@
3319 2330
3320 2331 if ( ! is_numeric( $levels ) ) {
3321 2332 // Show time in specified unit.
3322 2333 $levels = self::get_unit( $levels );
3323 -
3324 2334 if ( isset( $time_strings[ $levels ] ) ) {
3325 - $diff = array(
2335 + $diff = array(
3326 2336 $levels => self::time_format( $levels, $diff ),
3327 2337 );
3328 2338 $time_strings = array(
3329 2339 $levels => $time_strings[ $levels ],
@@ -3328,14 +2338,13 @@
3328 2338 $time_strings = array(
3329 2339 $levels => $time_strings[ $levels ],
3330 2340 );
3331 2341 }
3332 -
3333 2342 $levels = 1;
3334 2343 }
3335 2344
3336 2345 foreach ( $time_strings as $k => $v ) {
3337 - if ( ! empty( $diff[ $k ] ) ) {
2346 + if ( isset( $diff[ $k ] ) && $diff[ $k ] ) {
3338 2347 $time_strings[ $k ] = $diff[ $k ] . ' ' . ( $diff[ $k ] > 1 ? $v[1] : $v[0] );
3339 2348 } elseif ( isset( $diff[ $k ] ) && count( $time_strings ) === 1 ) {
3340 2349 // Account for 0.
3341 2350 $time_strings[ $k ] = $diff[ $k ] . ' ' . $v[1];
@@ -3343,21 +2352,17 @@
3343 2352 unset( $time_strings[ $k ] );
3344 2353 }
3345 2354 }
3346 2355
3347 - $levels_deep = apply_filters( 'frm_time_ago_levels', $levels, compact( 'time_strings', 'from', 'to' ) );
3348 - $time_strings = array_slice( $time_strings, 0, absint( $levels_deep ) );
2356 + $levels_deep = apply_filters( 'frm_time_ago_levels', $levels, compact( 'time_strings', 'from', 'to' ) );
2357 + $time_strings = array_slice( $time_strings, 0, absint( $levels_deep ) );
2358 + $time_ago_string = implode( ' ', $time_strings );
3349 2359
3350 - return implode( ' ', $time_strings );
2360 + return $time_ago_string;
3351 2361 }
3352 2362
3353 2363 /**
3354 2364 * @since 4.05.01
3355 - *
3356 - * @param string $unit
3357 - * @param array $diff
3358 - *
3359 - * @return int
3360 2365 */
3361 2366 private static function time_format( $unit, $diff ) {
3362 2367 $return = array(
3363 2368 'y' => 'y',
@@ -3362,14 +2367,14 @@
3362 2367 $return = array(
3363 2368 'y' => 'y',
3364 2369 'd' => 'days',
3365 2370 );
3366 -
3367 2371 if ( isset( $return[ $unit ] ) ) {
3368 2372 return $diff[ $return[ $unit ] ];
3369 2373 }
3370 2374
3371 2375 $total = $diff['days'] * self::convert_time( 'd', $unit );
2376 +
3372 2377 $times = array( 'h', 'i', 's' );
3373 2378
3374 2379 foreach ( $times as $time ) {
3375 2380 if ( ! isset( $diff[ $time ] ) ) {
@@ -3383,13 +2388,8 @@
3383 2388 }
3384 2389
3385 2390 /**
3386 2391 * @since 4.05.01
3387 - *
3388 - * @param string $from
3389 - * @param string $to
3390 - *
3391 - * @return int
3392 2392 */
3393 2393 private static function convert_time( $from, $to ) {
3394 2394 $convert = array(
3395 2395 's' => 1,
@@ -3405,35 +2405,28 @@
3405 2405 }
3406 2406
3407 2407 /**
3408 2408 * @since 4.05.01
3409 - *
3410 - * @param string $unit
3411 - *
3412 - * @return int|string
3413 2409 */
3414 2410 private static function get_unit( $unit ) {
3415 2411 $units = self::get_time_strings();
3416 -
3417 2412 if ( isset( $units[ $unit ] ) || is_numeric( $unit ) ) {
3418 2413 return $unit;
3419 2414 }
3420 2415
3421 2416 foreach ( $units as $u => $strings ) {
3422 - if ( in_array( $unit, $strings, true ) ) {
2417 + if ( in_array( $unit, $strings ) ) {
3423 2418 return $u;
3424 2419 }
3425 2420 }
3426 -
3427 2421 return 1;
3428 2422 }
3429 2423
3430 2424 /**
3431 2425 * Get the translatable time strings. The untranslated version is a failsafe
3432 - * in case languages are changing for the unit set in the shortcode.
2426 + * in case langauges are changing for the unit set in the shortcode.
3433 2427 *
3434 2428 * @since 2.0.20
3435 - *
3436 2429 * @return array
3437 2430 */
3438 2431 private static function get_time_strings() {
3439 2432 return array(
@@ -3477,48 +2470,35 @@
3477 2470
3478 2471 // Pagination Methods.
3479 2472
3480 2473 /**
3481 - * @param int $r_count
3482 - * @param int $current_p
3483 - * @param int $p_size
3484 - *
3485 - * @return int
2474 + * @param integer $current_p
3486 2475 */
3487 2476 public static function get_last_record_num( $r_count, $current_p, $p_size ) {
3488 - return $r_count < $current_p * $p_size ? $r_count : $current_p * $p_size;
2477 + return ( ( $r_count < ( $current_p * $p_size ) ) ? $r_count : ( $current_p * $p_size ) );
3489 2478 }
3490 2479
3491 2480 /**
3492 - * @param int $r_count
3493 - * @param int $current_p
3494 - * @param int $p_size
3495 - *
3496 - * @return int
2481 + * @param integer $current_p
3497 2482 */
3498 2483 public static function get_first_record_num( $r_count, $current_p, $p_size ) {
3499 - // phpcs:ignore Universal.Operators.StrictComparisons
3500 2484 if ( $current_p == 1 ) {
3501 2485 return 1;
2486 + } else {
2487 + return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 );
3502 2488 }
3503 - return self::get_last_record_num( $r_count, $current_p - 1, $p_size ) + 1;
3504 2489 }
3505 2490
3506 2491 /**
3507 - * @param array $json_vars
3508 - *
3509 2492 * @return array
3510 2493 */
3511 2494 public static function json_to_array( $json_vars ) {
3512 2495 $vars = array();
3513 -
3514 2496 foreach ( $json_vars as $jv ) {
3515 2497 $jv_name = explode( '[', $jv['name'] );
3516 2498 $last = count( $jv_name ) - 1;
3517 -
3518 2499 foreach ( $jv_name as $p => $n ) {
3519 2500 $name = trim( $n, ']' );
3520 -
3521 2501 if ( ! isset( $l1 ) ) {
3522 2502 $l1 = $name;
3523 2503 }
3524 2504
@@ -3529,9 +2509,9 @@
3529 2509 if ( ! isset( $l3 ) ) {
3530 2510 $l3 = $name;
3531 2511 }
3532 2512
3533 - $this_val = $p === $last ? $jv['value'] : array();
2513 + $this_val = ( $p == $last ) ? $jv['value'] : array();
3534 2514
3535 2515 switch ( $p ) {
3536 2516 case 0:
3537 2517 $l1 = $name;
@@ -3553,12 +2533,12 @@
3553 2533 self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] );
3554 2534 }
3555 2535
3556 2536 unset( $this_val, $n );
3557 - }//end foreach
2537 + }
3558 2538
3559 2539 unset( $last, $jv );
3560 - }//end foreach
2540 + }
3561 2541
3562 2542 return $vars;
3563 2543 }
3564 2544
@@ -3564,15 +2544,10 @@
3564 2544
3565 2545 /**
3566 2546 * @param string $name
3567 2547 * @param string $l1
3568 - * @param mixed $val
3569 - * @param array $vars
3570 - *
3571 - * @return void
3572 2548 */
3573 2549 public static function add_value_to_array( $name, $l1, $val, &$vars ) {
3574 - // phpcs:ignore Universal.Operators.StrictComparisons
3575 2550 if ( $name == '' ) {
3576 2551 $vars[] = $val;
3577 2552 } elseif ( ! isset( $vars[ $l1 ] ) ) {
3578 2553 $vars[ $l1 ] = $val;
@@ -3578,26 +2553,18 @@
3578 2553 $vars[ $l1 ] = $val;
3579 2554 }
3580 2555 }
3581 2556
3582 - /**
3583 - * @param string $name
3584 - * @param string $class
3585 - * @param string $form_name
3586 - *
3587 - * @return void
3588 - */
3589 2557 public static function maybe_add_tooltip( $name, $class = 'closed', $form_name = '' ) {
3590 2558 $tooltips = array(
3591 2559 'action_title' => __( 'Give this action a label for easy reference.', 'formidable' ),
3592 - 'email_to' => __( 'Add one or more recipient addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com. [default-email] is the address set in the global "Default Email Address" settings.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
2560 + 'email_to' => __( 'Add one or more recipient addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com. [admin_email] is the address set in WP General Settings.', 'formidable' ),
3593 2561 'cc' => __( 'Add CC addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
3594 2562 'bcc' => __( 'Add BCC addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
3595 - 'reply_to' => __( 'If you would like a different reply to address than the "from" address, add a single address here. FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
2563 + 'reply_to' => __( 'If you would like a different reply to address than the "from" address, add a single address here. FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
3596 2564 'from' => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <john@example.com> or john@example.com.', 'formidable' ),
3597 2565 /* translators: %1$s: Form name, %2$s: Date */
3598 - 'email_subject' => esc_attr( sprintf( __( 'If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable' ), $form_name, self::site_name() ) ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
3599 - 'new_tab' => __( 'This option will open the link in a new browser tab. Please note that some popup blockers may prevent this from happening, in which case the link will be displayed.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
2566 + 'email_subject' => esc_attr( sprintf( __( 'If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable' ), $form_name, self::site_name() ) ),
3600 2567 );
3601 2568
3602 2569 if ( ! isset( $tooltips[ $name ] ) ) {
3603 2570 return;
@@ -3602,9 +2569,9 @@
3602 2569 if ( ! isset( $tooltips[ $name ] ) ) {
3603 2570 return;
3604 2571 }
3605 2572
3606 - if ( 'open' === $class ) {
2573 + if ( 'open' == $class ) {
3607 2574 echo ' frm_help"';
3608 2575 } else {
3609 2576 echo ' class="frm_help"';
3610 2577 }
@@ -3610,9 +2577,9 @@
3610 2577 }
3611 2578
3612 2579 echo ' title="' . esc_attr( $tooltips[ $name ] );
3613 2580
3614 - if ( 'open' !== $class ) {
2581 + if ( 'open' != $class ) {
3615 2582 echo '"';
3616 2583 }
3617 2584 }
3618 2585
@@ -3617,28 +2584,20 @@
3617 2584 }
3618 2585
3619 2586 /**
3620 2587 * Add the current_page class to that page in the form nav
3621 - *
3622 - * @param int|string $page
3623 - * @param int|string $current_page
3624 - * @param array $action
3625 - *
3626 - * @return void
3627 2588 */
3628 2589 public static function select_current_page( $page, $current_page, $action = array() ) {
3629 - // phpcs:ignore Universal.Operators.StrictComparisons
3630 2590 if ( $current_page != $page ) {
3631 2591 return;
3632 2592 }
3633 2593
3634 2594 $frm_action = self::simple_get( 'frm_action', 'sanitize_title' );
3635 -
3636 2595 if ( 'lite-reports' === $frm_action ) {
3637 2596 $frm_action = 'reports';
3638 2597 }
3639 2598
3640 - if ( ! $action || ( $frm_action && in_array( $frm_action, $action, true ) ) ) {
2599 + if ( empty( $action ) || ( ! empty( $frm_action ) && in_array( $frm_action, $action ) ) ) {
3641 2600 echo ' class="current_page"';
3642 2601 }
3643 2602 }
3644 2603
@@ -3668,19 +2627,14 @@
3668 2627
3669 2628 // Add extra slashes for \r\n since WP strips them.
3670 2629 $post_content = str_replace( array( '\\r', '\\n', '\\u', '\\t' ), array( '\\\\r', '\\\\n', '\\\\u', '\\\\t' ), $post_content );
3671 2630
3672 - // Allow for &quot
3673 - return str_replace( '&quot;', '\\"', $post_content );
2631 + // allow for &quot
2632 + $post_content = str_replace( '&quot;', '\\"', $post_content );
2633 +
2634 + return $post_content;
3674 2635 }
3675 2636
3676 - /**
3677 - * @param array|string $val
3678 - * @param int|string $key
3679 - * @param array $post_content
3680 - *
3681 - * @return void
3682 - */
3683 2637 private static function prepare_action_slashes( $val, $key, &$post_content ) {
3684 2638 if ( ! isset( $post_content[ $key ] ) || is_numeric( $val ) ) {
3685 2639 return;
3686 2640 }
@@ -3689,28 +2643,22 @@
3689 2643 foreach ( $val as $k1 => $v1 ) {
3690 2644 self::prepare_action_slashes( $v1, $k1, $post_content[ $key ] );
3691 2645 unset( $k1, $v1 );
3692 2646 }
2647 + } else {
2648 + // Strip all slashes so everything is the same, no matter where the value is coming from
2649 + $val = stripslashes( $val );
3693 2650
3694 - return;
2651 + // Add backslashes before double quotes and forward slashes only
2652 + $post_content[ $key ] = addcslashes( $val, '"\\/' );
3695 2653 }
3696 -
3697 - // Strip all slashes so everything is the same, no matter where the value is coming from
3698 - $val = stripslashes( $val );
3699 -
3700 - // Add backslashes before double quotes and forward slashes only
3701 - $post_content[ $key ] = addcslashes( $val, '"\\/' );
3702 2654 }
3703 2655
3704 2656 /**
3705 - * Check for either json or serialized data. This is temporary while transitioning
2657 + * Check for either json or serilized data. This is temporary while transitioning
3706 2658 * all data to json.
3707 2659 *
3708 2660 * @since 4.02.03
3709 - *
3710 - * @param array|string $value
3711 - *
3712 - * @return void
3713 2661 */
3714 2662 public static function unserialize_or_decode( &$value ) {
3715 2663 if ( is_array( $value ) ) {
3716 2664 return;
@@ -3715,34 +2663,13 @@
3715 2663 if ( is_array( $value ) ) {
3716 2664 return;
3717 2665 }
3718 2666
3719 - $value = is_serialized( $value ) ? self::maybe_unserialize_array( $value ) : self::maybe_json_decode( $value, false );
3720 - }
3721 -
3722 - /**
3723 - * Safely unserialize an array if necessary.
3724 - * This function doesn't actually use unserialize. The string is parsed instead.
3725 - *
3726 - * @since 6.2
3727 - *
3728 - * @param mixed $value
3729 - *
3730 - * @return mixed
3731 - */
3732 - public static function maybe_unserialize_array( $value ) {
3733 - if ( ! is_string( $value ) ) {
3734 - return $value;
2667 + if ( is_serialized( $value ) ) {
2668 + $value = maybe_unserialize( $value );
2669 + } else {
2670 + $value = self::maybe_json_decode( $value, false );
3735 2671 }
3736 -
3737 - // Since we only expect an array, skip anything that doesn't start with a:.
3738 - if ( ! is_serialized( $value ) || ! str_starts_with( $value, 'a:' ) ) {
3739 - return $value;
3740 - }
3741 -
3742 - $parsed = FrmSerializedStringParserHelper::get()->parse( $value );
3743 -
3744 - return is_array( $parsed ) ? $parsed : $value;
3745 2672 }
3746 2673
3747 2674 /**
3748 2675 * Decode a JSON string.
@@ -3747,12 +2674,11 @@
3747 2674 /**
3748 2675 * Decode a JSON string.
3749 2676 * Do not switch shortcodes like [24] to array unless intentional ie XML values.
3750 2677 *
3751 - * @param array|string|null $string
3752 - * @param bool $single_to_array
3753 - *
3754 - * @return array|string|null
2678 + * @param mixed $string
2679 + * @param bool $single_to_array
2680 + * @return mixed
3755 2681 */
3756 2682 public static function maybe_json_decode( $string, $single_to_array = true ) {
3757 2683 if ( is_array( $string ) || is_null( $string ) ) {
3758 2684 return $string;
@@ -3757,51 +2683,21 @@
3757 2683 if ( is_array( $string ) || is_null( $string ) ) {
3758 2684 return $string;
3759 2685 }
3760 2686
3761 - $new_string = json_decode( $string, true );
3762 - $single_value = false;
3763 -
3764 - if ( ! $single_to_array ) {
3765 - $single_value = is_array( $new_string ) && count( $new_string ) === 1 && isset( $new_string[0] );
3766 - }
3767 -
3768 - if ( json_last_error() === JSON_ERROR_NONE && is_array( $new_string ) && ! $single_value ) {
3769 - return $new_string;
3770 - }
3771 -
3772 - return $string;
3773 - }
3774 -
3775 - /**
3776 - * @since 6.2.3
3777 - *
3778 - * @param string $value
3779 - *
3780 - * @return string
3781 - */
3782 - public static function maybe_utf8_encode( $value ) {
3783 - $from_format = 'ISO-8859-1';
3784 - $to_format = 'UTF-8';
3785 -
3786 - if ( function_exists( 'mb_check_encoding' ) && function_exists( 'mb_convert_encoding' ) ) {
3787 - if ( mb_check_encoding( $value, $from_format ) ) {
3788 - return mb_convert_encoding( $value, $to_format, $from_format );
2687 + $new_string = json_decode( $string, true );
2688 + if ( function_exists( 'json_last_error' ) ) {
2689 + // php 5.3+
2690 + $single_value = false;
2691 + if ( ! $single_to_array ) {
2692 + $single_value = is_array( $new_string ) && count( $new_string ) === 1 && isset( $new_string[0] );
3789 2693 }
3790 -
3791 - return $value;
3792 - }
3793 -
3794 - if ( function_exists( 'iconv' ) ) {
3795 - $converted = iconv( $from_format, $to_format, $value );
3796 -
3797 - // Value is false if $value is not ISO-8859-1.
3798 - if ( false !== $converted ) {
3799 - return $converted;
2694 + if ( json_last_error() == JSON_ERROR_NONE && is_array( $new_string ) && ! $single_value ) {
2695 + $string = $new_string;
3800 2696 }
3801 2697 }
3802 2698
3803 - return $value;
2699 + return $string;
3804 2700 }
3805 2701
3806 2702 /**
3807 2703 * Reformat the json serialized array in name => value array.
@@ -3806,12 +2702,8 @@
3806 2702 /**
3807 2703 * Reformat the json serialized array in name => value array.
3808 2704 *
3809 2705 * @since 4.02.03
3810 - *
3811 - * @param array $form
3812 - *
3813 - * @return void
3814 2706 */
3815 2707 public static function format_form_data( &$form ) {
3816 2708 $formatted = array();
3817 2709
@@ -3818,21 +2710,18 @@
3818 2710 foreach ( $form as $input ) {
3819 2711 if ( ! isset( $input['name'] ) ) {
3820 2712 continue;
3821 2713 }
3822 -
3823 2714 $key = $input['name'];
3824 -
3825 - if ( ! isset( $formatted[ $key ] ) ) {
2715 + if ( isset( $formatted[ $key ] ) ) {
2716 + if ( is_array( $formatted[ $key ] ) ) {
2717 + $formatted[ $key ][] = $input['value'];
2718 + } else {
2719 + $formatted[ $key ] = array( $formatted[ $key ], $input['value'] );
2720 + }
2721 + } else {
3826 2722 $formatted[ $key ] = $input['value'];
3827 - continue;
3828 2723 }
3829 -
3830 - if ( is_array( $formatted[ $key ] ) ) {
3831 - $formatted[ $key ][] = $input['value'];
3832 - } else {
3833 - $formatted[ $key ] = array( $formatted[ $key ], $input['value'] );
3834 - }
3835 2724 }
3836 2725
3837 2726 parse_str( http_build_query( $formatted ), $form );
3838 2727 }
@@ -3838,34 +2727,30 @@
3838 2727 }
3839 2728
3840 2729 /**
3841 2730 * @since 4.02.03
3842 - *
3843 - * @param array|string $value
3844 - *
3845 - * @return string
3846 2731 */
3847 2732 public static function maybe_json_encode( $value ) {
3848 - return is_array( $value ) ? wp_json_encode( $value ) : $value;
2733 + if ( is_array( $value ) ) {
2734 + $value = wp_json_encode( $value );
2735 + }
2736 + return $value;
3849 2737 }
3850 2738
3851 2739 /**
3852 - * Echo The javascript to open and highlight the Formidable menu
3853 - *
3854 2740 * @since 1.07.10
3855 2741 *
3856 - * @param string $post_type The name of the post type that may need to be highlighted.
3857 - *
3858 - * @return void
2742 + * @param string $post_type The name of the post type that may need to be highlighted
2743 + * echo The javascript to open and highlight the Formidable menu
3859 2744 */
3860 2745 public static function maybe_highlight_menu( $post_type ) {
3861 2746 global $post;
3862 2747
3863 - if ( isset( $_REQUEST['post_type'] ) && $_REQUEST['post_type'] !== $post_type ) {
2748 + if ( isset( $_REQUEST['post_type'] ) && $_REQUEST['post_type'] != $post_type ) {
3864 2749 return;
3865 2750 }
3866 2751
3867 - if ( is_object( $post ) && $post->post_type !== $post_type ) {
2752 + if ( is_object( $post ) && $post->post_type != $post_type ) {
3868 2753 return;
3869 2754 }
3870 2755
3871 2756 self::load_admin_wide_js();
@@ -3875,15 +2760,12 @@
3875 2760 /**
3876 2761 * Load the JS file on non-Formidable pages in the admin area
3877 2762 *
3878 2763 * @since 2.0
3879 - *
3880 - * @param bool $load
3881 - *
3882 - * @return void
3883 2764 */
3884 2765 public static function load_admin_wide_js( $load = true ) {
3885 - wp_register_script( 'formidable_admin_global', self::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery' ), self::plugin_version() );
2766 + $version = self::plugin_version();
2767 + wp_register_script( 'formidable_admin_global', self::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery' ), $version );
3886 2768
3887 2769 $global_strings = array(
3888 2770 'updating_msg' => __( 'Please wait while your site updates.', 'formidable' ),
3889 2771 'deauthorize' => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ),
@@ -3889,13 +2771,12 @@
3889 2771 'deauthorize' => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ),
3890 2772 'url' => self::plugin_url(),
3891 2773 'app_url' => 'https://formidableforms.com/',
3892 2774 'applicationsUrl' => admin_url( 'admin.php?page=formidable-applications' ),
3893 - 'canAccessApplicationDashboard' => current_user_can( is_callable( 'FrmProApplicationsHelper::get_required_templates_capability' ) ? FrmProApplicationsHelper::get_required_templates_capability() : 'frm_edit_forms' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
2775 + 'canAccessApplicationDashboard' => current_user_can( is_callable( 'FrmProApplicationsHelper::get_required_templates_capability' ) ? FrmProApplicationsHelper::get_required_templates_capability() : 'frm_edit_forms' ),
3894 2776 'loading' => __( 'Loading&hellip;', 'formidable' ),
3895 2777 'nonce' => wp_create_nonce( 'frm_ajax' ),
3896 2778 'proIncludesSliderJs' => is_callable( 'FrmProFormsHelper::prepare_custom_currency' ),
3897 - 'inboxSlideIn' => FrmInbox::get_inbox_slide_in_value_for_js(),
3898 2779 );
3899 2780 wp_localize_script( 'formidable_admin_global', 'frmGlobal', $global_strings );
3900 2781
3901 2782 if ( $load ) {
@@ -3904,10 +2785,8 @@
3904 2785 }
3905 2786
3906 2787 /**
3907 2788 * @since 2.0.9
3908 - *
3909 - * @return void
3910 2789 */
3911 2790 public static function load_font_style() {
3912 2791 wp_enqueue_style( 'frm_fonts', self::plugin_url() . '/css/frm_fonts.css', array(), self::plugin_version() );
3913 2792 }
@@ -3913,224 +2792,100 @@
3913 2792 }
3914 2793
3915 2794 /**
3916 2795 * @param string $location
3917 - *
3918 - * @return void
3919 2796 */
3920 2797 public static function localize_script( $location ) {
3921 - global $wp_scripts, $wp_version;
2798 + global $wp_scripts;
3922 2799
2800 + $ajax_url = admin_url( 'admin-ajax.php', is_ssl() ? 'admin' : 'http' );
2801 + $ajax_url = apply_filters( 'frm_ajax_url', $ajax_url );
2802 +
3923 2803 $script_strings = array(
3924 - 'ajax_url' => esc_url_raw( self::get_ajax_url() ),
3925 - 'images_url' => self::plugin_url() . '/images',
3926 - 'loading' => __( 'Loading&hellip;', 'formidable' ),
3927 - 'remove' => __( 'Remove', 'formidable' ),
3928 - 'offset' => apply_filters( 'frm_scroll_offset', 4 ),
3929 - 'nonce' => wp_create_nonce( 'frm_ajax' ),
3930 - 'id' => __( 'ID', 'formidable' ),
3931 - 'no_results' => __( 'No results match', 'formidable' ),
3932 - 'file_spam' => __( 'That file looks like Spam.', 'formidable' ),
3933 - 'calc_error' => __( 'There is an error in the calculation in the field with key', 'formidable' ),
3934 - 'empty_fields' => __( 'Please complete the preceding required fields before uploading a file.', 'formidable' ),
3935 - 'focus_first_error' => self::should_focus_first_error(),
3936 - 'include_alert_role' => self::should_include_alert_role_on_field_errors(),
3937 - // We need to keep this setting for a few versions because Pro checks for this.
3938 - 'include_resend_email' => false,
2804 + 'ajax_url' => $ajax_url,
2805 + 'images_url' => self::plugin_url() . '/images',
2806 + 'loading' => __( 'Loading&hellip;', 'formidable' ),
2807 + 'remove' => __( 'Remove', 'formidable' ),
2808 + 'offset' => apply_filters( 'frm_scroll_offset', 4 ),
2809 + 'nonce' => wp_create_nonce( 'frm_ajax' ),
2810 + 'id' => __( 'ID', 'formidable' ),
2811 + 'no_results' => __( 'No results match', 'formidable' ),
2812 + 'file_spam' => __( 'That file looks like Spam.', 'formidable' ),
2813 + 'calc_error' => __( 'There is an error in the calculation in the field with key', 'formidable' ),
2814 + 'empty_fields' => __( 'Please complete the preceding required fields before uploading a file.', 'formidable' ),
2815 + 'focus_first_error' => self::should_focus_first_error(),
2816 + 'include_alert_role' => self::should_include_alert_role_on_field_errors(),
3939 2817 );
3940 2818
3941 2819 $data = $wp_scripts->get_data( 'formidable', 'data' );
3942 -
3943 - if ( ! $data ) {
2820 + if ( empty( $data ) ) {
3944 2821 wp_localize_script( 'formidable', 'frm_js', $script_strings );
3945 2822 }
3946 2823
3947 - if ( $location === 'admin' ) {
2824 + if ( $location == 'admin' ) {
2825 + $frm_settings = self::get_settings();
3948 2826 $admin_script_strings = array(
3949 - 'desc' => __( '(Click to add description)', 'formidable' ),
3950 - 'blank' => __( '(Blank)', 'formidable' ),
3951 - 'no_label' => self::get_no_label_text(),
3952 - 'ok' => __( 'OK', 'formidable' ),
3953 - 'cancel' => __( 'Cancel', 'formidable' ),
3954 - 'default_label' => __( 'Default', 'formidable' ),
3955 - 'clear_default' => __( 'Clear default value when typing', 'formidable' ),
3956 - 'no_clear_default' => __( 'Do not clear default value when typing', 'formidable' ),
3957 - 'valid_default' => __( 'Default value will pass form validation', 'formidable' ),
3958 - 'no_valid_default' => __( 'Default value will NOT pass form validation', 'formidable' ),
3959 - 'confirm' => __( 'Are you sure?', 'formidable' ),
3960 - 'conf_delete' => __( 'Are you sure you want to delete this field and all data associated with it?', 'formidable' ),
3961 - 'conf_delete_sec' => __( 'All fields inside this Section will be deleted along with their data. Are you sure you want to delete this group of fields?', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
3962 - 'conf_no_repeat' => __( 'Warning: If you have entries with multiple rows, all but the first row will be lost.', 'formidable' ),
3963 - 'default_unique' => FrmFieldsHelper::default_unique_msg(),
3964 - 'default_conf' => __( 'The entered values do not match', 'formidable' ),
3965 - 'enter_email' => __( 'Enter Email', 'formidable' ),
3966 - 'confirm_email' => __( 'Confirm Email', 'formidable' ),
3967 - 'conditional_text' => __( 'Conditional content here', 'formidable' ),
3968 - 'new_option' => __( 'New Option', 'formidable' ),
3969 - 'css_invalid_size' => __( 'In certain browsers (e.g. Firefox) text will not display correctly if the field height is too small relative to the field padding and text size. Please increase your field height or decrease your field padding.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
3970 - 'enter_password' => __( 'Enter Password', 'formidable' ),
3971 - 'confirm_password' => __( 'Confirm Password', 'formidable' ),
3972 - 'import_complete' => __( 'Import Complete', 'formidable' ),
3973 - 'updating' => __( 'Please wait while your site updates.', 'formidable' ),
3974 - 'no_save_warning' => __( 'Warning: There is no way to retrieve unsaved entries.', 'formidable' ),
3975 - 'private_label' => __( 'Private', 'formidable' ),
3976 - 'jquery_ui_url' => '',
3977 - 'pro_url' => is_callable( 'FrmProAppHelper::plugin_url' ) ? FrmProAppHelper::plugin_url() : '',
3978 - 'no_licenses' => __( 'No new licenses were found', 'formidable' ),
3979 - 'unmatched_parens' => __( 'This calculation has at least one unmatched ( ) { } [ ].', 'formidable' ),
3980 - 'view_shortcodes' => __( 'This calculation may have shortcodes that work in Views but not forms.', 'formidable' ),
3981 - 'text_shortcodes' => __( 'This calculation may have shortcodes that work in text calculations but not numeric calculations.', 'formidable' ),
3982 - /* translators: %d is the number of allowed actions per form */
3983 - 'only_one_action' => sprintf( __( 'This form action is limited to %d per form.', 'formidable' ), 1 ),
3984 - 'edit_action_text' => __( 'Please edit the existing form action.', 'formidable' ),
3985 - 'only_one_payment_action' => __( 'This form already has a payment action, and is currently limited to a single payment action.', 'formidable' ),
3986 - 'only_one_stripe_action' => __( 'This form already has a payment action. Multiple Stripe actions are available when using the Stripe add-on, available for Formidable Business licenses and higher.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
3987 - 'unsafe_params' => FrmFormsHelper::reserved_words(),
2827 + 'desc' => __( '(Click to add description)', 'formidable' ),
2828 + 'blank' => __( '(Blank)', 'formidable' ),
2829 + 'no_label' => __( '(no label)', 'formidable' ),
2830 + 'saving' => esc_attr( __( 'Saving', 'formidable' ) ),
2831 + 'saved' => esc_attr( __( 'Saved', 'formidable' ) ),
2832 + 'ok' => __( 'OK', 'formidable' ),
2833 + 'cancel' => __( 'Cancel', 'formidable' ),
2834 + 'default_label' => __( 'Default', 'formidable' ),
2835 + 'clear_default' => __( 'Clear default value when typing', 'formidable' ),
2836 + 'no_clear_default' => __( 'Do not clear default value when typing', 'formidable' ),
2837 + 'valid_default' => __( 'Default value will pass form validation', 'formidable' ),
2838 + 'no_valid_default' => __( 'Default value will NOT pass form validation', 'formidable' ),
2839 + 'caution' => __( 'Heads up', 'formidable' ),
2840 + 'confirm' => __( 'Are you sure?', 'formidable' ),
2841 + 'conf_delete' => __( 'Are you sure you want to delete this field and all data associated with it?', 'formidable' ),
2842 + 'conf_delete_sec' => __( 'All fields inside this Section will be deleted along with their data. Are you sure you want to delete this group of fields?', 'formidable' ),
2843 + 'conf_no_repeat' => __( 'Warning: If you have entries with multiple rows, all but the first row will be lost.', 'formidable' ),
2844 + 'default_unique' => $frm_settings->unique_msg,
2845 + 'default_conf' => __( 'The entered values do not match', 'formidable' ),
2846 + 'enter_email' => __( 'Enter Email', 'formidable' ),
2847 + 'confirm_email' => __( 'Confirm Email', 'formidable' ),
2848 + 'conditional_text' => __( 'Conditional content here', 'formidable' ),
2849 + 'new_option' => __( 'New Option', 'formidable' ),
2850 + 'css_invalid_size' => __( 'In certain browsers (e.g. Firefox) text will not display correctly if the field height is too small relative to the field padding and text size. Please increase your field height or decrease your field padding.', 'formidable' ),
2851 + 'enter_password' => __( 'Enter Password', 'formidable' ),
2852 + 'confirm_password' => __( 'Confirm Password', 'formidable' ),
2853 + 'import_complete' => __( 'Import Complete', 'formidable' ),
2854 + 'updating' => __( 'Please wait while your site updates.', 'formidable' ),
2855 + 'no_save_warning' => __( 'Warning: There is no way to retrieve unsaved entries.', 'formidable' ),
2856 + 'private_label' => __( 'Private', 'formidable' ),
2857 + 'jquery_ui_url' => '',
2858 + 'pro_url' => is_callable( 'FrmProAppHelper::plugin_url' ) ? FrmProAppHelper::plugin_url() : '',
2859 + 'no_licenses' => __( 'No new licenses were found', 'formidable' ),
2860 + 'unmatched_parens' => __( 'This calculation has at least one unmatched ( ) { } [ ].', 'formidable' ),
2861 + 'view_shortcodes' => __( 'This calculation may have shortcodes that work in Views but not forms.', 'formidable' ),
2862 + 'text_shortcodes' => __( 'This calculation may have shortcodes that work in text calculations but not numeric calculations.', 'formidable' ),
2863 + 'only_one_action' => __( 'This form action is limited to one per form. Please edit the existing form action.', 'formidable' ),
2864 + 'unsafe_params' => FrmFormsHelper::reserved_words(),
3988 2865 /* Translators: %s is the name of a Detail Page Slug that is a reserved word.*/
3989 - 'slug_is_reserved' => sprintf( __( 'The Detail Page Slug "%s" is reserved by WordPress. This may cause problems. Is this intentional?', 'formidable' ), '****' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
2866 + 'slug_is_reserved' => sprintf( __( 'The Detail Page Slug "%s" is reserved by WordPress. This may cause problems. Is this intentional?', 'formidable' ), '****' ),
3990 2867 /* Translators: %s is the name of a parameter that is a reserved word. More than one word could be listed here, though that would not be common. */
3991 - 'param_is_reserved' => sprintf( __( 'The parameter "%s" is reserved by WordPress. This may cause problems when included in the URL. Is this intentional? ', 'formidable' ), '****' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
3992 - 'reserved_words' => __( 'See the list of reserved words in WordPress.', 'formidable' ),
3993 - 'repeat_limit_min' => __( 'Please enter a Repeat Limit that is greater than 1.', 'formidable' ),
3994 - 'checkbox_limit' => __( 'Please select a limit between 0 and 200.', 'formidable' ),
3995 - 'install' => __( 'Install', 'formidable' ),
3996 - 'active' => __( 'Active', 'formidable' ),
3997 - 'installed' => __( 'Installed', 'formidable' ),
3998 - 'not_installed' => __( 'Not Installed', 'formidable' ),
3999 - 'select_a_field' => __( 'Select a Field', 'formidable' ),
4000 - 'no_items_found' => __( 'No items found.', 'formidable' ),
4001 - 'field_already_used' => __( 'Oops. You have already used that field.', 'formidable' ),
4002 -
4003 - // Deprecated in 6.0.
4004 - 'saving' => '',
4005 -
4006 - // Deprecated in 6.0.
4007 - 'saved' => '',
4008 -
4009 - // translators: %1$s: HTML open tag, %2$s: HTML end tag.
4010 - 'holdShiftMsg' => esc_html__( 'You can hold %1$sShift%2$s on your keyboard to select multiple fields', 'formidable' ),
4011 - 'noTitleText' => FrmFormsHelper::get_no_title_text(),
4012 -
4013 - // In older versions this event listener causes the section to immediately close again
4014 - // When the h3 element is clicked. It's only required in WP 6.7+.
4015 - 'requireAccordionTitleClickListener' => version_compare( $wp_version, '6.7', '>=' ),
2868 + 'param_is_reserved' => sprintf( __( 'The parameter "%s" is reserved by WordPress. This may cause problems when included in the URL. Is this intentional? ', 'formidable' ), '****' ),
2869 + 'reserved_words' => __( 'See the list of reserved words in WordPress.', 'formidable' ),
2870 + 'repeat_limit_min' => __( 'Please enter a Repeat Limit that is greater than 1.', 'formidable' ),
2871 + 'checkbox_limit' => __( 'Please select a limit between 0 and 200.', 'formidable' ),
2872 + 'install' => __( 'Install', 'formidable' ),
2873 + 'active' => __( 'Active', 'formidable' ),
2874 + 'select_a_field' => __( 'Select a Field', 'formidable' ),
2875 + 'no_items_found' => __( 'No items found.', 'formidable' ),
2876 + 'field_already_used' => __( 'Oops. You have already used that field.', 'formidable' ),
4016 2877 );
4017 -
4018 - self::add_form_builder_modal_data( $admin_script_strings );
4019 -
4020 - /**
4021 - * @param array $admin_script_strings
4022 - */
4023 2878 $admin_script_strings = apply_filters( 'frm_admin_script_strings', $admin_script_strings );
4024 2879
4025 2880 $data = $wp_scripts->get_data( 'formidable_admin', 'data' );
4026 -
4027 - if ( ! $data ) {
2881 + if ( empty( $data ) ) {
4028 2882 wp_localize_script( 'formidable_admin', 'frm_admin_js', $admin_script_strings );
4029 2883 }
4030 - }//end if
4031 - }
4032 -
4033 - /**
4034 - * @param array $admin_script_strings
4035 - *
4036 - * @return void
4037 - */
4038 - private static function add_form_builder_modal_data( &$admin_script_strings ) {
4039 - if ( ! self::is_form_builder_page() || self::pro_is_installed() ) {
4040 - return;
4041 2884 }
4042 -
4043 - $stripe_connected = FrmStrpLiteConnectHelper::at_least_one_mode_is_setup();
4044 - $square_connected = FrmSquareLiteConnectHelper::at_least_one_mode_is_setup();
4045 - $paypal_connected = FrmPayPalLiteConnectHelper::at_least_one_mode_is_setup();
4046 - $gateway_connected = $stripe_connected || $square_connected || $paypal_connected;
4047 - $payments_settings_url = FrmStrpLiteAppController::get_payments_settings_url();
4048 -
4049 - if ( ! $gateway_connected ) {
4050 - // This modal shows when user clicks on one of the pricing fields and no payment gateways configured.
4051 - $admin_script_strings['paymentsSettingsModal'] = array(
4052 - 'title' => __( 'Setup a Payment Gateway first', 'formidable' ),
4053 - 'msg' => __( 'To use the payment fields, please install and configure a payment gateway in your account settings.', 'formidable' ),
4054 - 'closeText' => __( 'Close', 'formidable' ),
4055 - 'actionUrl' => $payments_settings_url,
4056 - 'actionText' => __( 'Go to Payment Settings', 'formidable' ),
4057 - 'noCenter' => true,
4058 - );
4059 - }
4060 -
4061 - // This modal shows on load once after upgrading the plugin.
4062 - $show_pricing_fields_modal = get_option( 'frm_show_pricing_fields_modal' );
4063 -
4064 - if ( ! $show_pricing_fields_modal ) {
4065 - return;
4066 - }
4067 -
4068 - $admin_script_strings['pricingFieldsModal'] = array(
4069 - 'title' => esc_html__( 'Start Accepting Payments Today!', 'formidable' ),
4070 - 'img' => esc_url( self::plugin_url() . '/images/upsell/pricing-fields.png' ),
4071 - 'noCenter' => true,
4072 - );
4073 -
4074 - if ( $gateway_connected ) {
4075 - $gateway_texts = array();
4076 -
4077 - if ( $stripe_connected ) {
4078 - $gateway_texts['stripe'] = esc_html__( 'Stripe', 'formidable' );
4079 - }
4080 -
4081 - if ( $square_connected ) {
4082 - $gateway_texts['square'] = esc_html__( 'Square', 'formidable' );
4083 - }
4084 -
4085 - if ( $paypal_connected ) {
4086 - $gateway_texts['paypal'] = esc_html__( 'PayPal', 'formidable' );
4087 - }
4088 -
4089 - $admin_script_strings['pricingFieldsModal']['msg'] = sprintf(
4090 - // translators: %s: Stripe, Square, or PayPal.
4091 - esc_html__( 'You already have %s connected, so these have already been unlocked.', 'formidable' ),
4092 - esc_html( implode( ' ' . esc_html__( 'and', 'formidable' ) . ' ', $gateway_texts ) )
4093 - );
4094 - } else {
4095 - $admin_script_strings['pricingFieldsModal']['closeText'] = __( 'I\'ll do it later!', 'formidable' );
4096 - $admin_script_strings['pricingFieldsModal']['actionText'] = __( 'Setup Payments Now', 'formidable' );
4097 - $admin_script_strings['pricingFieldsModal']['actionUrl'] = $payments_settings_url;
4098 - // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
4099 - $admin_script_strings['pricingFieldsModal']['msg'] = __( 'We\'ve unlocked Product, Quantity, and Total fields for Lite users! You can now transform your forms into checkout pages. To start collecting revenue, simply connect your preferred payment gateway (Stripe, Square, or PayPal) in your settings.', 'formidable' );
4100 - }//end if
4101 -
4102 - delete_option( 'frm_show_pricing_fields_modal' );
4103 2885 }
4104 2886
4105 2887 /**
4106 - * Get the no label text.
4107 - *
4108 - * @since 6.25.1
4109 - *
4110 - * @return string
4111 - */
4112 - public static function get_no_label_text() {
4113 - return __( '(no label)', 'formidable' );
4114 - }
4115 -
4116 - /**
4117 - * @since 6.5
4118 - *
4119 - * @return string
4120 - */
4121 - public static function get_ajax_url() {
4122 - $ajax_url = admin_url( 'admin-ajax.php', is_ssl() ? 'admin' : 'http' );
4123 -
4124 - /**
4125 - * @since 2.0.13
4126 - *
4127 - * @param string $ajax_url
4128 - */
4129 - return apply_filters( 'frm_ajax_url', $ajax_url );
4130 - }
4131 -
4132 - /**
4133 2888 * Returns whether or not the first errored input should be auto-focused (default true).
4134 2889 *
4135 2890 * @since 5.2.05
4136 2891 *
@@ -4155,11 +2910,9 @@
4155 2910 * Echo the message on the plugins listing page
4156 2911 *
4157 2912 * @since 1.07.10
4158 2913 *
4159 - * @param float $min_version The version the add-on requires.
4160 - *
4161 - * @return void
2914 + * @param float $min_version The version the add-on requires
4162 2915 */
4163 2916 public static function min_version_notice( $min_version ) {
4164 2917 $frm_version = self::plugin_version();
4165 2918
@@ -4168,11 +2921,11 @@
4168 2921 return;
4169 2922 }
4170 2923
4171 2924 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
4172 - echo '<tr class="plugin-update-tr active"><th colspan="' . absint( $wp_list_table->get_column_count() ) . '" class="check-column plugin-update colspanchange"><div class="update-message">' . // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
4173 - esc_html__( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
4174 - '</div></td></tr>';
2925 + echo '<tr class="plugin-update-tr active"><th colspan="' . absint( $wp_list_table->get_column_count() ) . '" class="check-column plugin-update colspanchange"><div class="update-message">' .
2926 + esc_html__( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
2927 + '</div></td></tr>';
4175 2928 }
4176 2929
4177 2930 /**
4178 2931 * If Pro is far outdated, show a message.
@@ -4178,10 +2931,8 @@
4178 2931 * If Pro is far outdated, show a message.
4179 2932 *
4180 2933 * @since 4.0.01
4181 2934 *
4182 - * @param string $min_version
4183 - *
4184 2935 * @return void
4185 2936 */
4186 2937 public static function min_pro_version_notice( $min_version ) {
4187 2938 if ( ! self::is_formidable_admin() ) {
@@ -4191,14 +2942,26 @@
4191 2942
4192 2943 self::php_version_notice();
4193 2944
4194 2945 $is_pro = self::pro_is_installed() && class_exists( 'FrmProDb' );
4195 -
4196 2946 if ( ! $is_pro || self::meets_min_pro_version( $min_version ) ) {
4197 2947 return;
4198 2948 }
4199 2949
4200 - include self::plugin_path() . '/classes/views/addons/min-version-notice.php';
2950 + $pro_version = FrmProDb::$plug_version;
2951 + $expired = FrmAddonsController::is_license_expired();
2952 + ?>
2953 + <div class="error frm_previous_install">
2954 + <?php
2955 + esc_html_e( 'You are running a version of Formidable Forms that may not be compatible with your version of Formidable Forms Pro.', 'formidable' );
2956 + if ( empty( $expired ) ) {
2957 + echo ' Please <a href="' . esc_url( admin_url( 'plugins.php?s=formidable%20forms%20pro' ) ) . '">update now</a>.';
2958 + } else {
2959 + echo '<br/>Please <a href="https://formidableforms.com/account/downloads/?utm_source=WordPress&utm_medium=outdated">renew now</a> to get the latest version.';
2960 + }
2961 + ?>
2962 + </div>
2963 + <?php
4201 2964 }
4202 2965
4203 2966 /**
4204 2967 * If Pro is installed, check the version number.
@@ -4203,12 +2966,8 @@
4203 2966 /**
4204 2967 * If Pro is installed, check the version number.
4205 2968 *
4206 2969 * @since 4.0.01
4207 - *
4208 - * @param string $min_version
4209 - *
4210 - * @return bool
4211 2970 */
4212 2971 public static function meets_min_pro_version( $min_version ) {
4213 2972 return ! class_exists( 'FrmProDb' ) || version_compare( FrmProDb::$plug_version, $min_version, '>=' );
4214 2973 }
@@ -4213,35 +2972,35 @@
4213 2972 return ! class_exists( 'FrmProDb' ) || version_compare( FrmProDb::$plug_version, $min_version, '>=' );
4214 2973 }
4215 2974
4216 2975 /**
4217 - * Show a message if the PHP version is below the recommendations.
2976 + * Show a message if the browser or PHP version is below the recommendations.
4218 2977 *
4219 2978 * @since 4.0.02
4220 - *
4221 - * @return void
4222 2979 */
4223 2980 private static function php_version_notice() {
4224 2981 $message = array();
2982 + if ( version_compare( phpversion(), '5.6', '<' ) ) {
2983 + $message[] = __( 'The version of PHP on your server is too low. If this is not corrected, you may see issues with Formidable Forms. Please contact your web host and ask to be updated to PHP 7.0+.', 'formidable' );
2984 + }
4225 2985
4226 - if ( version_compare( phpversion(), '7.0', '<' ) ) {
4227 - $message[] = __( 'The version of PHP on your server is too low. If this is not corrected, you may see issues with Formidable Forms. Please contact your web host and ask to be updated to PHP 7.0+.', 'formidable' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
2986 + $browser = self::get_server_value( 'HTTP_USER_AGENT' );
2987 + $is_ie = strpos( $browser, 'MSIE' ) !== false;
2988 + if ( $is_ie ) {
2989 + $message[] = __( 'You are using an outdated browser that is not compatible with Formidable Forms. Please update to a more current browser (we recommend Chrome).', 'formidable' );
4228 2990 }
4229 2991
4230 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
4231 2992 foreach ( $message as $m ) {
4232 2993 ?>
4233 - <div class="frm-banner-alert frm_error_style frm_previous_install">
2994 + <div class="error frm_previous_install">
4234 2995 <?php echo esc_html( $m ); ?>
4235 2996 </div>
4236 2997 <?php
4237 2998 }
4238 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
4239 2999 }
4240 3000
4241 3001 /**
4242 3002 * @param string $type
4243 - *
4244 3003 * @return array<string,string>
4245 3004 */
4246 3005 public static function locales( $type = 'date' ) {
4247 3006 $locales = array(
@@ -4335,12 +3094,12 @@
4335 3094 'zu' => __( 'Zulu', 'formidable' ),
4336 3095 );
4337 3096
4338 3097 if ( $type === 'captcha' ) {
4339 - // Remove the languages unavailable for the captcha
3098 + // remove the languages unavailable for the captcha
4340 3099 $unset = array( 'sq', 'bs', 'eo', 'fo', 'fr-CH', 'sr-SR', 'ar-DZ', 'be', 'cy-GB', 'kk', 'km', 'ky', 'lb', 'mk', 'nb', 'nn', 'rm', 'tj' );
4341 3100 } else {
4342 - // Remove the languages unavailable for the datepicker
3101 + // remove the languages unavailable for the datepicker
4343 3102 $unset = array( 'fil', 'fr-CA', 'de-AT', 'de-CH', 'iw', 'hi', 'pt', 'pt-PT', 'es-419', 'mr', 'lo', 'kn', 'si', 'gu', 'bn', 'zu', 'ur', 'te', 'sw', 'am' );
4344 3103 }
4345 3104
4346 3105 $locales = array_diff_key( $locales, array_flip( $unset ) );
@@ -4351,27 +3110,32 @@
4351 3110 * @since 5.4.5 Added $args parameter with type.
4352 3111 *
4353 3112 * @param array<string,string> $locales
4354 3113 * @param array $args {
4355 - *
4356 3114 * @type string $type
4357 3115 * }
4358 3116 */
4359 - return apply_filters( 'frm_locales', $locales, compact( 'type' ) );
3117 + $locales = apply_filters( 'frm_locales', $locales, compact( 'type' ) );
3118 +
3119 + return $locales;
4360 3120 }
4361 3121
4362 3122 /**
4363 - * @return string
3123 + * Output HTML containing reference text for accessibility
3124 + *
3125 + * @deprecated 5.1
4364 3126 */
3127 + public static function multiselect_accessibility() {
3128 + _deprecated_function( __METHOD__, '5.1' );
3129 + }
3130 +
4365 3131 public static function get_menu_icon_class() {
4366 3132 if ( is_callable( 'FrmProAppHelper::get_settings' ) ) {
4367 3133 $settings = FrmProAppHelper::get_settings();
4368 -
4369 3134 if ( is_object( $settings ) && ! empty( $settings->menu_icon ) ) {
4370 3135 return $settings->menu_icon;
4371 3136 }
4372 3137 }
4373 -
4374 3138 return 'frmfont frm_logo_icon';
4375 3139 }
4376 3140
4377 3141 /**
@@ -4389,9 +3153,10 @@
4389 3153 * @type array $input_attrs Attributes of value input.
4390 3154 * }
4391 3155 */
4392 3156 public static function images_dropdown( $args ) {
4393 - $args = self::fill_default_images_dropdown_args( $args );
3157 + $args = self::fill_default_images_dropdown_args( $args );
3158 +
4394 3159 $input_attrs_str = self::get_images_dropdown_input_attrs( $args );
4395 3160 ob_start();
4396 3161 include self::plugin_path() . '/classes/views/shared/images-dropdown.php';
4397 3162 $output = ob_get_clean();
@@ -4412,9 +3177,8 @@
4412 3177 *
4413 3178 * @since 5.0.04
4414 3179 *
4415 3180 * @param array $args The arguments.
4416 - *
4417 3181 * @return array
4418 3182 */
4419 3183 private static function fill_default_images_dropdown_args( $args ) {
4420 3184 $defaults = array(
@@ -4427,8 +3191,14 @@
4427 3191
4428 3192 $new_args['options'] = (array) $new_args['options'];
4429 3193 $new_args['input_attrs'] = (array) $new_args['input_attrs'];
4430 3194
3195 + // Set the number of columns.
3196 + $new_args['col_class'] = ceil( 12 / count( $new_args['options'] ) );
3197 + if ( $new_args['col_class'] > 6 ) {
3198 + $new_args['col_class'] = ceil( $new_args['col_class'] / 2 );
3199 + }
3200 +
4431 3201 /**
4432 3202 * Allows modifying the arguments of images_dropdown() method.
4433 3203 *
4434 3204 * @since 5.0.04
@@ -4444,9 +3214,8 @@
4444 3214 *
4445 3215 * @since 5.0.04
4446 3216 *
4447 3217 * @param array $args The arguments.
4448 - *
4449 3218 * @return string
4450 3219 */
4451 3220 private static function get_images_dropdown_input_attrs( $args ) {
4452 3221 $input_attrs = $args['input_attrs'];
@@ -4453,9 +3222,8 @@
4453 3222 $input_attrs['type'] = 'radio';
4454 3223 $input_attrs['name'] = $args['name'];
4455 3224
4456 3225 $input_attrs_str = '';
4457 -
4458 3226 foreach ( $input_attrs as $key => $input_attr ) {
4459 3227 $input_attrs_str .= ' ' . sprintf( '%s="%s"', esc_attr( $key ), esc_attr( $input_attr ) );
4460 3228 }
4461 3229
@@ -4470,23 +3238,8 @@
4470 3238 return apply_filters( 'frm_images_dropdown_input_attrs', $input_attrs_str, $args );
4471 3239 }
4472 3240
4473 3241 /**
4474 - * @since 6.7.1
4475 - *
4476 - * @param array $option Option data.
4477 - * @param array $args The arguments of images_dropdown() method.
4478 - *
4479 - * @return array
4480 - */
4481 - public static function get_images_dropdown_atts( $option, $args ) {
4482 - $image = self::get_images_dropdown_option_image( $option, $args );
4483 - $classes = self::get_images_dropdown_option_classes( $option, $args );
4484 - $custom_attrs = self::get_images_dropdown_option_html_attrs( $option, $args );
4485 - return compact( 'image', 'classes', 'custom_attrs' );
4486 - }
4487 -
4488 - /**
4489 3242 * Gets the image of each option in images_dropdown() method.
4490 3243 *
4491 3244 * @since 5.0.04
4492 3245 *
@@ -4491,9 +3244,8 @@
4491 3244 * @since 5.0.04
4492 3245 *
4493 3246 * @param array $option Option data.
4494 3247 * @param array $args The arguments of images_dropdown() method.
4495 - *
4496 3248 * @return string
4497 3249 */
4498 3250 private static function get_images_dropdown_option_image( $option, $args ) {
4499 3251 $image = self::icon_by_class(
@@ -4498,9 +3250,9 @@
4498 3250 private static function get_images_dropdown_option_image( $option, $args ) {
4499 3251 $image = self::icon_by_class(
4500 3252 'frmfont ' . $option['svg'],
4501 3253 array(
4502 - 'echo' => false,
3254 + 'echo' => false,
4503 3255 )
4504 3256 );
4505 3257
4506 3258 $args['option'] = $option;
@@ -4522,9 +3274,8 @@
4522 3274 * @since 5.0.04
4523 3275 *
4524 3276 * @param array $option Option data.
4525 3277 * @param array $args The arguments of images_dropdown() method.
4526 - *
4527 3278 * @return string
4528 3279 */
4529 3280 private static function get_images_dropdown_option_classes( $option, $args ) {
4530 3281 $classes = '';
@@ -4552,19 +3303,17 @@
4552 3303 * @since 5.0.04
4553 3304 *
4554 3305 * @param array $option Option data.
4555 3306 * @param array $args The arguments of images_dropdown() method.
4556 - *
4557 3307 * @return string
4558 3308 */
4559 3309 private static function get_images_dropdown_option_html_attrs( $option, $args ) {
4560 3310 $html_attrs = '';
4561 -
4562 3311 if ( ! empty( $option['custom_attrs'] ) && is_array( $option['custom_attrs'] ) ) {
4563 3312 $html_attrs_arr = array();
4564 3313
4565 3314 foreach ( $option['custom_attrs'] as $key => $value ) {
4566 - if ( in_array( $key, array( 'type', 'class', 'data-value' ), true ) ) {
3315 + if ( in_array( $key, array( 'type', 'class', 'data-value' ) ) ) {
4567 3316 continue;
4568 3317 }
4569 3318
4570 3319 $html_attrs_arr[] = sprintf( '%s="%s"', esc_attr( $key ), esc_attr( $value ) );
@@ -4622,13 +3371,14 @@
4622 3371 * @since 5.0.07
4623 3372 *
4624 3373 * @param array $values
4625 3374 * @param array $keys
4626 - *
4627 3375 * @return array
4628 3376 */
4629 3377 public static function maybe_filter_array( $values, $keys ) {
4630 - if ( self::allow_unfiltered_html() ) {
3378 + $allow_unfiltered_html = self::allow_unfiltered_html();
3379 +
3380 + if ( $allow_unfiltered_html ) {
4631 3381 return $values;
4632 3382 }
4633 3383
4634 3384 foreach ( $keys as $key ) {
@@ -4640,87 +3390,36 @@
4640 3390 return $values;
4641 3391 }
4642 3392
4643 3393 /**
4644 - * Some back end fields allow privileged users to add scripts.
3394 + * Some back end fields allow privleged users to add scripts.
4645 3395 * A site that uses the DISALLOW_UNFILTERED_HTML always remove scripts on echo.
4646 3396 *
4647 3397 * @since 5.0.13
4648 3398 *
4649 3399 * @param string $value
4650 - * @param array|string $allowed 'all' for everything included as defaults.
4651 - *
3400 + * @param array|string $allowed 'all' for everything included as defaults
4652 3401 * @return string
4653 3402 */
4654 3403 public static function maybe_kses( $value, $allowed = 'all' ) {
4655 3404 if ( self::should_never_allow_unfiltered_html() ) {
4656 - return self::kses( $value, $allowed );
3405 + $value = self::kses( $value, $allowed );
4657 3406 }
4658 3407 return $value;
4659 3408 }
4660 3409
4661 3410 /**
4662 - * Check if an option attribute used in an [input] shortcode is safe.
3411 + * @since 5.0.16
4663 3412 *
4664 - * @since 6.11.2
4665 - *
4666 - * @param string $key
4667 - * @param string $context Either 'display' or 'update'. On update, we want to allow a few keys that are never displayed.
4668 - *
4669 3413 * @return bool
4670 3414 */
4671 - public static function input_key_is_safe( $key, $context = 'display' ) {
4672 - if ( 'update' === $context && in_array( $key, array( 'opt', 'label' ), true ) ) {
4673 - $safe = true;
4674 - } elseif ( str_starts_with( $key, 'data-' ) ) {
4675 - // Allow all data attributes.
4676 - $safe = true;
4677 - } elseif ( str_starts_with( $key, 'aria-' ) ) {
4678 - // Allow all aria attributes.
4679 - $safe = true;
4680 - } else {
4681 - $safe_keys = array(
4682 - 'class',
4683 - 'required',
4684 - 'title',
4685 - 'placeholder',
4686 - 'value',
4687 - 'readonly',
4688 - 'disabled',
4689 - 'size',
4690 - 'maxlength',
4691 - 'min',
4692 - 'max',
4693 - 'pattern',
4694 - 'step',
4695 - 'autofocus',
4696 - 'width',
4697 - 'height',
4698 - 'autocomplete',
4699 - 'tabindex',
4700 - 'role',
4701 - 'style',
4702 - );
4703 - $safe = in_array( $key, $safe_keys, true );
4704 - }//end if
4705 -
4706 - /**
4707 - * Filter the $safe value so additional keys can be allowed or disallowed.
4708 - *
4709 - * @since 6.11.2
4710 - *
4711 - * @param bool $safe True if the key is considered safe.
4712 - * @param string $key
4713 - * @param string $context Either 'display' or 'update'.
4714 - */
4715 - return (bool) apply_filters( 'frm_input_key_is_safe', $safe, $key, $context );
3415 + public static function show_landing_pages() {
3416 + return self::show_new_feature( 'landing' );
4716 3417 }
4717 3418
4718 3419 /**
4719 3420 * @since 5.0.16
4720 3421 *
4721 - * @param string $medium
4722 - *
4723 3422 * @return array
4724 3423 */
4725 3424 public static function get_landing_page_upgrade_data_params( $medium = 'landing' ) {
4726 3425 $params = array(
@@ -4727,9 +3426,8 @@
4727 3426 'medium' => $medium,
4728 3427 'upgrade' => __( 'Form Landing Pages', 'formidable' ),
4729 3428 'message' => __( 'Easily manage a landing page for your form. Upgrade to get form landing pages.', 'formidable' ),
4730 3429 'screenshot' => 'landing.png',
4731 - 'learn-more' => self::get_doc_url( 'landing-page-forms', 'form-landing-page-settings', false ),
4732 3430 );
4733 3431 return self::get_upgrade_data_params( 'landing', $params );
4734 3432 }
4735 3433
@@ -4735,10 +3433,20 @@
4735 3433
4736 3434 /**
4737 3435 * @since 5.0.17
4738 3436 *
4739 - * @param string $feature
3437 + * @param string $plugin
3438 + * @return string|false
3439 + */
3440 + private static function get_plan_required( $plugin ) {
3441 + $link = FrmAddonsController::install_link( $plugin );
3442 + return FrmFormsHelper::get_plan_required( $link );
3443 + }
3444 +
3445 + /**
3446 + * @since 5.0.17
4740 3447 *
3448 + * @param string
4741 3449 * @return bool
4742 3450 */
4743 3451 public static function show_new_feature( $feature ) {
4744 3452 $link = FrmAddonsController::install_link( $feature );
@@ -4745,21 +3453,16 @@
4745 3453 return array_key_exists( 'status', $link ) || array_key_exists( 'class', $link );
4746 3454 }
4747 3455
4748 3456 /**
4749 - * Enhances upgrade data parameters with installation link and plan requirement information.
4750 - *
4751 3457 * @since 5.0.17
4752 3458 *
4753 - * @param string $plugin The plugin slug to get installation data for.
4754 - * @param array $params Initial parameters for the upgrade data.
4755 - * @param bool $detailed Whether to include detailed information.
4756 - *
4757 - * @return array Modified parameters with installation data.
3459 + * @param string $plugin
3460 + * @param array $params
3461 + * @return array
4758 3462 */
4759 - public static function get_upgrade_data_params( $plugin, $params, $detailed = false ) {
3463 + public static function get_upgrade_data_params( $plugin, $params ) {
4760 3464 $link = FrmAddonsController::install_link( $plugin );
4761 -
4762 3465 if ( ! $link ) {
4763 3466 return $params;
4764 3467 }
4765 3468
@@ -4765,20 +3468,15 @@
4765 3468
4766 3469 if ( ! empty( $link['url'] ) && self::pro_is_installed() ) {
4767 3470 $params['oneclick'] = json_encode( $link );
4768 3471 unset( $params['message'] );
4769 -
4770 3472 if ( ! isset( $params['medium'] ) ) {
4771 3473 $params['medium'] = $plugin;
4772 3474 }
4773 3475 } else {
4774 - $params['requires'] = $params['requires'] ?? FrmFormsHelper::get_plan_required( $link );
3476 + $params['requires'] = FrmFormsHelper::get_plan_required( $link );
4775 3477 }
4776 3478
4777 - if ( $detailed ) {
4778 - $params['plugin-status'] = $link['status'] ?? '';
4779 - }
4780 -
4781 3479 return $params;
4782 3480 }
4783 3481
4784 3482 /**
@@ -4787,9 +3485,8 @@
4787 3485 *
4788 3486 * @since 5.0.17
4789 3487 *
4790 3488 * @param string $text
4791 - *
4792 3489 * @return bool
4793 3490 */
4794 3491 public static function ctype_xdigit( $text ) {
4795 3492 if ( function_exists( 'ctype_xdigit' ) ) {
@@ -4804,14 +3501,12 @@
4804 3501 * @since 5.2.01
4805 3502 */
4806 3503 public static function set_current_screen_and_hook_suffix() {
4807 3504 global $hook_suffix;
4808 -
4809 3505 if ( is_null( $hook_suffix ) ) {
4810 3506 // $hook_suffix gets used in substr so make sure it's not null. PHP 8.1 deprecates null in substr.
4811 3507 $hook_suffix = ''; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
4812 3508 }
4813 -
4814 3509 set_current_screen();
4815 3510 }
4816 3511
4817 3512 /**
@@ -4818,15 +3513,15 @@
4818 3513 * Shows pill text.
4819 3514 *
4820 3515 * @since 5.2.02
4821 3516 *
4822 - * @param string|null $text Text in the pill. Default is NEW.
3517 + * @param string $text Text in the pill. Default is NEW.
4823 3518 */
4824 3519 public static function show_pill_text( $text = null ) {
4825 3520 if ( null === $text ) {
4826 3521 $text = __( 'NEW', 'formidable' );
4827 3522 }
4828 - echo '<span class="frm-meta-tag frm-new-pill">' . esc_html( $text ) . '</span>';
3523 + echo '<span class="frm-new-pill">' . esc_html( $text ) . '</span>';
4829 3524 }
4830 3525
4831 3526 /**
4832 3527 * Count the number of decimals digits.
@@ -4833,10 +3528,9 @@
4833 3528 *
4834 3529 * @since 5.2.07
4835 3530 *
4836 3531 * @param mixed $num Number.
4837 - *
4838 - * @return false|int Returns `false` if the passed parameter is not number.
3532 + * @return int|false Returns `false` if the passed parameter is not number.
4839 3533 */
4840 3534 public static function count_decimals( $num ) {
4841 3535 if ( ! is_numeric( $num ) ) {
4842 3536 return false;
@@ -4843,9 +3537,8 @@
4843 3537 }
4844 3538
4845 3539 $num = (string) $num;
4846 3540 $parts = explode( '.', $num );
4847 -
4848 3541 if ( 1 === count( $parts ) ) {
4849 3542 return 0;
4850 3543 }
4851 3544
@@ -4868,9 +3561,9 @@
4868 3561 }
4869 3562
4870 3563 add_filter(
4871 3564 'option_gmt_offset',
4872 - function ( $offset ) {
3565 + function( $offset ) {
4873 3566 if ( ! is_string( $offset ) || is_numeric( $offset ) ) {
4874 3567 // Leave a valid value alone.
4875 3568 return $offset;
4876 3569 }
@@ -4920,272 +3613,221 @@
4920 3613 return get_plugins();
4921 3614 }
4922 3615
4923 3616 /**
4924 - * Make sure that the file we're trying to load is in fact the expected file type, and that it's coming from our S3 bucket.
4925 - * This is to make sure that the URL can't be exploited for a SSRF attack.
4926 - *
4927 - * @since 5.5.5
4928 - *
4929 - * @param string $url
4930 - * @param string $expected_extension
4931 - *
4932 - * @return bool
3617 + * @since 4.08
3618 + * @deprecated 4.09.01
4933 3619 */
4934 - public static function validate_url_is_in_s3_bucket( $url, $expected_extension ) {
4935 - $file_is_in_expected_s3_bucket = str_starts_with( $url, 'https://s3.amazonaws.com/fp.strategy11.com' );
4936 -
4937 - if ( ! $file_is_in_expected_s3_bucket ) {
4938 - return false;
3620 + public static function expiring_message() {
3621 + _deprecated_function( __METHOD__, '4.09.01', 'FrmProAddonsController::expiring_message' );
3622 + if ( is_callable( 'FrmProAddonsController::expiring_message' ) ) {
3623 + FrmProAddonsController::expiring_message();
4939 3624 }
4940 -
4941 - $parsed = parse_url( $url );
4942 -
4943 - if ( ! is_array( $parsed ) ) {
4944 - // URL is malformed.
4945 - return false;
4946 - }
4947 -
4948 - $path = $parsed['path'];
4949 - $ext = pathinfo( $path, PATHINFO_EXTENSION );
4950 - // The URL isn't to an XML file.
4951 - return $expected_extension === $ext;
4952 3625 }
4953 3626
4954 3627 /**
4955 - * Display a dismissable warning message and save its dismissal state.
3628 + * Use the WP 4.7 wp_doing_ajax function
4956 3629 *
4957 - * @since 6.3
4958 - *
4959 - * @param string $message The warning message to display.
4960 - * @param string $option The unique identifier for the dismissal state of the message and the WP Ajax action.
4961 - *
4962 - * @return void
3630 + * @since 2.05.07
3631 + * @deprecated 4.04.04
4963 3632 */
4964 - public static function add_dismissable_warning_message( $message = '', $option = '' ) {
4965 - if ( ! $message || ! $option ) {
4966 - return;
4967 - }
3633 + public static function wp_doing_ajax() {
3634 + _deprecated_function( __METHOD__, '4.04.04', 'wp_doing_ajax' );
3635 + return wp_doing_ajax();
3636 + }
4968 3637
4969 - $ajax_callback = function () use ( $option ) {
4970 - self::dismiss_warning_message( $option );
4971 - };
4972 -
4973 - // We're handling JS codes with `doJsonPost` and it adds 'frm_' to the beginning of the action.
4974 - // To prevent any issues, we add 'frm_' from the beginning of the action.
4975 - add_action( 'wp_ajax_frm_' . $option, $ajax_callback );
4976 -
4977 - add_filter(
4978 - 'frm_message_list',
4979 - function ( $show_messages ) use ( $message, $option ) {
4980 - if ( get_option( $option, false ) ) {
4981 - return $show_messages;
4982 - }
4983 -
4984 - $dismiss_icon = self::icon_by_class(
4985 - 'frmfont frm_close_icon',
4986 - array(
4987 - 'aria-label' => _x( 'Dismiss', 'warning message: close icon label', 'formidable' ),
4988 - 'echo' => false,
4989 - )
4990 - );
4991 -
4992 - $show_messages[] = $message;
4993 - $show_messages[] = '<span class="frm-warning-dismiss frmsvg" data-action="' . esc_attr( $option ) . '">' . $dismiss_icon . '</span>';
4994 -
4995 - return $show_messages;
4996 - }
4997 - );
3638 + /**
3639 + * @deprecated 4.0
3640 + */
3641 + public static function insert_opt_html( $args ) {
3642 + _deprecated_function( __METHOD__, '4.0', 'FrmFormsHelper::insert_opt_html' );
3643 + FrmFormsHelper::insert_opt_html( $args );
4998 3644 }
4999 3645
5000 3646 /**
5001 - * Dismiss a warning message and update the dismissal state.
3647 + * Used to filter shortcode in text widgets
5002 3648 *
5003 - * @since 6.3
5004 - *
5005 - * @param string $option The unique identifier for the dismissal state of the message.
5006 - *
5007 - * @return void
3649 + * @deprecated 2.5.4
3650 + * @codeCoverageIgnore
5008 3651 */
5009 - public static function dismiss_warning_message( $option = '' ) {
5010 - self::permission_check( 'frm_change_settings' );
5011 - check_ajax_referer( 'frm_ajax', 'nonce' );
3652 + public static function widget_text_filter_callback( $matches ) {
3653 + return FrmDeprecated::widget_text_filter_callback( $matches );
3654 + }
5012 3655
5013 - if ( $option ) {
5014 - update_option( $option, true, false );
5015 - }
5016 -
5017 - wp_send_json_success();
3656 + /**
3657 + * @deprecated 3.01
3658 + * @codeCoverageIgnore
3659 + */
3660 + public static function sanitize_array( &$values ) {
3661 + FrmDeprecated::sanitize_array( $values );
5018 3662 }
5019 3663
5020 3664 /**
5021 - * Lite license copy.
5022 - * Used in FrmDashboardController & FrmSettingsController
3665 + * @param array $settings
3666 + * @param string $group
5023 3667 *
5024 - * @since 6.8
5025 - *
5026 - * @return string
3668 + * @since 2.0.6
3669 + * @deprecated 2.05.06
3670 + * @codeCoverageIgnore
5027 3671 */
5028 - public static function copy_for_lite_license() {
5029 - $message = __( 'You\'re using Formidable Forms Lite - no license needed. Enjoy!', 'formidable' ) . ' 🙂';
5030 - return apply_filters( 'frm_license_type_text', $message );
3672 + public static function save_settings( $settings, $group ) {
3673 + return FrmDeprecated::save_settings( $settings, $group );
5031 3674 }
5032 3675
5033 3676 /**
5034 - * Removes scripts that are unnecessarily loaded across the pages!
5035 - *
5036 - * @since 6.9
5037 - *
5038 - * @return void
3677 + * @since 2.0.4
3678 + * @deprecated 2.05.06
3679 + * @codeCoverageIgnore
5039 3680 */
5040 - public static function dequeue_extra_global_scripts() {
5041 - wp_dequeue_script( 'frm-surveys-admin' );
5042 - wp_dequeue_script( 'frm-quizzes-form-action' );
3681 + public static function save_json_post( $settings ) {
3682 + return FrmDeprecated::save_json_post( $settings );
5043 3683 }
5044 3684
5045 3685 /**
5046 - * Shows tooltip icon.
3686 + * @since 2.0
3687 + * @deprecated 2.05.06
3688 + * @codeCoverageIgnore
5047 3689 *
5048 - * @since 6.12
3690 + * @param string $cache_key The unique name for this cache
3691 + * @param string $group The name of the cache group
3692 + * @param string $query If blank, don't run a db call
3693 + * @param string $type The wpdb function to use with this query
5049 3694 *
5050 - * @param string $tooltip_text Tooltip text.
5051 - * @param array $atts Tooltip wrapper HTML attributes.
5052 - *
5053 - * @return void
3695 + * @return mixed $results The cache or query results
5054 3696 */
5055 - public static function tooltip_icon( $tooltip_text, $atts = array() ) {
5056 - $atts['title'] = $tooltip_text;
3697 + public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) {
3698 + return FrmDeprecated::check_cache( $cache_key, $group, $query, $type, $time );
3699 + }
5057 3700
5058 - if ( isset( $atts['class'] ) ) {
5059 - $atts['class'] .= ' frm_help';
5060 - } else {
5061 - $atts['class'] = 'frm_help';
5062 - }
5063 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
5064 - ?>
5065 - <span <?php self::array_to_html_params( $atts, true ); ?>>
5066 - <?php self::icon_by_class( 'frmfont frm_tooltip_icon' ); ?>
5067 - </span>
5068 - <?php
5069 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
3701 + /**
3702 + * @deprecated 2.05.06
3703 + * @codeCoverageIgnore
3704 + */
3705 + public static function set_cache( $cache_key, $results, $group = '', $time = 300 ) {
3706 + return FrmDeprecated::set_cache( $cache_key, $results, $group, $time );
5070 3707 }
5071 3708
5072 3709 /**
5073 - * Prints errors for settings in onboarding wizard or template settings.
5074 - *
5075 - * @since 6.15
5076 - *
5077 - * @param array $args Args.
5078 - *
5079 - * @return void
3710 + * @deprecated 2.05.06
3711 + * @codeCoverageIgnore
5080 3712 */
5081 - public static function print_setting_error( $args ) {
5082 - $args = wp_parse_args(
5083 - $args,
5084 - array(
5085 - 'id' => '',
5086 - 'errors' => array(),
5087 - 'class' => '',
5088 - )
5089 - );
3713 + public static function add_key_to_group_cache( $key, $group ) {
3714 + FrmDeprecated::add_key_to_group_cache( $key, $group );
3715 + }
5090 3716
5091 - $args['class'] .= ' frm-validation-error frm-mt-xs frm_hidden';
3717 + /**
3718 + * @deprecated 2.05.06
3719 + * @codeCoverageIgnore
3720 + */
3721 + public static function get_group_cached_keys( $group ) {
3722 + return FrmDeprecated::get_group_cached_keys( $group );
3723 + }
5092 3724
5093 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
5094 - ?>
5095 - <span id="<?php echo esc_attr( $args['id'] ); ?>" class="<?php echo esc_attr( $args['class'] ); ?>">
5096 - <?php
5097 - if ( is_array( $args['errors'] ) ) {
5098 - foreach ( $args['errors'] as $key => $msg ) {
5099 - ?>
5100 - <span frm-error="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $msg ); ?></span>
5101 - <?php
5102 - }
5103 - } else {
5104 - echo '<span>' . esc_html( $args['errors'] ) . '</span>';
5105 - }
5106 - ?>
5107 - </span>
5108 - <?php
5109 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
3725 + /**
3726 + * @since 2.0
3727 + * @deprecated 2.05.06
3728 + * @codeCoverageIgnore
3729 + * @return mixed The cached value or false
3730 + */
3731 + public static function check_cache_and_transient( $cache_key ) {
3732 + return FrmDeprecated::check_cache( $cache_key );
5110 3733 }
5111 3734
5112 3735 /**
5113 - * Check if GDPR is enabled.
3736 + * @since 2.0
3737 + * @deprecated 2.05.06
3738 + * @codeCoverageIgnore
5114 3739 *
5115 - * @since 6.19
3740 + * @param string $cache_key
3741 + */
3742 + public static function delete_cache_and_transient( $cache_key, $group = 'default' ) {
3743 + FrmDeprecated::delete_cache_and_transient( $cache_key, $group );
3744 + }
3745 +
3746 + /**
3747 + * @since 2.0
3748 + * @deprecated 2.05.06
3749 + * @codeCoverageIgnore
5116 3750 *
5117 - * @return bool
3751 + * @param string $group The name of the cache group
5118 3752 */
5119 - public static function is_gdpr_enabled() {
5120 - $frm_settings = self::get_settings();
5121 - return $frm_settings->enable_gdpr || $frm_settings->no_ips || $frm_settings->custom_header_ip || $frm_settings->no_gdpr_cookies;
3753 + public static function cache_delete_group( $group ) {
3754 + FrmDeprecated::cache_delete_group( $group );
5122 3755 }
5123 3756
5124 3757 /**
5125 - * Check if GDPR cookies are disabled.
3758 + * @since 1.07.10
3759 + * @deprecated 2.05.06
3760 + * @codeCoverageIgnore
5126 3761 *
5127 - * @since 6.19
3762 + * @param string $term The value to escape
5128 3763 *
5129 - * @return bool
3764 + * @return string The escaped value
5130 3765 */
5131 - public static function no_gdpr_cookies() {
5132 - $frm_settings = self::get_settings();
5133 - return $frm_settings->enable_gdpr && $frm_settings->no_gdpr_cookies;
3766 + public static function esc_like( $term ) {
3767 + return FrmDeprecated::esc_like( $term );
5134 3768 }
5135 3769
5136 3770 /**
5137 - * Check if a string is valid UTF-8.
3771 + * @param string $order_query
5138 3772 *
5139 - * @since 6.24
5140 - *
5141 - * @param string|null $string The string to check.
5142 - *
5143 - * @return bool
3773 + * @deprecated 2.05.06
3774 + * @codeCoverageIgnore
5144 3775 */
5145 - public static function is_valid_utf8( $string ) {
5146 - if ( is_null( $string ) ) {
5147 - // Return true so we do not attempt to change encoding on a null value.
5148 - return true;
5149 - }
3776 + public static function esc_order( $order_query ) {
3777 + return FrmDeprecated::esc_order( $order_query );
3778 + }
5150 3779
5151 - // wp_is_valid_utf8 is added in WP 6.9.
5152 - if ( function_exists( 'wp_is_valid_utf8' ) ) {
5153 - return wp_is_valid_utf8( $string );
5154 - }
5155 -
5156 - // As of WP 6.9, seems_utf8 is deprecated.
5157 - return function_exists( 'seems_utf8' ) ? seems_utf8( $string ) : false;
3780 + /**
3781 + * @deprecated 2.05.06
3782 + * @codeCoverageIgnore
3783 + */
3784 + public static function esc_order_by( &$order_by ) {
3785 + FrmDeprecated::esc_order_by( $order_by );
5158 3786 }
5159 3787
5160 3788 /**
5161 - * Get a documentation URL with UTM parameters and affiliate tracking.
3789 + * @param string $limit
5162 3790 *
5163 - * @since 6.26
5164 - *
5165 - * @param string $path The relative path to append to the base URL.
5166 - * @param string $campaign The campaign to use for UTM parameters.
5167 - * @param bool $add_kb_base Whether to prepend 'knowledgebase/' to the path. Default true.
5168 - *
5169 - * @return string The processed URL with UTM parameters and affiliate tracking.
3791 + * @deprecated 2.05.06
3792 + * @codeCoverageIgnore
5170 3793 */
5171 - public static function get_doc_url( $path, $campaign, $add_kb_base = true ) {
5172 - $path = trim( $path, '/' );
3794 + public static function esc_limit( $limit ) {
3795 + return FrmDeprecated::esc_limit( $limit );
3796 + }
5173 3797
5174 - if ( $add_kb_base ) {
5175 - $path = 'knowledgebase/' . $path;
5176 - }
3798 + /**
3799 + * @since 2.0
3800 + * @deprecated 2.05.06
3801 + * @codeCoverageIgnore
3802 + */
3803 + public static function prepare_array_values( $array, $type = '%s' ) {
3804 + return FrmDeprecated::prepare_array_values( $array, $type );
3805 + }
5177 3806
5178 - return self::maybe_add_missing_utm( 'https://formidableforms.com/' . $path, array( 'campaign' => $campaign ) );
3807 + /**
3808 + * @deprecated 2.05.06
3809 + * @codeCoverageIgnore
3810 + */
3811 + public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) {
3812 + return FrmDeprecated::prepend_and_or_where( $starts_with, $where );
5179 3813 }
5180 3814
5181 3815 /**
5182 - * @since 5.0.16
5183 - * @deprecated 6.26
3816 + * @since 2.0
3817 + * @deprecated 5.0.13
5184 3818 *
5185 - * @return bool
3819 + * @return string The base Google APIS url for the current version of jQuery UI
5186 3820 */
5187 - public static function show_landing_pages() {
5188 - _deprecated_function( __METHOD__, '6.26' );
5189 - return true;
3821 + public static function jquery_ui_base_url() {
3822 + _deprecated_function( __FUNCTION__, '5.0.13', 'FrmProAppHelper::jquery_ui_base_url' );
3823 + return is_callable( 'FrmProAppHelper::jquery_ui_base_url' ) ? FrmProAppHelper::jquery_ui_base_url() : '';
3824 + }
3825 +
3826 + /**
3827 + * @since 4.07
3828 + * @deprecated x.x
3829 + */
3830 + public static function renewal_message() {
3831 + _deprecated_function( __METHOD__, 'x.x', 'FrmProAddonsController::renewal_message' );
5190 3832 }
5191 3833 }