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