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