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