PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8
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 +686 -1708 6.346.8 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 = 106;
12 + public static $db_version = 101;
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.34';
36 + public static $plug_version = '6.8';
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' ) ) {
@@ -937,9 +669,8 @@
937 669 } else {
938 670 self::sanitize_value( self::class . '::strip_most_html', $value );
939 671 }
940 672 self::decode_specialchars( $value );
941 - self::sanitize_value( 'FrmHtmlSanitizer::sanitize_url_attributes', $value );
942 673 }
943 674
944 675 /**
945 676 * Allow only a small set of very basic HTML for unprivileged users.
@@ -948,12 +679,8 @@
948 679 *
949 680 * @param string $value
950 681 */
951 682 public static function strip_most_html( $value ) {
952 - if ( '' === $value ) {
953 - return $value;
954 - }
955 -
956 683 $allowed_html = array(
957 684 'b' => array(),
958 685 'br' => array(),
959 686 'strong' => array(),
@@ -978,15 +705,12 @@
978 705 * Do wp_specialchars_decode to get back '&' that wp_kses_post might have turned to '&amp;'
979 706 * this MUST be done, else we'll be back to the '& entity' problem.
980 707 *
981 708 * @since 4.0.04
982 - *
983 - * @param mixed $value Value to decode, passed by reference.
984 709 */
985 710 public static function decode_specialchars( &$value ) {
986 711 if ( is_array( $value ) ) {
987 712 $temp_values = $value;
988 -
989 713 foreach ( $temp_values as $k => $v ) {
990 714 self::decode_specialchars( $value[ $k ] );
991 715 }
992 716 } else {
@@ -1000,13 +724,13 @@
1000 724 * Adapted from wp_specialchars_decode().
1001 725 *
1002 726 * @since 4.03.01
1003 727 *
1004 - * @param string $string The string to prep, passed by reference.
728 + * @param string $string The string to prep.
1005 729 */
1006 730 private static function decode_amp( &$string ) {
1007 731 // Don't bother if there are no entities - saves a lot of processing
1008 - if ( ! $string || ! str_contains( $string, '&' ) ) {
732 + if ( empty( $string ) || strpos( $string, '&' ) === false ) {
1009 733 return;
1010 734 }
1011 735
1012 736 $translation = array(
@@ -1044,29 +768,17 @@
1044 768 * Sanitize the value, and allow some HTML
1045 769 *
1046 770 * @since 2.0
1047 771 *
1048 - * @param string $value The value to sanitize.
1049 - * @param array|string $allowed Allowed HTML tags and attributes, or 'all' for defaults.
772 + * @param string $value
773 + * @param array|string $allowed 'all' for everything included as defaults.
1050 774 *
1051 775 * @return string
1052 776 */
1053 777 public static function kses( $value, $allowed = array() ) {
1054 - return wp_kses( $value, self::allowed_html( $allowed ) );
1055 - }
778 + $allowed_html = self::allowed_html( $allowed );
1056 779
1057 - /**
1058 - * Sanitizes and echoes a given value.
1059 - *
1060 - * @since 6.18
1061 - *
1062 - * @param string $value The value to sanitize and output.
1063 - * @param array|string $allowed Allowed HTML tags and attributes.
1064 - *
1065 - * @return void
1066 - */
1067 - public static function kses_echo( $value, $allowed = array() ) {
1068 - echo self::kses( $value, $allowed ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
780 + return wp_kses( $value, $allowed_html );
1069 781 }
1070 782
1071 783 /**
1072 784 * The regular kses function strips [button_action] from submit button HTML.
@@ -1073,23 +785,21 @@
1073 785 *
1074 786 * @since 5.0.13
1075 787 *
1076 788 * @param string $html
1077 - *
1078 789 * @return string
1079 790 */
1080 791 public static function kses_submit_button( $html ) {
1081 - $included_button_action = str_contains( $html, '[button_action]' );
1082 - $included_back_hook = str_contains( $html, '[back_hook]' );
1083 - $included_draft_hook = str_contains( $html, '[draft_hook]' );
792 + $included_button_action = false !== strpos( $html, '[button_action]' );
793 + $included_back_hook = false !== strpos( $html, '[back_hook]' );
794 + $included_draft_hook = false !== strpos( $html, '[draft_hook]' );
1084 795 add_filter( 'safe_style_css', 'FrmAppHelper::allow_visibility_style' );
1085 796 add_filter( 'frm_striphtml_allowed_tags', 'FrmAppHelper::add_allowed_submit_button_tags' );
1086 797 $html = self::kses( $html, 'all' );
1087 798 remove_filter( 'safe_style_css', 'FrmAppHelper::allow_visibility_style' );
1088 799 remove_filter( 'frm_striphtml_allowed_tags', 'FrmAppHelper::add_allowed_submit_button_tags' );
1089 -
1090 800 if ( $included_button_action ) {
1091 - if ( str_contains( $html, '<input type="submit"' ) ) {
801 + if ( false !== strpos( $html, '<input type="submit"' ) ) {
1092 802 $pattern = '/(<input type="submit")([^>]*)(\/>)/';
1093 803 $html = preg_replace( $pattern, '$1$2[button_action] $3', $html, 1 );
1094 804 } else {
1095 805 $pattern = '/(<button)(.*)(class=")(.*)(frm_button_submit)(.*)(")(.*)([^>]+)(>)/';
@@ -1095,17 +805,14 @@
1095 805 $pattern = '/(<button)(.*)(class=")(.*)(frm_button_submit)(.*)(")(.*)([^>]+)(>)/';
1096 806 $html = preg_replace( $pattern, '$1$2$3$4$5$6$7 [button_action]$8$9$10', $html, 1 );
1097 807 }
1098 808 }
1099 -
1100 809 if ( $included_back_hook ) {
1101 810 $html = str_replace( 'class="frm_prev_page"', 'class="frm_prev_page" [back_hook]', $html );
1102 811 }
1103 -
1104 812 if ( $included_draft_hook ) {
1105 - return str_replace( 'class="frm_save_draft"', 'class="frm_save_draft" [draft_hook]', $html );
813 + $html = str_replace( 'class="frm_save_draft"', 'class="frm_save_draft" [draft_hook]', $html );
1106 814 }
1107 -
1108 815 return $html;
1109 816 }
1110 817
1111 818 /**
@@ -1111,9 +818,8 @@
1111 818 /**
1112 819 * @since 5.0.13
1113 820 *
1114 821 * @param array $allowed_attr
1115 - *
1116 822 * @return array
1117 823 */
1118 824 public static function allow_visibility_style( $allowed_attr ) {
1119 825 $allowed_attr[] = 'visibility';
@@ -1123,9 +829,8 @@
1123 829 /**
1124 830 * @since 5.0.13
1125 831 *
1126 832 * @param array $allowed_html
1127 - *
1128 833 * @return array
1129 834 */
1130 835 public static function add_allowed_submit_button_tags( $allowed_html ) {
1131 836 $allowed_html['input'] = array(
@@ -1142,22 +847,17 @@
1142 847 }
1143 848
1144 849 /**
1145 850 * @since 2.05.03
1146 - *
1147 - * @param array|string $allowed
1148 - *
1149 - * @return array
1150 851 */
1151 852 private static function allowed_html( $allowed ) {
1152 853 $html = self::safe_html();
1153 854 $allowed_html = array();
1154 -
1155 855 if ( $allowed === 'all' ) {
1156 856 $allowed_html = $html;
1157 - } elseif ( $allowed ) {
857 + } elseif ( ! empty( $allowed ) ) {
1158 858 foreach ( (array) $allowed as $a ) {
1159 - $allowed_html[ $a ] = $html[ $a ] ?? array();
859 + $allowed_html[ $a ] = isset( $html[ $a ] ) ? $html[ $a ] : array();
1160 860 }
1161 861 }
1162 862
1163 863 return apply_filters( 'frm_striphtml_allowed_tags', $allowed_html );
@@ -1164,10 +864,8 @@
1164 864 }
1165 865
1166 866 /**
1167 867 * @since 2.05.03
1168 - *
1169 - * @return array
1170 868 */
1171 869 private static function safe_html() {
1172 870 $allow_class = array(
1173 871 'class' => true,
@@ -1174,9 +872,9 @@
1174 872 'id' => true,
1175 873 );
1176 874
1177 875 return array(
1178 - 'a' => array(
876 + 'a' => array(
1179 877 'class' => true,
1180 878 'href' => true,
1181 879 'id' => true,
1182 880 'rel' => true,
@@ -1245,16 +943,16 @@
1245 943 'cite' => true,
1246 944 'title' => true,
1247 945 ),
1248 946 'rect' => array(
1249 - 'class' => true,
1250 - 'fill' => true,
1251 - 'height' => true,
1252 - 'width' => true,
1253 - 'x' => true,
1254 - 'y' => true,
1255 - 'rx' => true,
1256 - 'stroke' => true,
947 + 'class' => true,
948 + 'fill' => true,
949 + 'height' => true,
950 + 'width' => true,
951 + 'x' => true,
952 + 'y' => true,
953 + 'rx' => true,
954 + 'stroke' => true,
1257 955 'stroke-opacity' => true,
1258 956 'stroke-width' => true,
1259 957 ),
1260 958 'section' => $allow_class,
@@ -1289,9 +987,9 @@
1289 987 'xlink:href' => true,
1290 988 ),
1291 989 'ul' => $allow_class,
1292 990 'label' => array(
1293 - 'for' => true,
991 + 'for' => true,
1294 992 'class' => true,
1295 993 'id' => true,
1296 994 ),
1297 995 'button' => array(
@@ -1300,13 +998,8 @@
1300 998 ),
1301 999 'legend' => array(
1302 1000 'class' => true,
1303 1001 ),
1304 - 'option' => array(
1305 - 'class' => true,
1306 - 'value' => true,
1307 - 'selected' => true,
1308 - ),
1309 1002 );
1310 1003 }
1311 1004
1312 1005 /**
@@ -1319,16 +1012,14 @@
1319 1012 return;
1320 1013 }
1321 1014
1322 1015 $action_name = isset( $_GET['action'] ) ? 'action' : ( isset( $_GET['action2'] ) ? 'action2' : '' );
1323 -
1324 - if ( ! $action_name ) {
1016 + if ( empty( $action_name ) ) {
1325 1017 return;
1326 1018 }
1327 1019
1328 1020 $new_action = self::get_param( $action_name, '', 'get', 'sanitize_text_field' );
1329 -
1330 - if ( $new_action ) {
1021 + if ( ! empty( $new_action ) ) {
1331 1022 $_SERVER['REQUEST_URI'] = str_replace( '&action=' . $new_action, '', self::get_server_value( 'REQUEST_URI' ) );
1332 1023 }
1333 1024 }
1334 1025
@@ -1335,23 +1026,21 @@
1335 1026 /**
1336 1027 * Check the WP query for a parameter
1337 1028 *
1338 1029 * @since 2.0
1339 - *
1340 - * @param array|string $value
1341 - * @param string $param
1342 - *
1343 - * @return array|string
1030 + * @return string|array
1344 1031 */
1345 1032 public static function get_query_var( $value, $param ) {
1346 - // phpcs:ignore Universal.Operators.StrictComparisons
1347 1033 if ( $value != '' ) {
1348 1034 return $value;
1349 1035 }
1350 1036
1351 1037 global $wp_query;
1038 + if ( isset( $wp_query->query_vars[ $param ] ) ) {
1039 + $value = $wp_query->query_vars[ $param ];
1040 + }
1352 1041
1353 - return $wp_query->query_vars[ $param ] ?? $value;
1042 + return $value;
1354 1043 }
1355 1044
1356 1045 /**
1357 1046 * Try to show the SVG if possible. Otherwise, use the font icon.
@@ -1356,24 +1045,21 @@
1356 1045 /**
1357 1046 * Try to show the SVG if possible. Otherwise, use the font icon.
1358 1047 *
1359 1048 * @since 4.0.02
1360 - *
1361 1049 * @param string $class
1362 1050 * @param array $atts
1363 - *
1364 - * @return string|null
1365 1051 */
1366 1052 public static function icon_by_class( $class, $atts = array() ) {
1367 1053 $echo = ! isset( $atts['echo'] ) || $atts['echo'];
1368 -
1369 1054 if ( isset( $atts['echo'] ) ) {
1370 1055 unset( $atts['echo'] );
1371 1056 }
1372 1057
1373 1058 $html_atts = self::array_to_html_params( $atts );
1374 - $icon = trim( str_replace( array( 'frm_icon_font', 'frmfont ' ), '', $class ) );
1375 1059
1060 + $icon = trim( str_replace( array( 'frm_icon_font', 'frmfont ' ), '', $class ) );
1061 +
1376 1062 // Replace icons that have been removed or renamed.
1377 1063 $deprecated = array(
1378 1064 'frm_clone_solid_icon' => 'frm_clone_icon',
1379 1065 'frm_keyalt_icon' => 'frm_key_icon',
@@ -1378,9 +1064,8 @@
1378 1064 'frm_clone_solid_icon' => 'frm_clone_icon',
1379 1065 'frm_keyalt_icon' => 'frm_key_icon',
1380 1066 'frm_keyalt_solid_icon' => 'frm_key_solid_icon',
1381 1067 );
1382 -
1383 1068 if ( isset( $deprecated[ $icon ] ) ) {
1384 1069 $icon = $deprecated[ $icon ];
1385 1070 $class = str_replace( $icon, $deprecated[ $icon ], $class );
1386 1071 }
@@ -1387,24 +1072,23 @@
1387 1072
1388 1073 if ( $icon === $class ) {
1389 1074 $icon = '<i class="' . esc_attr( $class ) . '"' . $html_atts . '></i>';
1390 1075 } else {
1391 - $class = str_contains( $icon, ' ' ) ? ' ' . $icon : '';
1392 -
1393 - if ( str_contains( $icon, ' ' ) ) {
1076 + $class = strpos( $icon, ' ' ) === false ? '' : ' ' . $icon;
1077 + if ( strpos( $icon, ' ' ) ) {
1394 1078 $icon = explode( ' ', $icon );
1395 1079 $icon = reset( $icon );
1396 1080 }
1397 -
1398 - $icon = '<svg class="frmsvg' . esc_attr( $class ) . '"' . $html_atts . '><use href="#' . esc_attr( $icon ) . '" /></svg>';
1081 + $icon = '<svg class="frmsvg' . esc_attr( $class ) . '"' . $html_atts . '>
1082 + <use xlink:href="#' . esc_attr( $icon ) . '" />
1083 + </svg>';
1399 1084 }
1400 1085
1401 1086 if ( $echo ) {
1402 1087 echo self::kses_icon( $icon ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1403 - return null;
1088 + } else {
1089 + return $icon;
1404 1090 }
1405 -
1406 - return $icon;
1407 1091 }
1408 1092
1409 1093 /**
1410 1094 * Run kses for icons. It needs to add a few filters first in order to preserve some custom style values.
@@ -1411,9 +1095,8 @@
1411 1095 *
1412 1096 * @since 5.0.13
1413 1097 *
1414 1098 * @param string $icon
1415 - *
1416 1099 * @return string
1417 1100 */
1418 1101 public static function kses_icon( $icon ) {
1419 1102 add_filter( 'safe_style_css', 'FrmAppHelper::allow_vars_in_styles' );
@@ -1429,15 +1112,13 @@
1429 1112 /**
1430 1113 * @since 5.0.13.1
1431 1114 *
1432 1115 * @param array $allowed_html
1433 - *
1434 1116 * @return array
1435 1117 */
1436 1118 public static function add_allowed_icon_tags( $allowed_html ) {
1437 1119 $allowed_html['svg']['data-open'] = true;
1438 1120 $allowed_html['svg']['title'] = true;
1439 - $allowed_html['svg']['tabindex'] = true;
1440 1121 return $allowed_html;
1441 1122 }
1442 1123
1443 1124 /**
@@ -1443,9 +1124,8 @@
1443 1124 /**
1444 1125 * @since 5.0.13
1445 1126 *
1446 1127 * @param array $allowed_attr
1447 - *
1448 1128 * @return array
1449 1129 */
1450 1130 public static function allow_vars_in_styles( $allowed_attr ) {
1451 1131 $allowed_attr[] = '--primary-700';
@@ -1458,9 +1138,9 @@
1458 1138 * @param bool $allow_css
1459 1139 * @param string $css_string
1460 1140 */
1461 1141 public static function allow_style( $allow_css, $css_string ) {
1462 - if ( ! $allow_css && str_starts_with( $css_string, '--primary-700:' ) ) {
1142 + if ( ! $allow_css && 0 === strpos( $css_string, '--primary-700:' ) ) {
1463 1143 $split = explode( ':', $css_string, 2 );
1464 1144 $allow_css = 2 === count( $split ) && self::is_a_valid_color( $split[1] );
1465 1145 }
1466 1146 return $allow_css;
@@ -1469,22 +1149,19 @@
1469 1149 /**
1470 1150 * @since 5.0.13
1471 1151 *
1472 1152 * @param string $value
1473 - *
1474 1153 * @return bool
1475 1154 */
1476 1155 private static function is_a_valid_color( $value ) {
1477 1156 $match = 0;
1478 -
1479 - if ( str_starts_with( $value, 'rgba(' ) ) {
1157 + if ( 0 === strpos( $value, 'rgba(' ) ) {
1480 1158 $match = preg_match( '/^rgba\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d*(?:\.\d+)?)\)$/', $value );
1481 - } elseif ( str_starts_with( $value, 'rgb(' ) ) {
1159 + } elseif ( 0 === strpos( $value, 'rgb(' ) ) {
1482 1160 $match = preg_match( '/^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/', $value );
1483 - } elseif ( str_starts_with( $value, '#' ) ) {
1161 + } elseif ( 0 === strpos( $value, '#' ) ) {
1484 1162 $match = preg_match( '/^#([a-f0-9]{6}|[a-f0-9]{3})\b$/', $value );
1485 1163 }
1486 -
1487 1164 return (bool) $match;
1488 1165 }
1489 1166
1490 1167 /**
@@ -1490,9 +1167,8 @@
1490 1167 /**
1491 1168 * Include svg images.
1492 1169 *
1493 1170 * @since 4.0.02
1494 - *
1495 1171 * @return void
1496 1172 */
1497 1173 public static function include_svg() {
1498 1174 if ( self::$included_svg ) {
@@ -1511,20 +1187,17 @@
1511 1187 * @since 5.0.13 added $echo parameter.
1512 1188 *
1513 1189 * @param array $atts
1514 1190 * @param bool $echo
1515 - *
1516 1191 * @return string|void
1517 1192 */
1518 1193 public static function array_to_html_params( $atts, $echo = false ) {
1519 - $callback = function () use ( $atts ) {
1520 - if ( ! $atts ) {
1521 - return;
1194 + $callback = function() use ( $atts ) {
1195 + if ( $atts ) {
1196 + foreach ( $atts as $key => $value ) {
1197 + echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
1198 + }
1522 1199 }
1523 -
1524 - foreach ( $atts as $key => $value ) {
1525 - echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
1526 - }
1527 1200 };
1528 1201 return self::clip( $callback, $echo );
1529 1202 }
1530 1203
@@ -1534,12 +1207,9 @@
1534 1207 * @since 5.0.13
1535 1208 *
1536 1209 * @param Closure $echo_function
1537 1210 * @param bool $echo
1538 - *
1539 - * @return string|null
1540 - *
1541 - * @psalm-return ($echo is true ? null : string)
1211 + * @return string|void
1542 1212 */
1543 1213 public static function clip( $echo_function, $echo = false ) {
1544 1214 if ( ! $echo ) {
1545 1215 ob_start();
@@ -1548,30 +1218,28 @@
1548 1218 if ( is_callable( $echo_function ) ) {
1549 1219 $echo_function();
1550 1220 }
1551 1221
1552 - return $echo ? null : ob_get_clean();
1222 + if ( ! $echo ) {
1223 + $return = ob_get_contents();
1224 + ob_end_clean();
1225 + return $return;
1226 + }
1553 1227 }
1554 1228
1555 1229 /**
1556 1230 * @since 3.0
1557 - *
1558 - * @param array $atts
1559 - *
1560 - * @return void
1561 1231 */
1562 1232 public static function get_admin_header( $atts ) {
1563 - $has_nav = ! empty( $atts['form'] ) && empty( $atts['is_template'] );
1564 -
1565 - if ( empty( $atts['close'] ) ) {
1233 + $has_nav = ( isset( $atts['form'] ) && ! empty( $atts['form'] ) && ( ! isset( $atts['is_template'] ) || ! $atts['is_template'] ) );
1234 + if ( ! isset( $atts['close'] ) || empty( $atts['close'] ) ) {
1566 1235 $atts['close'] = admin_url( 'admin.php?page=formidable' );
1567 1236 }
1568 -
1569 1237 if ( ! isset( $atts['import_link'] ) ) {
1570 1238 $atts['import_link'] = false;
1571 1239 }
1572 1240
1573 - include self::plugin_path() . '/classes/views/shared/admin-header.php';
1241 + include( self::plugin_path() . '/classes/views/shared/admin-header.php' );
1574 1242 }
1575 1243
1576 1244 /**
1577 1245 * @since 6.0
@@ -1576,19 +1244,16 @@
1576 1244 /**
1577 1245 * @since 6.0
1578 1246 *
1579 1247 * @param string $type
1580 - *
1581 1248 * @return void
1582 1249 */
1583 1250 public static function import_link( $type = 'secondary' ) {
1584 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1585 1251 ?>
1586 1252 <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">
1587 1253 <?php esc_html_e( 'Import', 'formidable' ); ?>
1588 1254 </a>
1589 1255 <?php
1590 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1591 1256 }
1592 1257
1593 1258 /**
1594 1259 * Print applicable admin banner.
@@ -1595,9 +1260,8 @@
1595 1260 *
1596 1261 * @since 5.4.2
1597 1262 *
1598 1263 * @param bool $should_show_lite_upgrade
1599 - *
1600 1264 * @return void
1601 1265 */
1602 1266 public static function print_admin_banner( $should_show_lite_upgrade ) {
1603 1267 if ( ! current_user_can( 'administrator' ) ) {
@@ -1604,44 +1268,19 @@
1604 1268 FrmInbox::maybe_show_banner();
1605 1269 return;
1606 1270 }
1607 1271
1608 - if ( FrmSalesApi::maybe_show_banner() || self::maybe_show_license_warning() || FrmInbox::maybe_show_banner() || ! $should_show_lite_upgrade || self::pro_is_installed() ) {
1272 + if ( self::maybe_show_license_warning() || FrmInbox::maybe_show_banner() || ! $should_show_lite_upgrade || self::pro_is_installed() ) {
1609 1273 // Print license warning or inbox banner and exit if either prints.
1610 1274 // And exit before printing the upgrade bar if it shouldn't be shown.
1611 1275 return;
1612 1276 }
1613 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1614 1277 ?>
1615 1278 <div class="frm-upgrade-bar">
1616 - <div class="frm-upgrade-bar-inner">
1617 - <?php
1618 - $cta_text = FrmSalesApi::get_best_sale_value( 'lite_banner_cta_text' );
1619 -
1620 - if ( ! $cta_text ) {
1621 - $cta_text = __( 'upgrading to PRO', 'formidable' );
1622 - }
1623 -
1624 - $upgrade_link = FrmSalesApi::get_best_sale_value( 'lite_banner_cta_link' );
1625 - $utm = array(
1626 - 'campaign' => 'settings-license',
1627 - 'content' => 'lite-banner',
1628 - );
1629 -
1630 - $upgrade_link = $upgrade_link ? self::maybe_add_missing_utm( $upgrade_link, $utm ) : self::admin_upgrade_link( $utm );
1631 -
1632 - printf(
1633 - /* translators: %1$s: Start link HTML, %2$s: CTA text ("upgrading to PRO" by default), %3$s: End link HTML */
1634 - esc_html__( 'You\'re using Formidable Forms Lite. To unlock more features consider %1$s%2$s%3$s.', 'formidable' ),
1635 - '<a href="' . esc_url( $upgrade_link ) . '">',
1636 - esc_html( $cta_text ),
1637 - '</a>'
1638 - );
1639 - ?>
1640 - </div>
1279 + <span>You're using Formidable Forms Lite. To unlock more features consider</span>
1280 + <a href="<?php echo esc_url( self::admin_upgrade_link( 'top-bar' ) ); ?>" target="_blank" rel="noopener">upgrading to Pro</a>.
1641 1281 </div>
1642 1282 <?php
1643 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1644 1283 }
1645 1284
1646 1285 /**
1647 1286 * @since 5.4.2
@@ -1655,9 +1294,8 @@
1655 1294 /**
1656 1295 * Render a button for a new item (Form, Application, etc).
1657 1296 *
1658 1297 * @since 3.0
1659 - *
1660 1298 * @param array $atts {
1661 1299 * Details about the button.
1662 1300 *
1663 1301 * @type array $link_hook Custom link hook, calls do_action and exits early.
@@ -1664,9 +1302,8 @@
1664 1302 * @type string $new_link Href value, default #.
1665 1303 * @type string $class Custom class names, space separated.
1666 1304 * @type string $button_text Button text. Default "Add New".
1667 1305 * }
1668 - *
1669 1306 * @return void
1670 1307 */
1671 1308 public static function add_new_item_link( $atts ) {
1672 1309 if ( isset( $atts['link_hook'] ) ) {
@@ -1692,12 +1329,8 @@
1692 1329 }
1693 1330
1694 1331 /**
1695 1332 * @since 3.06
1696 - *
1697 - * @param array $atts
1698 - *
1699 - * @return void
1700 1333 */
1701 1334 public static function show_search_box( $atts ) {
1702 1335 $defaults = array(
1703 1336 'placeholder' => '',
@@ -1703,12 +1336,10 @@
1703 1336 'placeholder' => '',
1704 1337 'tosearch' => '',
1705 1338 'text' => __( 'Search', 'formidable' ),
1706 1339 'input_id' => '',
1707 - 'value' => false,
1708 - 'class' => '',
1709 1340 );
1710 - $atts = array_merge( $defaults, $atts );
1341 + $atts = array_merge( $defaults, $atts );
1711 1342
1712 1343 if ( $atts['input_id'] === 'template' && empty( $atts['tosearch'] ) ) {
1713 1344 $atts['tosearch'] = 'frm-card';
1714 1345 }
@@ -1713,9 +1344,8 @@
1713 1344 $atts['tosearch'] = 'frm-card';
1714 1345 }
1715 1346
1716 1347 $class = 'frm-search-input';
1717 -
1718 1348 if ( ! empty( $atts['tosearch'] ) ) {
1719 1349 $class .= ' frm-auto-search';
1720 1350 }
1721 1351
@@ -1720,35 +1350,21 @@
1720 1350 }
1721 1351
1722 1352 $input_id = $atts['input_id'] . '-search-input';
1723 1353
1724 - $input_atts = array(
1725 - 'type' => 'search',
1726 - 'id' => $input_id,
1727 - 'name' => 's',
1728 - 'placeholder' => $atts['placeholder'],
1729 - 'class' => $class,
1730 - 'data-tosearch' => $atts['tosearch'],
1731 - );
1732 -
1733 - if ( is_string( $atts['value'] ) ) {
1734 - $input_atts['value'] = $atts['value'];
1735 - } elseif ( isset( $_REQUEST['s'] ) ) {
1736 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1737 - $input_atts['value'] = wp_unslash( $_REQUEST['s'] );
1738 - }
1739 -
1740 - if ( ! empty( $atts['tosearch'] ) ) {
1741 - $input_atts['autocomplete'] = 'off';
1742 - }
1743 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1744 1354 ?>
1745 - <p class="frm-search <?php echo esc_attr( $atts['class'] ); ?>">
1355 + <p class="frm-search">
1746 1356 <label class="screen-reader-text" for="<?php echo esc_attr( $input_id ); ?>">
1747 1357 <?php echo esc_html( $atts['text'] ); ?>:
1748 1358 </label>
1749 - <?php self::icon_by_class( 'frmfont frm_search_icon frm_svg20' ); ?>
1750 - <input <?php self::array_to_html_params( $input_atts, true ); ?> />
1359 + <span class="frmfont frm_search_icon"></span>
1360 + <input type="search" id="<?php echo esc_attr( $input_id ); ?>" name="s"
1361 + value="<?php _admin_search_query(); ?>" placeholder="<?php echo esc_attr( $atts['placeholder'] ); ?>"
1362 + class="<?php echo esc_attr( $class ); ?>" data-tosearch="<?php echo esc_attr( $atts['tosearch'] ); ?>"
1363 + <?php if ( ! empty( $atts['tosearch'] ) ) { ?>
1364 + autocomplete="off"
1365 + <?php } ?>
1366 + />
1751 1367 <?php
1752 1368 if ( empty( $atts['tosearch'] ) ) {
1753 1369 submit_button( $atts['text'], 'button-secondary', '', false, array( 'id' => 'search-submit' ) );
1754 1370 }
@@ -1754,21 +1370,16 @@
1754 1370 }
1755 1371 ?>
1756 1372 </p>
1757 1373 <?php
1758 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1759 1374 }
1760 1375
1761 1376 /**
1762 - * @param string $type Hook type slug.
1763 - * @param object|null $object Optional related object.
1764 - *
1765 - * @return void
1377 + * @param string $type
1766 1378 */
1767 1379 public static function trigger_hook_load( $type, $object = null ) {
1768 1380 // Only load the form hooks once.
1769 1381 $hooks_loaded = apply_filters( 'frm_' . $type . '_hooks_loaded', false, $object );
1770 -
1771 1382 if ( ! $hooks_loaded ) {
1772 1383 do_action( 'frm_load_' . $type . '_hooks' );
1773 1384 }
1774 1385 }
@@ -1808,9 +1419,9 @@
1808 1419 'new_file_path' => self::plugin_path() . '/js',
1809 1420 )
1810 1421 );
1811 1422 $new_file = new FrmCreateFile( $file_atts );
1812 - $files = array(
1423 + $files = array(
1813 1424 FrmStrpLiteAppHelper::plugin_path() . 'js/frmstrp.min.js',
1814 1425 );
1815 1426
1816 1427 /**
@@ -1827,14 +1438,14 @@
1827 1438 * True when value is 1, true, 'true', 'yes'
1828 1439 *
1829 1440 * @since 1.07.10
1830 1441 *
1831 - * @param bool|int|string $value The value to compare.
1442 + * @param string $value The value to compare.
1832 1443 *
1833 - * @return bool
1444 + * @return boolean True or False
1834 1445 */
1835 1446 public static function is_true( $value ) {
1836 - return true === $value || '1' === (string) $value || 'true' === $value || 'yes' === $value;
1447 + return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value );
1837 1448 }
1838 1449
1839 1450 /**
1840 1451 * Gets all post from a specific post type.
@@ -1842,9 +1453,8 @@
1842 1453 *
1843 1454 * @since 4.10.01 Add `$post_type` argument.
1844 1455 *
1845 1456 * @param string $post_type Post type to query. Default is `page`.
1846 - *
1847 1457 * @return WP_Post[]
1848 1458 */
1849 1459 public static function get_pages( $post_type = 'page' ) {
1850 1460 $query = array(
@@ -1863,9 +1473,8 @@
1863 1473 *
1864 1474 * @since 5.0.09
1865 1475 *
1866 1476 * @param string $post_type Post type to query. Default is `page`.
1867 - *
1868 1477 * @return array
1869 1478 */
1870 1479 public static function get_post_ids_and_titles( $post_type = 'page' ) {
1871 1480 return FrmDb::get_results(
@@ -1890,12 +1499,13 @@
1890 1499 *
1891 1500 * @param array $args Selection arguments.
1892 1501 */
1893 1502 public static function maybe_autocomplete_pages_options( $args ) {
1894 - $args = self::preformat_selection_args( $args );
1503 + $args = self::preformat_selection_args( $args );
1504 +
1895 1505 $pages_count = wp_count_posts( $args['post_type'] );
1896 1506
1897 - if ( ! isset( $pages_count->publish ) || $pages_count->publish <= 50 ) {
1507 + if ( $pages_count->publish <= 50 ) {
1898 1508 self::wp_pages_dropdown( $args );
1899 1509 return;
1900 1510 }
1901 1511
@@ -1901,9 +1511,9 @@
1901 1511
1902 1512 wp_enqueue_script( 'jquery-ui-autocomplete' );
1903 1513
1904 1514 $selected = self::get_post_param( $args['field_name'], $args['page_id'], 'absint' );
1905 - $title = '';
1515 + $title = '';
1906 1516
1907 1517 if ( $selected ) {
1908 1518 $title = get_the_title( $selected );
1909 1519 }
@@ -1919,119 +1529,18 @@
1919 1529 <?php
1920 1530 }
1921 1531
1922 1532 /**
1923 - * Maybe show an HTML select or autocomplete input based on the number of options.
1924 - *
1925 - * @since 6.21
1926 - *
1927 - * @param array $args Args. See the method for details.
1533 + * @param array $args
1534 + * @param string $page_id Deprecated.
1535 + * @param boolean $truncate Deprecated.
1928 1536 */
1929 - public static function maybe_autocomplete_options( $args ) {
1930 - $defaults = array(
1931 - 'truncate' => false,
1932 - 'placeholder' => ' ',
1933 - 'name' => '',
1934 - 'id' => '',
1935 - 'selected' => '',
1936 - 'source' => array(),
1937 - 'dropdown_limit' => 50,
1938 - 'autocomplete_placeholder' => __( 'Select an option', 'formidable' ),
1939 - 'value_key' => 'value',
1940 - 'label_key' => 'label',
1941 - );
1942 -
1943 - $args = wp_parse_args( $args, $defaults );
1944 - $html_attrs = array();
1945 -
1946 - if ( ! empty( $args['name'] ) ) {
1947 - $html_attrs['name'] = $args['name'];
1948 - }
1949 -
1950 - if ( ! empty( $args['id'] ) ) {
1951 - $html_attrs['id'] = $args['id'];
1952 - }
1953 -
1954 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1955 - if ( count( $args['source'] ) <= $args['dropdown_limit'] ) {
1956 - ?>
1957 - <select <?php self::array_to_html_params( $html_attrs, true ); ?>>
1958 - <option value=""><?php echo esc_html( $args['placeholder'] ); ?></option>
1959 - <?php
1960 - foreach ( $args['source'] as $key => $source ) :
1961 - $value_label = self::get_dropdown_value_and_label_from_option( $source, $key, $args );
1962 -
1963 - if ( ! empty( $args['truncate'] ) ) {
1964 - $value_label['label'] = self::truncate( $value_label['label'], $args['truncate'] );
1965 - }
1966 - ?>
1967 - <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 ?>
1968 - <?php endforeach; ?>
1969 - </select>
1970 - <?php
1971 - return;
1972 - }
1973 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1974 -
1975 - $options = array();
1976 - $autocomplete_value = '';
1977 -
1978 - foreach ( $args['source'] as $key => $source ) {
1979 - $value_label = self::get_dropdown_value_and_label_from_option( $source, $key, $args );
1980 -
1981 - if ( $value_label['value'] === $args['selected'] ) {
1982 - $autocomplete_value = $value_label['label'];
1983 - }
1984 -
1985 - $options[] = $value_label;
1986 - }
1987 -
1988 - $html_attrs['type'] = 'hidden';
1989 - $html_attrs['class'] = 'frm_autocomplete_value_input';
1990 - $html_attrs['value'] = $args['selected'];
1991 - ?>
1992 - <input type="text" class="frm-custom-search"
1993 - data-source="<?php echo esc_attr( wp_json_encode( $options ) ); ?>"
1994 - placeholder="<?php echo esc_attr( $args['autocomplete_placeholder'] ); ?>"
1995 - value="<?php echo esc_attr( $autocomplete_value ); ?>" />
1996 - <input <?php self::array_to_html_params( $html_attrs, true ); ?> />
1997 - <?php
1998 - }
1999 -
2000 - /**
2001 - * Gets dropdown value and label from autodropdown option.
2002 - *
2003 - * @since 6.21
2004 - *
2005 - * @param array|string $option Autocomplete option.
2006 - * @param string $key Array key of the option.
2007 - * @param array $args See {@see FrmAppHelper::maybe_autocomplete_options()}.
2008 - *
2009 - * @return array
2010 - */
2011 - private static function get_dropdown_value_and_label_from_option( $option, $key, $args ) {
2012 - if ( is_array( $option ) ) {
2013 - $value = $option[ $args['value_key'] ] ?? '';
2014 - $label = $option[ $args['label_key'] ] ?? '';
2015 - } else {
2016 - $value = $key;
2017 - $label = $option;
2018 - }
2019 -
2020 - return compact( 'value', 'label' );
2021 - }
2022 -
2023 - /**
2024 - * @param array $args
2025 - * @param string $page_id Deprecated.
2026 - * @param bool $truncate Deprecated.
2027 - */
2028 1537 public static function wp_pages_dropdown( $args = array(), $page_id = '', $truncate = false ) {
2029 1538 self::prep_page_dropdown_params( $page_id, $truncate, $args );
2030 1539
2031 1540 $pages = self::get_post_ids_and_titles( $args['post_type'] );
2032 1541 $selected = self::get_post_param( $args['field_name'], $args['page_id'], 'absint' );
2033 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
1542 +
2034 1543 ?>
2035 1544 <select name="<?php echo esc_attr( $args['field_name'] ); ?>" id="<?php echo esc_attr( $args['field_name'] ); ?>" class="frm-pages-dropdown">
2036 1545 <option value=""><?php echo esc_html( $args['placeholder'] ); ?></option>
2037 1546 <?php foreach ( $pages as $page ) { ?>
@@ -2040,9 +1549,8 @@
2040 1549 </option>
2041 1550 <?php } ?>
2042 1551 </select>
2043 1552 <?php
2044 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
2045 1553 }
2046 1554
2047 1555 /**
2048 1556 * Fill in missing parameters passed to wp_pages_dropdown().
@@ -2048,14 +1556,8 @@
2048 1556 * Fill in missing parameters passed to wp_pages_dropdown().
2049 1557 * This is for reverse compatibility with switching 3 params to 1.
2050 1558 *
2051 1559 * @since 4.03.06
2052 - *
2053 - * @param string $page_id Deprecated.
2054 - * @param bool $truncate Deprecated.
2055 - * @param mixed $args
2056 - *
2057 - * @return void
2058 1560 */
2059 1561 private static function prep_page_dropdown_params( $page_id, $truncate, &$args ) {
2060 1562 if ( ! is_array( $args ) ) {
2061 1563 $args = array(
@@ -2072,20 +1574,16 @@
2072 1574 * Filter to format args for page dropdown or autocomplete
2073 1575 *
2074 1576 * @since 4.03.06
2075 1577 * @since 4.10.01 Added `post_type` and `autocomplete_placeholder` to the arguments array.
2076 - *
2077 - * @param array $args
2078 - *
2079 - * @return array
2080 1578 */
2081 1579 private static function preformat_selection_args( $args ) {
2082 1580 $defaults = array(
2083 - 'truncate' => false,
2084 - 'placeholder' => ' ',
2085 - 'field_name' => '',
2086 - 'page_id' => '',
2087 - 'post_type' => 'page',
1581 + 'truncate' => false,
1582 + 'placeholder' => ' ',
1583 + 'field_name' => '',
1584 + 'page_id' => '',
1585 + 'post_type' => 'page',
2088 1586 'autocomplete_placeholder' => __( 'Select a Page', 'formidable' ),
2089 1587 );
2090 1588
2091 1589 return array_merge( $defaults, $args );
@@ -2090,18 +1588,13 @@
2090 1588
2091 1589 return array_merge( $defaults, $args );
2092 1590 }
2093 1591
2094 - /**
2095 - * @param int $post_id
2096 - *
2097 - * @return string
2098 - */
2099 1592 public static function post_edit_link( $post_id ) {
2100 1593 $post = get_post( $post_id );
2101 -
2102 1594 if ( $post ) {
2103 1595 $post_url = admin_url( 'post.php?post=' . $post_id . '&action=edit' );
1596 +
2104 1597 return '<a href="' . esc_url( $post_url ) . '">' . self::truncate( $post->post_title, 50 ) . '</a>';
2105 1598 }
2106 1599
2107 1600 return '';
@@ -2114,9 +1607,11 @@
2114 1607 *
2115 1608 * @return bool
2116 1609 */
2117 1610 public static function is_full_screen() {
2118 - return self::is_form_builder_page() || self::is_style_editor_page() || self::is_full_screen_view_builder_page();
1611 + return self::is_form_builder_page() ||
1612 + self::is_style_editor_page() ||
1613 + self::is_full_screen_view_builder_page();
2119 1614 }
2120 1615
2121 1616 /**
2122 1617 * Check if user is on the style editor or its alternative URL.
@@ -2126,9 +1621,8 @@
2126 1621 * @since 5.5.3
2127 1622 * @since 6.0 Added the $view parameter. Previously there was only a 'edit' view.
2128 1623 *
2129 1624 * @param string $view Supports 'edit', 'list', and ''. If '', both 'edit' and 'list' will match.
2130 - *
2131 1625 * @return bool
2132 1626 */
2133 1627 public static function is_style_editor_page( $view = '' ) {
2134 1628 if ( ! self::is_admin_page( 'formidable-styles' ) && ! self::is_admin_page( 'formidable-styles2' ) ) {
@@ -2160,27 +1654,33 @@
2160 1654 return self::is_admin_page( 'formidable-views-editor' );
2161 1655 }
2162 1656
2163 1657 /**
1658 + * @since 4.0
1659 + * @deprecated 5.5.3
1660 + */
1661 + public static function maybe_full_screen_link( $link ) {
1662 + _deprecated_function( __METHOD__, '5.5.3' );
1663 + return $link;
1664 + }
1665 +
1666 + /**
2164 1667 * @param string $field_name
2165 - * @param array|string $capability
1668 + * @param string|array $capability
2166 1669 * @param string $multiple 'single' and 'multiple'.
2167 1670 */
2168 1671 public static function wp_roles_dropdown( $field_name, $capability, $multiple = 'single' ) {
2169 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
2170 1672 ?>
2171 1673 <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>"
2172 - <?php echo 'multiple' === $multiple ? 'multiple="multiple"' : ''; ?>
1674 + <?php echo ( 'multiple' === $multiple ) ? 'multiple="multiple"' : ''; ?>
2173 1675 class="frm_multiselect">
2174 1676 <?php self::roles_options( $capability ); ?>
2175 1677 </select>
2176 1678 <?php
2177 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
2178 1679 }
2179 1680
2180 1681 /**
2181 1682 * @since 4.07
2182 - *
2183 1683 * @param array|string $selected
2184 1684 * @param string $current
2185 1685 */
2186 1686 private static function selected( $selected, $current ) {
@@ -2191,13 +1691,12 @@
2191 1691 }
2192 1692 }
2193 1693
2194 1694 /**
2195 - * @param array|string $capability
1695 + * @param string|array $capability
2196 1696 */
2197 1697 public static function roles_options( $capability ) {
2198 1698 global $frm_vars;
2199 -
2200 1699 if ( isset( $frm_vars['editable_roles'] ) ) {
2201 1700 $editable_roles = $frm_vars['editable_roles'];
2202 1701 } else {
2203 1702 $editable_roles = get_editable_roles();
@@ -2206,9 +1705,9 @@
2206 1705
2207 1706 foreach ( $editable_roles as $role => $details ) {
2208 1707 $name = translate_user_role( $details['name'] );
2209 1708 ?>
2210 - <option value="<?php echo esc_attr( $role ); ?>" <?php self::selected( $capability, $role ); ?>><?php echo esc_html( $name ); ?></option>
1709 + <option value="<?php echo esc_attr( $role ); ?>" <?php self::selected( $capability, $role ); ?>><?php echo esc_attr( $name ); ?> </option>
2211 1710 <?php
2212 1711 unset( $role, $details );
2213 1712 }
2214 1713 }
@@ -2218,9 +1717,8 @@
2218 1717 *
2219 1718 * @since 5.0 Parameter `$type` supports `pro_only` value.
2220 1719 *
2221 1720 * @param string $type Supports `auto`, `pro`, or `pro_only`.
2222 - *
2223 1721 * @return array
2224 1722 */
2225 1723 public static function frm_capabilities( $type = 'auto' ) {
2226 1724 if ( ! self::pro_is_installed() && ! in_array( $type, array( 'pro', 'pro_only' ), true ) ) {
@@ -2238,8 +1736,14 @@
2238 1736 * @param array<string,string> $pro_cap
2239 1737 */
2240 1738 $pro_cap = apply_filters( 'frm_pro_capabilities', $pro_cap );
2241 1739
1740 + if ( ! array_key_exists( 'frm_edit_displays', $pro_cap ) && is_callable( 'FrmProAppHelper::views_is_installed' ) && FrmProAppHelper::views_is_installed() ) {
1741 + // For backward compatibility, add the Add/Edit Views permission if Pro is not up to date.
1742 + // This was added in 6.5.4. Remove this in the future.
1743 + $pro_cap['frm_edit_displays'] = __( 'Add/Edit Views', 'formidable' );
1744 + }
1745 +
2242 1746 if ( 'pro_only' === $type ) {
2243 1747 return $pro_cap;
2244 1748 }
2245 1749
@@ -2285,18 +1789,21 @@
2285 1789 if ( $role === 'loggedin' || ! $role ) {
2286 1790 return is_user_logged_in();
2287 1791 }
2288 1792
2289 - if ( (int) $role === 1 ) {
1793 + if ( $role == 1 ) {
2290 1794 $role = 'administrator';
2291 1795 }
2292 1796
2293 - return is_user_logged_in() ? current_user_can( $role ) : false;
1797 + if ( ! is_user_logged_in() ) {
1798 + return false;
1799 + }
1800 +
1801 + return current_user_can( $role );
2294 1802 }
2295 1803
2296 1804 /**
2297 - * @param array|string $needed_role
2298 - *
1805 + * @param string|array $needed_role
2299 1806 * @return bool
2300 1807 */
2301 1808 public static function user_has_permission( $needed_role ) {
2302 1809 if ( is_array( $needed_role ) ) {
@@ -2310,20 +1817,18 @@
2310 1817 }
2311 1818
2312 1819 $can = self::current_user_can( $needed_role );
2313 1820
2314 - if ( $can || in_array( $needed_role, array( '-1', 'loggedout' ), true ) ) {
1821 + if ( $can || in_array( $needed_role, array( '-1', 'loggedout' ) ) ) {
2315 1822 return $can;
2316 1823 }
2317 1824
2318 1825 $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' );
2319 -
2320 1826 foreach ( $roles as $role ) {
2321 1827 if ( current_user_can( $role ) ) {
2322 1828 return true;
2323 1829 }
2324 -
2325 - if ( $role === $needed_role ) {
1830 + if ( $role == $needed_role ) {
2326 1831 break;
2327 1832 }
2328 1833 }
2329 1834
@@ -2341,11 +1846,11 @@
2341 1846 if ( ! current_user_can( 'administrator' ) || current_user_can( 'frm_view_forms' ) ) {
2342 1847 return;
2343 1848 }
2344 1849
2345 - $user = new WP_User( get_current_user_id() );
1850 + $user_id = get_current_user_id();
1851 + $user = new WP_User( $user_id );
2346 1852 $frm_roles = self::frm_capabilities();
2347 -
2348 1853 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
2349 1854 $user->add_cap( $frm_role );
2350 1855 unset( $frm_role, $frm_role_description );
2351 1856 }
@@ -2354,47 +1859,35 @@
2354 1859 /**
2355 1860 * Make sure admins have permission to see the menu items
2356 1861 *
2357 1862 * @since 2.0.6
2358 - *
2359 - * @param string $cap
2360 - *
2361 - * @return void
2362 1863 */
2363 1864 public static function force_capability( $cap = 'frm_change_settings' ) {
2364 - if ( ! current_user_can( 'administrator' ) || current_user_can( $cap ) ) {
2365 - return;
1865 + if ( current_user_can( 'administrator' ) && ! current_user_can( $cap ) ) {
1866 + $role = get_role( 'administrator' );
1867 + $frm_roles = self::frm_capabilities();
1868 + foreach ( $frm_roles as $frm_role => $frm_role_description ) {
1869 + $role->add_cap( $frm_role );
1870 + }
2366 1871 }
2367 -
2368 - $role = get_role( 'administrator' );
2369 - $frm_roles = self::frm_capabilities();
2370 -
2371 - foreach ( $frm_roles as $frm_role => $frm_role_description ) {
2372 - $role->add_cap( $frm_role );
2373 - }
2374 1872 }
2375 1873
2376 1874 /**
2377 - * Check if the user has permission for action.
1875 + * Check if the user has permision for action.
2378 1876 * Return permission message and stop the action if no permission
2379 1877 *
2380 1878 * @since 2.0
2381 1879 *
2382 1880 * @param string $permission
2383 - * @param string $show_message
2384 1881 */
2385 1882 public static function permission_check( $permission, $show_message = 'show' ) {
2386 1883 $permission_error = self::permission_nonce_error( $permission );
2387 -
2388 - if ( $permission_error === false ) {
2389 - return;
1884 + if ( $permission_error !== false ) {
1885 + if ( 'hide' == $show_message ) {
1886 + $permission_error = '';
1887 + }
1888 + wp_die( esc_html( $permission_error ) );
2390 1889 }
2391 -
2392 - if ( 'hide' === $show_message ) {
2393 - $permission_error = '';
2394 - }
2395 -
2396 - wp_die( esc_html( $permission_error ) );
2397 1890 }
2398 1891
2399 1892 /**
2400 1893 * Check user permission and nonce
@@ -2401,27 +1894,24 @@
2401 1894 *
2402 1895 * @since 2.0
2403 1896 *
2404 1897 * @param string $permission
2405 - * @param string $nonce_name
2406 - * @param string $nonce
2407 1898 *
2408 1899 * @return false|string The permission message or false if allowed
2409 1900 */
2410 1901 public static function permission_nonce_error( $permission, $nonce_name = '', $nonce = '' ) {
2411 - if ( $permission && ! current_user_can( $permission ) && ! current_user_can( 'administrator' ) ) {
1902 + if ( ! empty( $permission ) && ! current_user_can( $permission ) && ! current_user_can( 'administrator' ) ) {
2412 1903 $frm_settings = self::get_settings();
1904 +
2413 1905 return $frm_settings->admin_permission;
2414 1906 }
2415 1907
2416 1908 $error = false;
2417 -
2418 - if ( ! $nonce_name ) {
1909 + if ( empty( $nonce_name ) ) {
2419 1910 return $error;
2420 1911 }
2421 1912
2422 - $nonce_value = $_REQUEST && isset( $_REQUEST[ $nonce_name ] ) ? sanitize_text_field( wp_unslash( $_REQUEST[ $nonce_name ] ) ) : '';
2423 -
1913 + $nonce_value = ( $_REQUEST && isset( $_REQUEST[ $nonce_name ] ) ) ? sanitize_text_field( wp_unslash( $_REQUEST[ $nonce_name ] ) ) : '';
2424 1914 if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $nonce_value, $nonce ) ) ) {
2425 1915 $frm_settings = self::get_settings();
2426 1916 $error = $frm_settings->admin_permission;
2427 1917 }
@@ -2428,14 +1918,8 @@
2428 1918
2429 1919 return $error;
2430 1920 }
2431 1921
2432 - /**
2433 - * @param array|string $values
2434 - * @param string $current
2435 - *
2436 - * @return void
2437 - */
2438 1922 public static function checked( $values, $current ) {
2439 1923 if ( self::check_selected( $values, $current ) ) {
2440 1924 echo ' checked="checked"';
2441 1925 }
@@ -2440,74 +1924,40 @@
2440 1924 echo ' checked="checked"';
2441 1925 }
2442 1926 }
2443 1927
2444 - /**
2445 - * @param array|string $values
2446 - * @param string|null $current
2447 - *
2448 - * @return bool
2449 - */
2450 1928 public static function check_selected( $values, $current ) {
2451 1929 $values = self::recursive_function_map( $values, 'trim' );
2452 1930 $values = self::recursive_function_map( $values, 'htmlspecialchars_decode' );
2453 - $current = is_null( $current ) ? '' : htmlspecialchars_decode( trim( $current ) );
1931 + $current = htmlspecialchars_decode( trim( $current ) );
2454 1932
2455 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict, Universal.Operators.StrictComparisons
2456 - return is_array( $values ) ? in_array( $current, $values ) : $values == $current;
1933 + return ( is_array( $values ) && in_array( $current, $values ) ) || ( ! is_array( $values ) && $values == $current );
2457 1934 }
2458 1935
2459 - /**
2460 - * @param array|string $value
2461 - * @param callable|string $function
2462 - *
2463 - * @return array|string
2464 - */
2465 1936 public static function recursive_function_map( $value, $function ) {
2466 1937 if ( is_array( $value ) ) {
2467 1938 $original_function = $function;
2468 - $function = count( $value ) ? explode( ', ', FrmDb::prepare_array_values( $value, $function ) ) : array( $function );
2469 -
2470 - if ( self::is_assoc( $value ) ) {
1939 + if ( count( $value ) ) {
1940 + $function = explode( ', ', FrmDb::prepare_array_values( $value, $function ) );
1941 + } else {
1942 + $function = array( $function );
1943 + }
1944 + if ( ! self::is_assoc( $value ) ) {
1945 + $value = array_map( array( 'FrmAppHelper', 'recursive_function_map' ), $value, $function );
1946 + } else {
2471 1947 foreach ( $value as $k => $v ) {
2472 1948 if ( ! is_array( $v ) ) {
2473 1949 $value[ $k ] = call_user_func( $original_function, $v );
2474 1950 }
2475 1951 }
2476 - } else {
2477 - $value = array_map( array( 'FrmAppHelper', 'recursive_function_map' ), $value, $function );
2478 1952 }
2479 1953 } else {
2480 - $value = self::maybe_update_value_if_null( $value, $function );
2481 1954 $value = call_user_func( $function, $value );
2482 - }//end if
2483 -
2484 - return $value;
2485 - }
2486 -
2487 - /**
2488 - * Updates value to empty string if it is null and being passed to a string function.
2489 - *
2490 - * @since 6.8.4
2491 - *
2492 - * @param mixed $value
2493 - * @param string $function
2494 - *
2495 - * @return mixed
2496 - */
2497 - private static function maybe_update_value_if_null( $value, $function ) {
2498 - if ( null === $value && in_array( $function, array( 'trim', 'strlen' ), true ) ) {
2499 - return '';
2500 1955 }
2501 1956
2502 1957 return $value;
2503 1958 }
2504 1959
2505 - /**
2506 - * @param array $array
2507 - *
2508 - * @return bool
2509 - */
2510 1960 public static function is_assoc( $array ) {
2511 1961 return (bool) count( array_filter( array_keys( $array ), 'is_string' ) );
2512 1962 }
2513 1963
@@ -2512,24 +1962,20 @@
2512 1962 }
2513 1963
2514 1964 /**
2515 1965 * Flatten a multi-dimensional array
2516 - *
2517 - * @param array $array
2518 - * @param string $keys
2519 - *
2520 - * @return array
2521 1966 */
2522 1967 public static function array_flatten( $array, $keys = 'keep' ) {
2523 1968 $return = array();
2524 -
2525 1969 foreach ( $array as $key => $value ) {
2526 1970 if ( is_array( $value ) ) {
2527 1971 $return = array_merge( $return, self::array_flatten( $value, $keys ) );
2528 - } elseif ( $keys === 'keep' ) {
2529 - $return[ $key ] = $value;
2530 1972 } else {
2531 - $return[] = $value;
1973 + if ( $keys === 'keep' ) {
1974 + $return[ $key ] = $value;
1975 + } else {
1976 + $return[] = $value;
1977 + }
2532 1978 }
2533 1979 }
2534 1980
2535 1981 return $return;
@@ -2534,43 +1980,16 @@
2534 1980
2535 1981 return $return;
2536 1982 }
2537 1983
2538 - /**
2539 - * Flatten an array before imploding it to avoid Array to string conversion warnings.
2540 - *
2541 - * @since 6.16.1
2542 - *
2543 - * @param string $sep
2544 - * @param array $array
2545 - *
2546 - * @return string
2547 - */
2548 - public static function safe_implode( $sep, $array ) {
2549 - $array = self::array_flatten( $array );
2550 - return implode( $sep, $array );
2551 - }
2552 -
2553 - /**
2554 - * @param string $text
2555 - * @param bool $is_rich_text
2556 - *
2557 - * @return string
2558 - */
2559 1984 public static function esc_textarea( $text, $is_rich_text = false ) {
2560 1985 $safe_text = str_replace( '&quot;', '"', $text );
2561 -
2562 1986 if ( ! $is_rich_text ) {
2563 1987 $safe_text = htmlspecialchars( $safe_text, ENT_NOQUOTES );
2564 1988 }
2565 -
2566 1989 $safe_text = str_replace( '&amp; ', '& ', $safe_text );
2567 1990
2568 - /**
2569 - * @param string $safe_text
2570 - * @param string $text
2571 - */
2572 - return (string) apply_filters( 'esc_textarea', $safe_text, $text );
1991 + return apply_filters( 'esc_textarea', $safe_text, $text );
2573 1992 }
2574 1993
2575 1994 /**
2576 1995 * Add auto paragraphs to text areas
@@ -2575,59 +1994,44 @@
2575 1994 /**
2576 1995 * Add auto paragraphs to text areas
2577 1996 *
2578 1997 * @since 2.0
2579 - *
2580 - * @param mixed $content
2581 - *
2582 - * @return mixed
2583 1998 */
2584 1999 public static function use_wpautop( $content ) {
2585 - if ( apply_filters( 'frm_use_wpautop', true ) && is_string( $content ) ) {
2586 - return wpautop( str_replace( '<br>', '<br />', $content ) );
2000 + if ( apply_filters( 'frm_use_wpautop', true ) && ! is_array( $content ) ) {
2001 + $content = wpautop( str_replace( '<br>', '<br />', $content ) );
2587 2002 }
2588 2003
2589 2004 return $content;
2590 2005 }
2591 2006
2592 - /**
2593 - * Replace quotes with their HTML entities.
2594 - *
2595 - * @param string $val
2596 - *
2597 - * @return string
2598 - */
2599 2007 public static function replace_quotes( $val ) {
2600 2008 // Replace double quotes.
2601 2009 $val = str_replace( array( '&#8220;', '&#8221;', '&#8243;' ), '"', $val );
2602 2010
2603 2011 // Replace single quotes.
2604 - return str_replace( array( '&#8216;', '&#8217;', '&#8242;', '&prime;', '&rsquo;', '&lsquo;' ), "'", $val );
2012 + $val = str_replace( array( '&#8216;', '&#8217;', '&#8242;', '&prime;', '&rsquo;', '&lsquo;' ), "'", $val );
2013 +
2014 + return $val;
2605 2015 }
2606 2016
2607 2017 /**
2608 - * @param string $handle
2609 - * @param int|string $default
2610 - *
2611 - * @return int|string
2018 + * @param string $handle
2612 2019 */
2613 2020 public static function script_version( $handle, $default = 0 ) {
2614 2021 global $wp_scripts;
2615 -
2616 2022 if ( ! $wp_scripts ) {
2617 2023 return $default;
2618 2024 }
2619 2025
2620 2026 $ver = $default;
2621 -
2622 2027 if ( ! isset( $wp_scripts->registered[ $handle ] ) ) {
2623 2028 return $ver;
2624 2029 }
2625 2030
2626 2031 $query = $wp_scripts->registered[ $handle ];
2627 -
2628 2032 if ( is_object( $query ) && ! empty( $query->ver ) ) {
2629 - return $query->ver;
2033 + $ver = $query->ver;
2630 2034 }
2631 2035
2632 2036 return $ver;
2633 2037 }
@@ -2636,23 +2040,17 @@
2636 2040 * @since 5.0.13 added $echo param.
2637 2041 *
2638 2042 * @param string $url
2639 2043 * @param bool $echo
2640 - *
2641 - * @return string|null
2044 + * @return string|void
2642 2045 */
2643 2046 public static function js_redirect( $url, $echo = false ) {
2644 - $callback = function () use ( $url ) {
2047 + $callback = function() use ( $url ) {
2645 2048 echo '<script type="text/javascript">window.location="' . esc_url_raw( $url ) . '"</script>';
2646 2049 };
2647 2050 return self::clip( $callback, $echo );
2648 2051 }
2649 2052
2650 - /**
2651 - * @param int|string $user_id
2652 - *
2653 - * @return int|string
2654 - */
2655 2053 public static function get_user_id_param( $user_id ) {
2656 2054 if ( ! $user_id || is_numeric( $user_id ) ) {
2657 2055 return $user_id;
2658 2056 }
@@ -2657,13 +2055,16 @@
2657 2055 return $user_id;
2658 2056 }
2659 2057
2660 2058 $user_id = sanitize_text_field( $user_id );
2661 -
2662 2059 if ( $user_id === 'current' ) {
2663 2060 $user_id = get_current_user_id();
2664 2061 } else {
2665 - $user = is_email( $user_id ) ? get_user_by( 'email', $user_id ) : get_user_by( 'login', $user_id );
2062 + if ( is_email( $user_id ) ) {
2063 + $user = get_user_by( 'email', $user_id );
2064 + } else {
2065 + $user = get_user_by( 'login', $user_id );
2066 + }
2666 2067
2667 2068 if ( $user ) {
2668 2069 $user_id = $user->ID;
2669 2070 }
@@ -2672,14 +2073,8 @@
2672 2073
2673 2074 return $user_id;
2674 2075 }
2675 2076
2676 - /**
2677 - * @param string $filename
2678 - * @param array $atts
2679 - *
2680 - * @return false|string
2681 - */
2682 2077 public static function get_file_contents( $filename, $atts = array() ) {
2683 2078 if ( ! is_file( $filename ) ) {
2684 2079 return false;
2685 2080 }
@@ -2685,10 +2080,13 @@
2685 2080 }
2686 2081
2687 2082 extract( $atts ); // phpcs:ignore WordPress.PHP.DontExtract
2688 2083 ob_start();
2689 - include $filename;
2690 - return ob_get_clean();
2084 + include( $filename );
2085 + $contents = ob_get_contents();
2086 + ob_end_clean();
2087 +
2088 + return $contents;
2691 2089 }
2692 2090
2693 2091 /**
2694 2092 * @param string $name
@@ -2698,9 +2096,8 @@
2698 2096 * @param int $num_chars
2699 2097 */
2700 2098 public static function get_unique_key( $name, $table_name, $column, $id = 0, $num_chars = 5 ) {
2701 2099 $key = '';
2702 -
2703 2100 if ( $name ) {
2704 2101 $key = sanitize_key( $name );
2705 2102 $key = self::maybe_clear_long_key( $key, $column );
2706 2103 }
@@ -2720,31 +2117,31 @@
2720 2117 $column
2721 2118 );
2722 2119
2723 2120 // Create a unique field id if it has already been used.
2724 - if ( ! in_array( $key, $similar_keys, true ) ) {
2725 - return $key;
2726 - }
2121 + if ( in_array( $key, $similar_keys, true ) ) {
2122 + $key = self::maybe_truncate_key_before_appending( $column, $key );
2727 2123
2728 - $key = self::maybe_truncate_key_before_appending( $column, $key );
2124 + /**
2125 + * Allow for a custom separator between the attempted key and the generated suffix.
2126 + *
2127 + * @since 5.2.03
2128 + *
2129 + * @param string $separator. Default empty.
2130 + * @param string $key the key without the added suffix.
2131 + */
2132 + $separator = apply_filters( 'frm_unique_' . $column . '_separator', '', $key );
2729 2133
2730 - /**
2731 - * Allow for a custom separator between the attempted key and the generated suffix.
2732 - *
2733 - * @since 5.2.03
2734 - *
2735 - * @param string $separator. Default empty.
2736 - * @param string $key the key without the added suffix.
2737 - */
2738 - $separator = apply_filters( 'frm_unique_' . $column . '_separator', '', $key );
2134 + $suffix = 2;
2135 + do {
2136 + $key_check = $key . $separator . $suffix;
2137 + ++$suffix;
2138 + } while ( in_array( $key_check, $similar_keys, true ) );
2739 2139
2740 - $suffix = 2;
2741 - do {
2742 - $key_check = $key . $separator . $suffix;
2743 - ++$suffix;
2744 - } while ( in_array( $key_check, $similar_keys, true ) );
2140 + $key = $key_check;
2141 + }//end if
2745 2142
2746 - return $key_check;
2143 + return $key;
2747 2144 }
2748 2145
2749 2146 /**
2750 2147 * Avoid trying to append to a really long key,
@@ -2751,26 +2148,20 @@
2751 2148 * The database limit is 100 for form and field keys so we want to avoid getting too close.
2752 2149 *
2753 2150 * @param string $column
2754 2151 * @param string $key
2755 - *
2756 2152 * @return string
2757 2153 */
2758 2154 private static function maybe_truncate_key_before_appending( $column, $key ) {
2759 - if ( ! in_array( $column, array( 'form_key', 'field_key' ), true ) ) {
2760 - return $key;
2761 - }
2762 -
2763 - $max_key_length_before_truncating = 60;
2764 -
2765 - if ( strlen( $key ) > $max_key_length_before_truncating ) {
2766 - $key = substr( $key, 0, $max_key_length_before_truncating );
2767 -
2768 - if ( is_numeric( $key ) ) {
2769 - $key .= 'a';
2155 + if ( in_array( $column, array( 'form_key', 'field_key' ), true ) ) {
2156 + $max_key_length_before_truncating = 60;
2157 + if ( strlen( $key ) > $max_key_length_before_truncating ) {
2158 + $key = substr( $key, 0, $max_key_length_before_truncating );
2159 + if ( is_numeric( $key ) ) {
2160 + $key .= 'a';
2161 + }
2770 2162 }
2771 2163 }
2772 -
2773 2164 return $key;
2774 2165 }
2775 2166
2776 2167 /**
@@ -2777,36 +2168,31 @@
2777 2168 * Possibly reset a key to avoid conflicts with column size limits.
2778 2169 *
2779 2170 * @param string $key
2780 2171 * @param string $column
2781 - *
2782 2172 * @return string either the original key value, or an empty string if the key was too long.
2783 2173 */
2784 2174 private static function maybe_clear_long_key( $key, $column ) {
2785 2175 if ( 'field_key' === $column && strlen( $key ) >= 70 ) {
2786 - return '';
2176 + $key = '';
2787 2177 }
2788 2178 return $key;
2789 2179 }
2790 2180
2791 2181 /**
2792 - * @since 6.21 This is changed from `private` to `public`.
2793 - *
2794 2182 * @param int $num_chars
2795 - *
2796 2183 * @return string
2797 2184 */
2798 - public static function generate_new_key( $num_chars ) {
2799 - $max_slug_value = 36 ** $num_chars;
2185 + private static function generate_new_key( $num_chars ) {
2186 + $max_slug_value = pow( 36, $num_chars );
2800 2187
2801 2188 // We want to have at least 2 characters in the slug.
2802 2189 $min_slug_value = 37;
2803 - return base_convert( random_int( $min_slug_value, $max_slug_value ), 10, 36 );
2190 + return base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
2804 2191 }
2805 2192
2806 2193 /**
2807 2194 * @param string $key
2808 - *
2809 2195 * @return string
2810 2196 */
2811 2197 private static function prevent_numeric_and_reserved_keys( $key ) {
2812 2198 if ( is_numeric( $key ) ) {
@@ -2820,14 +2206,12 @@
2820 2206 'editlink',
2821 2207 'siteurl',
2822 2208 'evenodd',
2823 2209 );
2824 -
2825 2210 if ( in_array( $key, $not_allowed, true ) ) {
2826 2211 $key .= 'a';
2827 2212 }
2828 2213 }
2829 -
2830 2214 return $key;
2831 2215 }
2832 2216
2833 2217 /**
@@ -2839,9 +2223,9 @@
2839 2223 * @param bool $default
2840 2224 * @param array $post_values
2841 2225 * @param array $args
2842 2226 *
2843 - * @return array|bool
2227 + * @return bool|array
2844 2228 */
2845 2229 public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) {
2846 2230 if ( ! $record ) {
2847 2231 return false;
@@ -2846,9 +2230,9 @@
2846 2230 if ( ! $record ) {
2847 2231 return false;
2848 2232 }
2849 2233
2850 - if ( ! $post_values ) {
2234 + if ( empty( $post_values ) ) {
2851 2235 $post_values = wp_unslash( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
2852 2236 }
2853 2237
2854 2238 $values = array(
@@ -2856,9 +2240,9 @@
2856 2240 'fields' => array(),
2857 2241 );
2858 2242
2859 2243 foreach ( array( 'name', 'description' ) as $var ) {
2860 - $default_val = $record->{$var} ?? '';
2244 + $default_val = isset( $record->{$var} ) ? $record->{$var} : '';
2861 2245 $values[ $var ] = self::get_param( $var, $default_val, 'get', 'wp_kses_post' );
2862 2246 unset( $var, $default_val );
2863 2247 }
2864 2248
@@ -2876,67 +2260,48 @@
2876 2260
2877 2261 return $values;
2878 2262 }
2879 2263
2880 - /**
2881 - * @param array|string $fields
2882 - * @param object $record
2883 - * @param array $values
2884 - * @param array $args
2885 - *
2886 - * @return void
2887 - */
2888 2264 private static function prepare_field_arrays( $fields, $record, array &$values, $args ) {
2889 - if ( ! $fields ) {
2890 - return;
2891 - }
2892 -
2893 - foreach ( (array) $fields as $field ) {
2894 - if ( ! self::is_admin_page() ) {
2895 - // Don't prep default values on the form settings page.
2896 - $field->default_value = apply_filters( 'frm_get_default_value', $field->default_value, $field, true );
2265 + if ( ! empty( $fields ) ) {
2266 + foreach ( (array) $fields as $field ) {
2267 + if ( ! self::is_admin_page() ) {
2268 + // Don't prep default values on the form settings page.
2269 + $field->default_value = apply_filters( 'frm_get_default_value', $field->default_value, $field, true );
2270 + }
2271 + $args['parent_form_id'] = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id;
2272 + self::fill_field_defaults( $field, $record, $values, $args );
2897 2273 }
2898 -
2899 - $args['parent_form_id'] = $args['parent_form_id'] ?? $field->form_id;
2900 - self::fill_field_defaults( $field, $record, $values, $args );
2901 2274 }
2902 2275 }
2903 2276
2904 - /**
2905 - * @param object $field
2906 - * @param object $record
2907 - * @param array $values
2908 - * @param array $args
2909 - *
2910 - * @return void
2911 - */
2912 2277 private static function fill_field_defaults( $field, $record, array &$values, $args ) {
2913 2278 $post_values = $args['post_values'];
2914 2279
2915 2280 if ( $args['default'] ) {
2916 2281 $meta_value = $field->default_value;
2917 - } elseif ( $record->post_id && self::pro_is_installed() && ! empty( $field->field_options['post_field'] ) ) {
2918 - if ( ! isset( $field->field_options['custom_field'] ) ) {
2919 - $field->field_options['custom_field'] = '';
2282 + } else {
2283 + if ( $record->post_id && self::pro_is_installed() && isset( $field->field_options['post_field'] ) && $field->field_options['post_field'] ) {
2284 + if ( ! isset( $field->field_options['custom_field'] ) ) {
2285 + $field->field_options['custom_field'] = '';
2286 + }
2287 + $meta_value = FrmProEntryMetaHelper::get_post_value(
2288 + $record->post_id,
2289 + $field->field_options['post_field'],
2290 + $field->field_options['custom_field'],
2291 + array(
2292 + 'truncate' => false,
2293 + 'type' => $field->type,
2294 + 'form_id' => $field->form_id,
2295 + 'field' => $field,
2296 + )
2297 + );
2298 + } else {
2299 + $meta_value = FrmEntryMeta::get_meta_value( $record, $field->id );
2920 2300 }
2921 -
2922 - $meta_value = FrmProEntryMetaHelper::get_post_value(
2923 - $record->post_id,
2924 - $field->field_options['post_field'],
2925 - $field->field_options['custom_field'],
2926 - array(
2927 - 'truncate' => false,
2928 - 'type' => $field->type,
2929 - 'form_id' => $field->form_id,
2930 - 'field' => $field,
2931 - )
2932 - );
2933 - } else {
2934 - $meta_value = FrmEntryMeta::get_meta_value( $record, $field->id );
2935 2301 }//end if
2936 2302
2937 - $field_type = $post_values['field_options'][ 'type_' . $field->id ] ?? $field->type;
2938 -
2303 + $field_type = isset( $post_values['field_options'][ 'type_' . $field->id ] ) ? $post_values['field_options'][ 'type_' . $field->id ] : $field->type;
2939 2304 if ( isset( $post_values['item_meta'][ $field->id ] ) ) {
2940 2305 $new_value = $post_values['item_meta'][ $field->id ];
2941 2306 self::unserialize_or_decode( $new_value );
2942 2307 } else {
@@ -2951,9 +2316,9 @@
2951 2316 $args['field_type'] = $field_type;
2952 2317
2953 2318 FrmFieldsHelper::prepare_edit_front_field( $field_array, $field, $values['id'], $args );
2954 2319
2955 - if ( empty( $field_array['unique'] ) ) {
2320 + if ( ! isset( $field_array['unique'] ) || ! $field_array['unique'] ) {
2956 2321 $field_array['unique_msg'] = '';
2957 2322 }
2958 2323
2959 2324 $field_array = array_merge( (array) $field->field_options, $field_array );
@@ -2988,9 +2353,9 @@
2988 2353 * @param array $post_values
2989 2354 * @param array $values
2990 2355 */
2991 2356 private static function fill_form_opts( $record, $table, $post_values, array &$values ) {
2992 - if ( $table === 'entries' ) {
2357 + if ( $table == 'entries' ) {
2993 2358 $form = $record->form_id;
2994 2359 FrmForm::maybe_get_form( $form );
2995 2360 } else {
2996 2361 $form = $record;
@@ -3020,21 +2385,15 @@
3020 2385 }
3021 2386
3022 2387 /**
3023 2388 * Set to POST value or default
3024 - *
3025 - * @param array $post_values
3026 - * @param array $values
3027 - *
3028 - * @return void
3029 2389 */
3030 2390 private static function fill_form_defaults( $post_values, array &$values ) {
3031 2391 $form_defaults = FrmFormsHelper::get_default_opts();
3032 2392
3033 2393 foreach ( $form_defaults as $opt => $default ) {
3034 - // phpcs:ignore Universal.Operators.StrictComparisons
3035 2394 if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
3036 - $values[ $opt ] = $post_values['options'][ $opt ] ?? $default;
2395 + $values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default;
3037 2396 }
3038 2397
3039 2398 unset( $opt, $default );
3040 2399 }
@@ -3044,9 +2403,9 @@
3044 2403 }
3045 2404
3046 2405 foreach ( array( 'before', 'after', 'submit' ) as $h ) {
3047 2406 if ( ! isset( $values[ $h . '_html' ] ) ) {
3048 - $values[ $h . '_html' ] = $post_values['options'][ $h . '_html' ] ?? FrmFormsHelper::get_default_html( $h );
2407 + $values[ $h . '_html' ] = ( isset( $post_values['options'][ $h . '_html' ] ) ? $post_values['options'][ $h . '_html' ] : FrmFormsHelper::get_default_html( $h ) );
3049 2408 }
3050 2409 unset( $h );
3051 2410 }
3052 2411 }
@@ -3055,70 +2414,46 @@
3055 2414 * @since 2.2.10
3056 2415 *
3057 2416 * @param array $post_values
3058 2417 *
3059 - * @return bool|int
2418 + * @return boolean|int
3060 2419 */
3061 2420 public static function custom_style_value( $post_values ) {
3062 - if ( $post_values && isset( $post_values['options']['custom_style'] ) ) {
3063 - return absint( $post_values['options']['custom_style'] );
2421 + if ( ! empty( $post_values ) && isset( $post_values['options']['custom_style'] ) ) {
2422 + $custom_style = absint( $post_values['options']['custom_style'] );
2423 + } else {
2424 + $frm_settings = self::get_settings();
2425 + $custom_style = ( $frm_settings->load_style != 'none' );
3064 2426 }
3065 2427
3066 - $frm_settings = self::get_settings();
3067 - return $frm_settings->load_style !== 'none';
2428 + return $custom_style;
3068 2429 }
3069 2430
3070 - /**
3071 - * Truncate a string.
3072 - *
3073 - * Note: By default, this function will allow for a few additional characters more than $length.
3074 - * If a string has no spaces, it allows up to 50 additional characters. To force a true length limit,
3075 - * use $force_length_limit = true.
3076 - *
3077 - * @param mixed $original_string
3078 - * @param int|string $length
3079 - * @param int $minword
3080 - * @param string $continue
3081 - * @param bool $force_length_limit Force the final string to never exceed the length limit.
3082 - *
3083 - * @return string
3084 - */
3085 - public static function truncate( $original_string, $length, $minword = 3, $continue = '...', $force_length_limit = false ) {
3086 - if ( ! is_string( $original_string ) && ! is_int( $original_string ) ) {
2431 + public static function truncate( $str, $length, $minword = 3, $continue = '...' ) {
2432 + if ( is_array( $str ) ) {
3087 2433 return '';
3088 2434 }
3089 2435
3090 - $length = (int) $length;
2436 + $length = (int) $length;
2437 + $str = wp_strip_all_tags( $str );
2438 + $original_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $str ) );
3091 2439
3092 - if ( $length === 0 ) {
2440 + if ( $length == 0 ) {
3093 2441 return '';
3094 - }
3095 -
3096 - $str = wp_strip_all_tags( (string) $original_string );
3097 - $original_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $str ) );
3098 -
3099 - if ( $length <= 10 ) {
2442 + } elseif ( $length <= 10 ) {
3100 2443 $sub = self::mb_function( array( 'mb_substr', 'substr' ), array( $str, 0, $length ) );
3101 2444
3102 - if ( $force_length_limit ) {
3103 - return $sub;
3104 - }
2445 + return $sub . ( ( $length < $original_len ) ? $continue : '' );
2446 + }
3105 2447
3106 - return $sub . ( $length < $original_len ? $continue : '' );
3107 - }
2448 + $sub = '';
2449 + $len = 0;
3108 2450
3109 - $sub = '';
3110 - $len = 0;
3111 2451 $words = self::mb_function( array( 'mb_split', 'explode' ), array( ' ', $str ) );
3112 2452
3113 - if ( ! is_array( $words ) ) {
3114 - return $original_string;
3115 - }
3116 -
3117 2453 foreach ( $words as $word ) {
3118 - $part = ( $sub !== '' ? ' ' : '' ) . $word;
2454 + $part = ( ( $sub != '' ) ? ' ' : '' ) . $word;
3119 2455 $total_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub . $part ) );
3120 -
3121 2456 if ( $total_len > $length && substr_count( $sub, ' ' ) ) {
3122 2457 break;
3123 2458 }
3124 2459
@@ -3131,22 +2466,11 @@
3131 2466
3132 2467 unset( $total_len, $word );
3133 2468 }
3134 2469
3135 - $sub = self::maybe_force_truncate_on_string_with_no_spaces( $sub, $length, $force_length_limit );
2470 + $sub = self::maybe_force_truncate_on_string_with_no_spaces( $sub, $length );
3136 2471
3137 - if ( $force_length_limit ) {
3138 - // Ensure the final string doesn't exceed the length limit.
3139 - $final_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub ) );
3140 -
3141 - if ( $final_len > $length ) {
3142 - return self::mb_function( array( 'mb_substr', 'substr' ), array( $sub, 0, $length ) );
3143 - }
3144 -
3145 - return $sub;
3146 - }
3147 -
3148 - return $sub . ( $len < $original_len ? $continue : '' );
2472 + return $sub . ( ( $len < $original_len ) ? $continue : '' );
3149 2473 }
3150 2474
3151 2475 /**
3152 2476 * If the string is still too long because there may not have been any spaces, force truncate.
@@ -3152,51 +2476,30 @@
3152 2476 * If the string is still too long because there may not have been any spaces, force truncate.
3153 2477 *
3154 2478 * @since 6.5.4
3155 2479 *
3156 - * @param string $sub Current substring.
3157 - * @param int $length The length limit.
3158 - * @param bool $force_length_limit Force the string to not exceed the length limit.
3159 - *
2480 + * @param string $sub Current substring.
2481 + * @param int $length The length limit.
3160 2482 * @return string
3161 2483 */
3162 - private static function maybe_force_truncate_on_string_with_no_spaces( $sub, $length, $force_length_limit = false ) {
3163 - if ( ! $force_length_limit ) {
3164 - if ( strlen( $sub ) < $length + 50 ) {
3165 - // If the string isn't way over the limit, leave it.
3166 - return $sub;
3167 - }
3168 -
3169 - $first_space = strpos( $sub, ' ', $length );
3170 -
3171 - if ( false !== $first_space ) {
3172 - // Ignore anything with spaces.
3173 - return $sub;
3174 - }
3175 -
3176 - return substr( $sub, 0, $length + 10 );
2484 + private static function maybe_force_truncate_on_string_with_no_spaces( $sub, $length ) {
2485 + if ( strlen( $sub ) < $length + 50 ) {
2486 + // If the string isn't way over the limit, leave it.
2487 + return $sub;
3177 2488 }
3178 2489
3179 - // When force_length_limit is true, ensure the string doesn't exceed the length.
3180 - $final_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub ) );
3181 -
3182 - if ( $final_len > $length ) {
3183 - return self::mb_function( array( 'mb_substr', 'substr' ), array( $sub, 0, $length ) );
2490 + $first_space = strpos( $sub, ' ', $length );
2491 + if ( false !== $first_space ) {
2492 + // Ignore anything with spaces.
2493 + return $sub;
3184 2494 }
3185 2495
3186 - return $sub;
2496 + return substr( $sub, 0, $length + 10 );
3187 2497 }
3188 2498
3189 - /**
3190 - * @param array $function_names
3191 - * @param array $args
3192 - *
3193 - * @return mixed
3194 - */
3195 2499 public static function mb_function( $function_names, $args ) {
3196 2500 $mb_function_name = $function_names[0];
3197 2501 $function_name = $function_names[1];
3198 -
3199 2502 if ( function_exists( $mb_function_name ) ) {
3200 2503 $function_name = $mb_function_name;
3201 2504 }
3202 2505
@@ -3202,21 +2505,14 @@
3202 2505
3203 2506 return call_user_func_array( $function_name, $args );
3204 2507 }
3205 2508
3206 - /**
3207 - * @param string $date
3208 - * @param string $date_format
3209 - * @param string $time_format
3210 - *
3211 - * @return string
3212 - */
3213 2509 public static function get_formatted_time( $date, $date_format = '', $time_format = '' ) {
3214 - if ( ! $date ) {
2510 + if ( empty( $date ) ) {
3215 2511 return $date;
3216 2512 }
3217 2513
3218 - if ( ! $date_format ) {
2514 + if ( empty( $date_format ) ) {
3219 2515 $date_format = get_option( 'date_format' );
3220 2516 }
3221 2517
3222 2518 if ( preg_match( '/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date ) && self::pro_is_installed() ) {
@@ -3224,10 +2520,10 @@
3224 2520 $date = FrmProAppHelper::convert_date( $date, $frmpro_settings->date_format, 'Y-m-d' );
3225 2521 }
3226 2522
3227 2523 $formatted = self::get_localized_date( $date_format, $date );
3228 - $do_time = gmdate( 'H:i:s', strtotime( $date ) ) !== '00:00:00';
3229 2524
2525 + $do_time = ( gmdate( 'H:i:s', strtotime( $date ) ) != '00:00:00' );
3230 2526 if ( $do_time ) {
3231 2527 $formatted .= self::add_time_to_date( $time_format, $date );
3232 2528 }
3233 2529
@@ -3233,38 +2529,28 @@
3233 2529
3234 2530 return $formatted;
3235 2531 }
3236 2532
3237 - /**
3238 - * @param string $time_format
3239 - * @param string $date
3240 - *
3241 - * @return string
3242 - */
3243 2533 private static function add_time_to_date( $time_format, $date ) {
3244 - if ( ! $time_format ) {
2534 + if ( empty( $time_format ) ) {
3245 2535 $time_format = get_option( 'time_format' );
3246 2536 }
3247 2537
3248 2538 $trimmed_format = trim( $time_format );
3249 -
3250 - if ( $time_format && $trimmed_format ) {
3251 - return ' ' . __( 'at', 'formidable' ) . ' ' . self::get_localized_date( $time_format, $date );
2539 + $time = '';
2540 + if ( $time_format && ! empty( $trimmed_format ) ) {
2541 + $time = ' ' . __( 'at', 'formidable' ) . ' ' . self::get_localized_date( $time_format, $date );
3252 2542 }
3253 2543
3254 - return '';
2544 + return $time;
3255 2545 }
3256 2546
3257 2547 /**
3258 2548 * @since 2.0.8
3259 - *
3260 - * @param string $date_format
3261 - * @param string $date
3262 - *
3263 - * @return string
3264 2549 */
3265 2550 public static function get_localized_date( $date_format, $date ) {
3266 2551 $date = get_date_from_gmt( $date );
2552 +
3267 2553 return date_i18n( $date_format, strtotime( $date ) );
3268 2554 }
3269 2555
3270 2556 /**
@@ -3269,16 +2555,19 @@
3269 2555
3270 2556 /**
3271 2557 * Gets the time ago in words.
3272 2558 *
3273 - * @param int $from In seconds.
3274 - * @param int|string $to In seconds.
3275 - * @param int|string $levels Number of time units to include or a specific unit.
2559 + * @param int $from In seconds.
2560 + * @param int|string $to In seconds.
3276 2561 *
3277 - * @return string Time ago.
2562 + * @return string $time_ago
3278 2563 */
3279 2564 public static function human_time_diff( $from, $to = '', $levels = 1 ) {
3280 - $now = ! $to && 0 !== $to ? new DateTime() : new DateTime( '@' . $to );
2565 + if ( empty( $to ) && 0 !== $to ) {
2566 + $now = new DateTime();
2567 + } else {
2568 + $now = new DateTime( '@' . $to );
2569 + }
3281 2570 $ago = new DateTime( '@' . $from );
3282 2571
3283 2572 // Get the time difference
3284 2573 $diff_object = $now->diff( $ago );
@@ -3284,9 +2573,9 @@
3284 2573 $diff_object = $now->diff( $ago );
3285 2574 $diff = get_object_vars( $diff_object );
3286 2575
3287 2576 // Add week amount and update day amount
3288 - $diff['w'] = floor( $diff['d'] / 7 );
2577 + $diff['w'] = floor( $diff['d'] / 7 );
3289 2578 $diff['d'] -= $diff['w'] * 7;
3290 2579
3291 2580 $time_strings = self::get_time_strings();
3292 2581
@@ -3292,11 +2581,10 @@
3292 2581
3293 2582 if ( ! is_numeric( $levels ) ) {
3294 2583 // Show time in specified unit.
3295 2584 $levels = self::get_unit( $levels );
3296 -
3297 2585 if ( isset( $time_strings[ $levels ] ) ) {
3298 - $diff = array(
2586 + $diff = array(
3299 2587 $levels => self::time_format( $levels, $diff ),
3300 2588 );
3301 2589 $time_strings = array(
3302 2590 $levels => $time_strings[ $levels ],
@@ -3301,14 +2589,13 @@
3301 2589 $time_strings = array(
3302 2590 $levels => $time_strings[ $levels ],
3303 2591 );
3304 2592 }
3305 -
3306 2593 $levels = 1;
3307 2594 }
3308 2595
3309 2596 foreach ( $time_strings as $k => $v ) {
3310 - if ( ! empty( $diff[ $k ] ) ) {
2597 + if ( isset( $diff[ $k ] ) && $diff[ $k ] ) {
3311 2598 $time_strings[ $k ] = $diff[ $k ] . ' ' . ( $diff[ $k ] > 1 ? $v[1] : $v[0] );
3312 2599 } elseif ( isset( $diff[ $k ] ) && count( $time_strings ) === 1 ) {
3313 2600 // Account for 0.
3314 2601 $time_strings[ $k ] = $diff[ $k ] . ' ' . $v[1];
@@ -3316,21 +2603,17 @@
3316 2603 unset( $time_strings[ $k ] );
3317 2604 }
3318 2605 }
3319 2606
3320 - $levels_deep = apply_filters( 'frm_time_ago_levels', $levels, compact( 'time_strings', 'from', 'to' ) );
3321 - $time_strings = array_slice( $time_strings, 0, absint( $levels_deep ) );
2607 + $levels_deep = apply_filters( 'frm_time_ago_levels', $levels, compact( 'time_strings', 'from', 'to' ) );
2608 + $time_strings = array_slice( $time_strings, 0, absint( $levels_deep ) );
2609 + $time_ago_string = implode( ' ', $time_strings );
3322 2610
3323 - return implode( ' ', $time_strings );
2611 + return $time_ago_string;
3324 2612 }
3325 2613
3326 2614 /**
3327 2615 * @since 4.05.01
3328 - *
3329 - * @param string $unit
3330 - * @param array $diff
3331 - *
3332 - * @return int
3333 2616 */
3334 2617 private static function time_format( $unit, $diff ) {
3335 2618 $return = array(
3336 2619 'y' => 'y',
@@ -3335,14 +2618,14 @@
3335 2618 $return = array(
3336 2619 'y' => 'y',
3337 2620 'd' => 'days',
3338 2621 );
3339 -
3340 2622 if ( isset( $return[ $unit ] ) ) {
3341 2623 return $diff[ $return[ $unit ] ];
3342 2624 }
3343 2625
3344 2626 $total = $diff['days'] * self::convert_time( 'd', $unit );
2627 +
3345 2628 $times = array( 'h', 'i', 's' );
3346 2629
3347 2630 foreach ( $times as $time ) {
3348 2631 if ( ! isset( $diff[ $time ] ) ) {
@@ -3356,13 +2639,8 @@
3356 2639 }
3357 2640
3358 2641 /**
3359 2642 * @since 4.05.01
3360 - *
3361 - * @param string $from
3362 - * @param string $to
3363 - *
3364 - * @return int
3365 2643 */
3366 2644 private static function convert_time( $from, $to ) {
3367 2645 $convert = array(
3368 2646 's' => 1,
@@ -3378,35 +2656,28 @@
3378 2656 }
3379 2657
3380 2658 /**
3381 2659 * @since 4.05.01
3382 - *
3383 - * @param string $unit
3384 - *
3385 - * @return int|string
3386 2660 */
3387 2661 private static function get_unit( $unit ) {
3388 2662 $units = self::get_time_strings();
3389 -
3390 2663 if ( isset( $units[ $unit ] ) || is_numeric( $unit ) ) {
3391 2664 return $unit;
3392 2665 }
3393 2666
3394 2667 foreach ( $units as $u => $strings ) {
3395 - if ( in_array( $unit, $strings, true ) ) {
2668 + if ( in_array( $unit, $strings ) ) {
3396 2669 return $u;
3397 2670 }
3398 2671 }
3399 -
3400 2672 return 1;
3401 2673 }
3402 2674
3403 2675 /**
3404 2676 * Get the translatable time strings. The untranslated version is a failsafe
3405 - * in case languages are changing for the unit set in the shortcode.
2677 + * in case langauges are changing for the unit set in the shortcode.
3406 2678 *
3407 2679 * @since 2.0.20
3408 - *
3409 2680 * @return array
3410 2681 */
3411 2682 private static function get_time_strings() {
3412 2683 return array(
@@ -3450,48 +2721,41 @@
3450 2721
3451 2722 // Pagination Methods.
3452 2723
3453 2724 /**
3454 - * @param int $r_count
3455 - * @param int $current_p
3456 - * @param int $p_size
3457 - *
2725 + * @param integer $r_count
2726 + * @param integer $current_p
2727 + * @param integer $p_size
3458 2728 * @return int
3459 2729 */
3460 2730 public static function get_last_record_num( $r_count, $current_p, $p_size ) {
3461 - return $r_count < $current_p * $p_size ? $r_count : $current_p * $p_size;
2731 + return ( ( $r_count < ( $current_p * $p_size ) ) ? $r_count : ( $current_p * $p_size ) );
3462 2732 }
3463 2733
3464 2734 /**
3465 - * @param int $r_count
3466 - * @param int $current_p
3467 - * @param int $p_size
3468 - *
2735 + * @param integer $r_count
2736 + * @param integer $current_p
2737 + * @param integer $p_size
3469 2738 * @return int
3470 2739 */
3471 2740 public static function get_first_record_num( $r_count, $current_p, $p_size ) {
3472 - // phpcs:ignore Universal.Operators.StrictComparisons
3473 2741 if ( $current_p == 1 ) {
3474 2742 return 1;
2743 + } else {
2744 + return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 );
3475 2745 }
3476 - return self::get_last_record_num( $r_count, $current_p - 1, $p_size ) + 1;
3477 2746 }
3478 2747
3479 2748 /**
3480 - * @param array $json_vars
3481 - *
3482 2749 * @return array
3483 2750 */
3484 2751 public static function json_to_array( $json_vars ) {
3485 2752 $vars = array();
3486 -
3487 2753 foreach ( $json_vars as $jv ) {
3488 2754 $jv_name = explode( '[', $jv['name'] );
3489 2755 $last = count( $jv_name ) - 1;
3490 -
3491 2756 foreach ( $jv_name as $p => $n ) {
3492 2757 $name = trim( $n, ']' );
3493 -
3494 2758 if ( ! isset( $l1 ) ) {
3495 2759 $l1 = $name;
3496 2760 }
3497 2761
@@ -3502,9 +2766,9 @@
3502 2766 if ( ! isset( $l3 ) ) {
3503 2767 $l3 = $name;
3504 2768 }
3505 2769
3506 - $this_val = $p === $last ? $jv['value'] : array();
2770 + $this_val = ( $p == $last ) ? $jv['value'] : array();
3507 2771
3508 2772 switch ( $p ) {
3509 2773 case 0:
3510 2774 $l1 = $name;
@@ -3537,15 +2801,10 @@
3537 2801
3538 2802 /**
3539 2803 * @param string $name
3540 2804 * @param string $l1
3541 - * @param mixed $val
3542 - * @param array $vars
3543 - *
3544 - * @return void
3545 2805 */
3546 2806 public static function add_value_to_array( $name, $l1, $val, &$vars ) {
3547 - // phpcs:ignore Universal.Operators.StrictComparisons
3548 2807 if ( $name == '' ) {
3549 2808 $vars[] = $val;
3550 2809 } elseif ( ! isset( $vars[ $l1 ] ) ) {
3551 2810 $vars[ $l1 ] = $val;
@@ -3551,26 +2810,19 @@
3551 2810 $vars[ $l1 ] = $val;
3552 2811 }
3553 2812 }
3554 2813
3555 - /**
3556 - * @param string $name
3557 - * @param string $class
3558 - * @param string $form_name
3559 - *
3560 - * @return void
3561 - */
3562 2814 public static function maybe_add_tooltip( $name, $class = 'closed', $form_name = '' ) {
3563 2815 $tooltips = array(
3564 2816 'action_title' => __( 'Give this action a label for easy reference.', 'formidable' ),
3565 - 'email_to' => __( 'Add one or more recipient addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com. [default-email] is the address set in the global "Default Email Address" settings.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
2817 + 'email_to' => __( 'Add one or more recipient addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com. [admin_email] is the address set in WP General Settings.', 'formidable' ),
3566 2818 'cc' => __( 'Add CC addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
3567 2819 'bcc' => __( 'Add BCC addresses separated by a ",". FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
3568 - 'reply_to' => __( 'If you would like a different reply to address than the "from" address, add a single address here. FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
2820 + 'reply_to' => __( 'If you would like a different reply to address than the "from" address, add a single address here. FORMAT: Name <name@email.com> or name@email.com.', 'formidable' ),
3569 2821 'from' => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <john@example.com> or john@example.com.', 'formidable' ),
3570 2822 /* translators: %1$s: Form name, %2$s: Date */
3571 - '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
3572 - '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
2823 + '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() ) ),
2824 + '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' ),
3573 2825 );
3574 2826
3575 2827 if ( ! isset( $tooltips[ $name ] ) ) {
3576 2828 return;
@@ -3575,9 +2827,9 @@
3575 2827 if ( ! isset( $tooltips[ $name ] ) ) {
3576 2828 return;
3577 2829 }
3578 2830
3579 - if ( 'open' === $class ) {
2831 + if ( 'open' == $class ) {
3580 2832 echo ' frm_help"';
3581 2833 } else {
3582 2834 echo ' class="frm_help"';
3583 2835 }
@@ -3583,9 +2835,9 @@
3583 2835 }
3584 2836
3585 2837 echo ' title="' . esc_attr( $tooltips[ $name ] );
3586 2838
3587 - if ( 'open' !== $class ) {
2839 + if ( 'open' != $class ) {
3588 2840 echo '"';
3589 2841 }
3590 2842 }
3591 2843
@@ -3590,28 +2842,20 @@
3590 2842 }
3591 2843
3592 2844 /**
3593 2845 * Add the current_page class to that page in the form nav
3594 - *
3595 - * @param int|string $page
3596 - * @param int|string $current_page
3597 - * @param array $action
3598 - *
3599 - * @return void
3600 2846 */
3601 2847 public static function select_current_page( $page, $current_page, $action = array() ) {
3602 - // phpcs:ignore Universal.Operators.StrictComparisons
3603 2848 if ( $current_page != $page ) {
3604 2849 return;
3605 2850 }
3606 2851
3607 2852 $frm_action = self::simple_get( 'frm_action', 'sanitize_title' );
3608 -
3609 2853 if ( 'lite-reports' === $frm_action ) {
3610 2854 $frm_action = 'reports';
3611 2855 }
3612 2856
3613 - if ( ! $action || ( $frm_action && in_array( $frm_action, $action, true ) ) ) {
2857 + if ( empty( $action ) || ( ! empty( $frm_action ) && in_array( $frm_action, $action ) ) ) {
3614 2858 echo ' class="current_page"';
3615 2859 }
3616 2860 }
3617 2861
@@ -3641,19 +2885,14 @@
3641 2885
3642 2886 // Add extra slashes for \r\n since WP strips them.
3643 2887 $post_content = str_replace( array( '\\r', '\\n', '\\u', '\\t' ), array( '\\\\r', '\\\\n', '\\\\u', '\\\\t' ), $post_content );
3644 2888
3645 - // Allow for &quot
3646 - return str_replace( '&quot;', '\\"', $post_content );
2889 + // allow for &quot
2890 + $post_content = str_replace( '&quot;', '\\"', $post_content );
2891 +
2892 + return $post_content;
3647 2893 }
3648 2894
3649 - /**
3650 - * @param array|string $val
3651 - * @param int|string $key
3652 - * @param array $post_content
3653 - *
3654 - * @return void
3655 - */
3656 2895 private static function prepare_action_slashes( $val, $key, &$post_content ) {
3657 2896 if ( ! isset( $post_content[ $key ] ) || is_numeric( $val ) ) {
3658 2897 return;
3659 2898 }
@@ -3662,17 +2901,15 @@
3662 2901 foreach ( $val as $k1 => $v1 ) {
3663 2902 self::prepare_action_slashes( $v1, $k1, $post_content[ $key ] );
3664 2903 unset( $k1, $v1 );
3665 2904 }
2905 + } else {
2906 + // Strip all slashes so everything is the same, no matter where the value is coming from
2907 + $val = stripslashes( $val );
3666 2908
3667 - return;
2909 + // Add backslashes before double quotes and forward slashes only
2910 + $post_content[ $key ] = addcslashes( $val, '"\\/' );
3668 2911 }
3669 -
3670 - // Strip all slashes so everything is the same, no matter where the value is coming from
3671 - $val = stripslashes( $val );
3672 -
3673 - // Add backslashes before double quotes and forward slashes only
3674 - $post_content[ $key ] = addcslashes( $val, '"\\/' );
3675 2912 }
3676 2913
3677 2914 /**
3678 2915 * Check for either json or serialized data. This is temporary while transitioning
@@ -3680,9 +2917,8 @@
3680 2917 *
3681 2918 * @since 4.02.03
3682 2919 *
3683 2920 * @param array|string $value
3684 - *
3685 2921 * @return void
3686 2922 */
3687 2923 public static function unserialize_or_decode( &$value ) {
3688 2924 if ( is_array( $value ) ) {
@@ -3688,9 +2924,13 @@
3688 2924 if ( is_array( $value ) ) {
3689 2925 return;
3690 2926 }
3691 2927
3692 - $value = is_serialized( $value ) ? self::maybe_unserialize_array( $value ) : self::maybe_json_decode( $value, false );
2928 + if ( is_serialized( $value ) ) {
2929 + $value = self::maybe_unserialize_array( $value );
2930 + } else {
2931 + $value = self::maybe_json_decode( $value, false );
2932 + }
3693 2933 }
3694 2934
3695 2935 /**
3696 2936 * Safely unserialize an array if necessary.
@@ -3698,9 +2938,8 @@
3698 2938 *
3699 2939 * @since 6.2
3700 2940 *
3701 2941 * @param mixed $value
3702 - *
3703 2942 * @return mixed
3704 2943 */
3705 2944 public static function maybe_unserialize_array( $value ) {
3706 2945 if ( ! is_string( $value ) ) {
@@ -3707,15 +2946,18 @@
3707 2946 return $value;
3708 2947 }
3709 2948
3710 2949 // Since we only expect an array, skip anything that doesn't start with a:.
3711 - if ( ! is_serialized( $value ) || ! str_starts_with( $value, 'a:' ) ) {
2950 + if ( ! is_serialized( $value ) || 'a:' !== substr( $value, 0, 2 ) ) {
3712 2951 return $value;
3713 2952 }
3714 2953
3715 2954 $parsed = FrmSerializedStringParserHelper::get()->parse( $value );
2955 + if ( is_array( $parsed ) ) {
2956 + $value = $parsed;
2957 + }
3716 2958
3717 - return is_array( $parsed ) ? $parsed : $value;
2959 + return $value;
3718 2960 }
3719 2961
3720 2962 /**
3721 2963 * Decode a JSON string.
@@ -3720,12 +2962,11 @@
3720 2962 /**
3721 2963 * Decode a JSON string.
3722 2964 * Do not switch shortcodes like [24] to array unless intentional ie XML values.
3723 2965 *
3724 - * @param array|string|null $string
3725 - * @param bool $single_to_array
3726 - *
3727 - * @return array|string|null
2966 + * @param mixed $string
2967 + * @param bool $single_to_array
2968 + * @return mixed
3728 2969 */
3729 2970 public static function maybe_json_decode( $string, $single_to_array = true ) {
3730 2971 if ( is_array( $string ) || is_null( $string ) ) {
3731 2972 return $string;
@@ -3730,19 +2971,20 @@
3730 2971 if ( is_array( $string ) || is_null( $string ) ) {
3731 2972 return $string;
3732 2973 }
3733 2974
3734 - $new_string = json_decode( $string, true );
3735 - $single_value = false;
3736 -
3737 - if ( ! $single_to_array ) {
3738 - $single_value = is_array( $new_string ) && count( $new_string ) === 1 && isset( $new_string[0] );
2975 + $new_string = json_decode( $string, true );
2976 + if ( function_exists( 'json_last_error' ) ) {
2977 + // php 5.3+
2978 + $single_value = false;
2979 + if ( ! $single_to_array ) {
2980 + $single_value = is_array( $new_string ) && count( $new_string ) === 1 && isset( $new_string[0] );
2981 + }
2982 + if ( json_last_error() == JSON_ERROR_NONE && is_array( $new_string ) && ! $single_value ) {
2983 + $string = $new_string;
2984 + }
3739 2985 }
3740 2986
3741 - if ( json_last_error() === JSON_ERROR_NONE && is_array( $new_string ) && ! $single_value ) {
3742 - return $new_string;
3743 - }
3744 -
3745 2987 return $string;
3746 2988 }
3747 2989
3748 2990 /**
@@ -3748,9 +2990,8 @@
3748 2990 /**
3749 2991 * @since 6.2.3
3750 2992 *
3751 2993 * @param string $value
3752 - *
3753 2994 * @return string
3754 2995 */
3755 2996 public static function maybe_utf8_encode( $value ) {
3756 2997 $from_format = 'ISO-8859-1';
@@ -3759,15 +3000,13 @@
3759 3000 if ( function_exists( 'mb_check_encoding' ) && function_exists( 'mb_convert_encoding' ) ) {
3760 3001 if ( mb_check_encoding( $value, $from_format ) ) {
3761 3002 return mb_convert_encoding( $value, $to_format, $from_format );
3762 3003 }
3763 -
3764 3004 return $value;
3765 3005 }
3766 3006
3767 3007 if ( function_exists( 'iconv' ) ) {
3768 3008 $converted = iconv( $from_format, $to_format, $value );
3769 -
3770 3009 // Value is false if $value is not ISO-8859-1.
3771 3010 if ( false !== $converted ) {
3772 3011 return $converted;
3773 3012 }
@@ -3779,12 +3018,8 @@
3779 3018 /**
3780 3019 * Reformat the json serialized array in name => value array.
3781 3020 *
3782 3021 * @since 4.02.03
3783 - *
3784 - * @param array $form
3785 - *
3786 - * @return void
3787 3022 */
3788 3023 public static function format_form_data( &$form ) {
3789 3024 $formatted = array();
3790 3025
@@ -3791,21 +3026,18 @@
3791 3026 foreach ( $form as $input ) {
3792 3027 if ( ! isset( $input['name'] ) ) {
3793 3028 continue;
3794 3029 }
3795 -
3796 3030 $key = $input['name'];
3797 -
3798 - if ( ! isset( $formatted[ $key ] ) ) {
3031 + if ( isset( $formatted[ $key ] ) ) {
3032 + if ( is_array( $formatted[ $key ] ) ) {
3033 + $formatted[ $key ][] = $input['value'];
3034 + } else {
3035 + $formatted[ $key ] = array( $formatted[ $key ], $input['value'] );
3036 + }
3037 + } else {
3799 3038 $formatted[ $key ] = $input['value'];
3800 - continue;
3801 3039 }
3802 -
3803 - if ( is_array( $formatted[ $key ] ) ) {
3804 - $formatted[ $key ][] = $input['value'];
3805 - } else {
3806 - $formatted[ $key ] = array( $formatted[ $key ], $input['value'] );
3807 - }
3808 3040 }
3809 3041
3810 3042 parse_str( http_build_query( $formatted ), $form );
3811 3043 }
@@ -3811,15 +3043,14 @@
3811 3043 }
3812 3044
3813 3045 /**
3814 3046 * @since 4.02.03
3815 - *
3816 - * @param array|string $value
3817 - *
3818 - * @return string
3819 3047 */
3820 3048 public static function maybe_json_encode( $value ) {
3821 - return is_array( $value ) ? wp_json_encode( $value ) : $value;
3049 + if ( is_array( $value ) ) {
3050 + $value = wp_json_encode( $value );
3051 + }
3052 + return $value;
3822 3053 }
3823 3054
3824 3055 /**
3825 3056 * Echo The javascript to open and highlight the Formidable menu
@@ -3826,19 +3057,18 @@
3826 3057 *
3827 3058 * @since 1.07.10
3828 3059 *
3829 3060 * @param string $post_type The name of the post type that may need to be highlighted.
3830 - *
3831 3061 * @return void
3832 3062 */
3833 3063 public static function maybe_highlight_menu( $post_type ) {
3834 3064 global $post;
3835 3065
3836 - if ( isset( $_REQUEST['post_type'] ) && $_REQUEST['post_type'] !== $post_type ) {
3066 + if ( isset( $_REQUEST['post_type'] ) && $_REQUEST['post_type'] != $post_type ) {
3837 3067 return;
3838 3068 }
3839 3069
3840 - if ( is_object( $post ) && $post->post_type !== $post_type ) {
3070 + if ( is_object( $post ) && $post->post_type != $post_type ) {
3841 3071 return;
3842 3072 }
3843 3073
3844 3074 self::load_admin_wide_js();
@@ -3848,15 +3078,12 @@
3848 3078 /**
3849 3079 * Load the JS file on non-Formidable pages in the admin area
3850 3080 *
3851 3081 * @since 2.0
3852 - *
3853 - * @param bool $load
3854 - *
3855 - * @return void
3856 3082 */
3857 3083 public static function load_admin_wide_js( $load = true ) {
3858 - wp_register_script( 'formidable_admin_global', self::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery' ), self::plugin_version() );
3084 + $version = self::plugin_version();
3085 + wp_register_script( 'formidable_admin_global', self::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery' ), $version );
3859 3086
3860 3087 $global_strings = array(
3861 3088 'updating_msg' => __( 'Please wait while your site updates.', 'formidable' ),
3862 3089 'deauthorize' => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ),
@@ -3862,13 +3089,12 @@
3862 3089 'deauthorize' => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ),
3863 3090 'url' => self::plugin_url(),
3864 3091 'app_url' => 'https://formidableforms.com/',
3865 3092 'applicationsUrl' => admin_url( 'admin.php?page=formidable-applications' ),
3866 - '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
3093 + 'canAccessApplicationDashboard' => current_user_can( is_callable( 'FrmProApplicationsHelper::get_required_templates_capability' ) ? FrmProApplicationsHelper::get_required_templates_capability() : 'frm_edit_forms' ),
3867 3094 'loading' => __( 'Loading&hellip;', 'formidable' ),
3868 3095 'nonce' => wp_create_nonce( 'frm_ajax' ),
3869 3096 'proIncludesSliderJs' => is_callable( 'FrmProFormsHelper::prepare_custom_currency' ),
3870 - 'inboxSlideIn' => FrmInbox::get_inbox_slide_in_value_for_js(),
3871 3097 );
3872 3098 wp_localize_script( 'formidable_admin_global', 'frmGlobal', $global_strings );
3873 3099
3874 3100 if ( $load ) {
@@ -3877,10 +3103,8 @@
3877 3103 }
3878 3104
3879 3105 /**
3880 3106 * @since 2.0.9
3881 - *
3882 - * @return void
3883 3107 */
3884 3108 public static function load_font_style() {
3885 3109 wp_enqueue_style( 'frm_fonts', self::plugin_url() . '/css/frm_fonts.css', array(), self::plugin_version() );
3886 3110 }
@@ -3886,111 +3110,95 @@
3886 3110 }
3887 3111
3888 3112 /**
3889 3113 * @param string $location
3890 - *
3891 - * @return void
3892 3114 */
3893 3115 public static function localize_script( $location ) {
3894 - global $wp_scripts, $wp_version;
3116 + global $wp_scripts;
3895 3117
3896 3118 $script_strings = array(
3897 - 'ajax_url' => esc_url_raw( self::get_ajax_url() ),
3898 - 'images_url' => self::plugin_url() . '/images',
3899 - 'loading' => __( 'Loading&hellip;', 'formidable' ),
3900 - 'remove' => __( 'Remove', 'formidable' ),
3901 - 'offset' => apply_filters( 'frm_scroll_offset', 4 ),
3902 - 'nonce' => wp_create_nonce( 'frm_ajax' ),
3903 - 'id' => __( 'ID', 'formidable' ),
3904 - 'no_results' => __( 'No results match', 'formidable' ),
3905 - 'file_spam' => __( 'That file looks like Spam.', 'formidable' ),
3906 - 'calc_error' => __( 'There is an error in the calculation in the field with key', 'formidable' ),
3907 - 'empty_fields' => __( 'Please complete the preceding required fields before uploading a file.', 'formidable' ),
3908 - 'focus_first_error' => self::should_focus_first_error(),
3909 - 'include_alert_role' => self::should_include_alert_role_on_field_errors(),
3910 - // We need to keep this setting for a few versions because Pro checks for this.
3911 - 'include_resend_email' => false,
3119 + 'ajax_url' => esc_url_raw( self::get_ajax_url() ),
3120 + 'images_url' => self::plugin_url() . '/images',
3121 + 'loading' => __( 'Loading&hellip;', 'formidable' ),
3122 + 'remove' => __( 'Remove', 'formidable' ),
3123 + 'offset' => apply_filters( 'frm_scroll_offset', 4 ),
3124 + 'nonce' => wp_create_nonce( 'frm_ajax' ),
3125 + 'id' => __( 'ID', 'formidable' ),
3126 + 'no_results' => __( 'No results match', 'formidable' ),
3127 + 'file_spam' => __( 'That file looks like Spam.', 'formidable' ),
3128 + 'calc_error' => __( 'There is an error in the calculation in the field with key', 'formidable' ),
3129 + 'empty_fields' => __( 'Please complete the preceding required fields before uploading a file.', 'formidable' ),
3130 + 'focus_first_error' => self::should_focus_first_error(),
3131 + 'include_alert_role' => self::should_include_alert_role_on_field_errors(),
3912 3132 );
3913 3133
3914 3134 $data = $wp_scripts->get_data( 'formidable', 'data' );
3915 -
3916 3135 if ( ! $data ) {
3917 3136 wp_localize_script( 'formidable', 'frm_js', $script_strings );
3918 3137 }
3919 3138
3920 3139 if ( $location === 'admin' ) {
3140 + $frm_settings = self::get_settings();
3921 3141 $admin_script_strings = array(
3922 - 'desc' => __( '(Click to add description)', 'formidable' ),
3923 - 'blank' => __( '(Blank)', 'formidable' ),
3924 - 'no_label' => self::get_no_label_text(),
3925 - 'ok' => __( 'OK', 'formidable' ),
3926 - 'cancel' => __( 'Cancel', 'formidable' ),
3927 - 'default_label' => __( 'Default', 'formidable' ),
3928 - 'clear_default' => __( 'Clear default value when typing', 'formidable' ),
3929 - 'no_clear_default' => __( 'Do not clear default value when typing', 'formidable' ),
3930 - 'valid_default' => __( 'Default value will pass form validation', 'formidable' ),
3931 - 'no_valid_default' => __( 'Default value will NOT pass form validation', 'formidable' ),
3932 - 'confirm' => __( 'Are you sure?', 'formidable' ),
3933 - 'conf_delete' => __( 'Are you sure you want to delete this field and all data associated with it?', 'formidable' ),
3934 - '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
3935 - 'conf_no_repeat' => __( 'Warning: If you have entries with multiple rows, all but the first row will be lost.', 'formidable' ),
3936 - 'default_unique' => FrmFieldsHelper::default_unique_msg(),
3937 - 'default_conf' => __( 'The entered values do not match', 'formidable' ),
3938 - 'enter_email' => __( 'Enter Email', 'formidable' ),
3939 - 'confirm_email' => __( 'Confirm Email', 'formidable' ),
3940 - 'conditional_text' => __( 'Conditional content here', 'formidable' ),
3941 - 'new_option' => __( 'New Option', 'formidable' ),
3942 - '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
3943 - 'enter_password' => __( 'Enter Password', 'formidable' ),
3944 - 'confirm_password' => __( 'Confirm Password', 'formidable' ),
3945 - 'import_complete' => __( 'Import Complete', 'formidable' ),
3946 - 'updating' => __( 'Please wait while your site updates.', 'formidable' ),
3947 - 'no_save_warning' => __( 'Warning: There is no way to retrieve unsaved entries.', 'formidable' ),
3948 - 'private_label' => __( 'Private', 'formidable' ),
3949 - 'jquery_ui_url' => '',
3950 - 'pro_url' => is_callable( 'FrmProAppHelper::plugin_url' ) ? FrmProAppHelper::plugin_url() : '',
3951 - 'no_licenses' => __( 'No new licenses were found', 'formidable' ),
3952 - 'unmatched_parens' => __( 'This calculation has at least one unmatched ( ) { } [ ].', 'formidable' ),
3953 - 'view_shortcodes' => __( 'This calculation may have shortcodes that work in Views but not forms.', 'formidable' ),
3954 - 'text_shortcodes' => __( 'This calculation may have shortcodes that work in text calculations but not numeric calculations.', 'formidable' ),
3955 - /* translators: %d is the number of allowed actions per form */
3956 - 'only_one_action' => sprintf( __( 'This form action is limited to %d per form.', 'formidable' ), 1 ),
3957 - 'edit_action_text' => __( 'Please edit the existing form action.', 'formidable' ),
3958 - 'only_one_payment_action' => __( 'This form already has a payment action, and is currently limited to a single payment action.', 'formidable' ),
3959 - '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
3960 - 'unsafe_params' => FrmFormsHelper::reserved_words(),
3142 + 'desc' => __( '(Click to add description)', 'formidable' ),
3143 + 'blank' => __( '(Blank)', 'formidable' ),
3144 + 'no_label' => __( '(no label)', 'formidable' ),
3145 + 'ok' => __( 'OK', 'formidable' ),
3146 + 'cancel' => __( 'Cancel', 'formidable' ),
3147 + 'default_label' => __( 'Default', 'formidable' ),
3148 + 'clear_default' => __( 'Clear default value when typing', 'formidable' ),
3149 + 'no_clear_default' => __( 'Do not clear default value when typing', 'formidable' ),
3150 + 'valid_default' => __( 'Default value will pass form validation', 'formidable' ),
3151 + 'no_valid_default' => __( 'Default value will NOT pass form validation', 'formidable' ),
3152 + 'confirm' => __( 'Are you sure?', 'formidable' ),
3153 + 'conf_delete' => __( 'Are you sure you want to delete this field and all data associated with it?', 'formidable' ),
3154 + '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' ),
3155 + 'conf_no_repeat' => __( 'Warning: If you have entries with multiple rows, all but the first row will be lost.', 'formidable' ),
3156 + 'default_unique' => $frm_settings->unique_msg,
3157 + 'default_conf' => __( 'The entered values do not match', 'formidable' ),
3158 + 'enter_email' => __( 'Enter Email', 'formidable' ),
3159 + 'confirm_email' => __( 'Confirm Email', 'formidable' ),
3160 + 'conditional_text' => __( 'Conditional content here', 'formidable' ),
3161 + 'new_option' => __( 'New Option', 'formidable' ),
3162 + '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' ),
3163 + 'enter_password' => __( 'Enter Password', 'formidable' ),
3164 + 'confirm_password' => __( 'Confirm Password', 'formidable' ),
3165 + 'import_complete' => __( 'Import Complete', 'formidable' ),
3166 + 'updating' => __( 'Please wait while your site updates.', 'formidable' ),
3167 + 'no_save_warning' => __( 'Warning: There is no way to retrieve unsaved entries.', 'formidable' ),
3168 + 'private_label' => __( 'Private', 'formidable' ),
3169 + 'jquery_ui_url' => '',
3170 + 'pro_url' => is_callable( 'FrmProAppHelper::plugin_url' ) ? FrmProAppHelper::plugin_url() : '',
3171 + 'no_licenses' => __( 'No new licenses were found', 'formidable' ),
3172 + 'unmatched_parens' => __( 'This calculation has at least one unmatched ( ) { } [ ].', 'formidable' ),
3173 + 'view_shortcodes' => __( 'This calculation may have shortcodes that work in Views but not forms.', 'formidable' ),
3174 + 'text_shortcodes' => __( 'This calculation may have shortcodes that work in text calculations but not numeric calculations.', 'formidable' ),
3175 + 'only_one_action' => __( 'This form action is limited to one per form. Please edit the existing form action.', 'formidable' ),
3176 + 'unsafe_params' => FrmFormsHelper::reserved_words(),
3961 3177 /* Translators: %s is the name of a Detail Page Slug that is a reserved word.*/
3962 - '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
3178 + 'slug_is_reserved' => sprintf( __( 'The Detail Page Slug "%s" is reserved by WordPress. This may cause problems. Is this intentional?', 'formidable' ), '****' ),
3963 3179 /* 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. */
3964 - '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
3965 - 'reserved_words' => __( 'See the list of reserved words in WordPress.', 'formidable' ),
3966 - 'repeat_limit_min' => __( 'Please enter a Repeat Limit that is greater than 1.', 'formidable' ),
3967 - 'checkbox_limit' => __( 'Please select a limit between 0 and 200.', 'formidable' ),
3968 - 'install' => __( 'Install', 'formidable' ),
3969 - 'active' => __( 'Active', 'formidable' ),
3970 - 'installed' => __( 'Installed', 'formidable' ),
3971 - 'not_installed' => __( 'Not Installed', 'formidable' ),
3972 - 'select_a_field' => __( 'Select a Field', 'formidable' ),
3973 - 'no_items_found' => __( 'No items found.', 'formidable' ),
3974 - 'field_already_used' => __( 'Oops. You have already used that field.', 'formidable' ),
3180 + 'param_is_reserved' => sprintf( __( 'The parameter "%s" is reserved by WordPress. This may cause problems when included in the URL. Is this intentional? ', 'formidable' ), '****' ),
3181 + 'reserved_words' => __( 'See the list of reserved words in WordPress.', 'formidable' ),
3182 + 'repeat_limit_min' => __( 'Please enter a Repeat Limit that is greater than 1.', 'formidable' ),
3183 + 'checkbox_limit' => __( 'Please select a limit between 0 and 200.', 'formidable' ),
3184 + 'install' => __( 'Install', 'formidable' ),
3185 + 'active' => __( 'Active', 'formidable' ),
3186 + 'installed' => __( 'Installed', 'formidable' ),
3187 + 'not_installed' => __( 'Not Installed', 'formidable' ),
3188 + 'select_a_field' => __( 'Select a Field', 'formidable' ),
3189 + 'no_items_found' => __( 'No items found.', 'formidable' ),
3190 + 'field_already_used' => __( 'Oops. You have already used that field.', 'formidable' ),
3975 3191
3976 3192 // Deprecated in 6.0.
3977 - 'saving' => '',
3193 + 'saving' => '',
3978 3194
3979 3195 // Deprecated in 6.0.
3980 - 'saved' => '',
3196 + 'saved' => '',
3981 3197
3982 3198 // translators: %1$s: HTML open tag, %2$s: HTML end tag.
3983 - 'holdShiftMsg' => esc_html__( 'You can hold %1$sShift%2$s on your keyboard to select multiple fields', 'formidable' ),
3984 - 'noTitleText' => FrmFormsHelper::get_no_title_text(),
3985 -
3986 - // In older versions this event listener causes the section to immediately close again
3987 - // When the h3 element is clicked. It's only required in WP 6.7+.
3988 - 'requireAccordionTitleClickListener' => version_compare( $wp_version, '6.7', '>=' ),
3199 + 'holdShiftMsg' => esc_html__( 'You can hold %1$sShift%2$s on your keyboard to select multiple fields', 'formidable' ),
3989 3200 );
3990 -
3991 - self::add_form_builder_modal_data( $admin_script_strings );
3992 -
3993 3201 /**
3994 3202 * @param array $admin_script_strings
3995 3203 */
3996 3204 $admin_script_strings = apply_filters( 'frm_admin_script_strings', $admin_script_strings );
@@ -3995,9 +3203,8 @@
3995 3203 */
3996 3204 $admin_script_strings = apply_filters( 'frm_admin_script_strings', $admin_script_strings );
3997 3205
3998 3206 $data = $wp_scripts->get_data( 'formidable_admin', 'data' );
3999 -
4000 3207 if ( ! $data ) {
4001 3208 wp_localize_script( 'formidable_admin', 'frm_admin_js', $admin_script_strings );
4002 3209 }
4003 3210 }//end if
@@ -4003,91 +3210,8 @@
4003 3210 }//end if
4004 3211 }
4005 3212
4006 3213 /**
4007 - * @param array $admin_script_strings
4008 - *
4009 - * @return void
4010 - */
4011 - private static function add_form_builder_modal_data( &$admin_script_strings ) {
4012 - if ( ! self::is_form_builder_page() || self::pro_is_installed() ) {
4013 - return;
4014 - }
4015 -
4016 - $stripe_connected = FrmStrpLiteConnectHelper::at_least_one_mode_is_setup();
4017 - $square_connected = FrmSquareLiteConnectHelper::at_least_one_mode_is_setup();
4018 - $paypal_connected = FrmPayPalLiteConnectHelper::at_least_one_mode_is_setup();
4019 - $gateway_connected = $stripe_connected || $square_connected || $paypal_connected;
4020 - $payments_settings_url = FrmStrpLiteAppController::get_payments_settings_url();
4021 -
4022 - if ( ! $gateway_connected ) {
4023 - // This modal shows when user clicks on one of the pricing fields and no payment gateways configured.
4024 - $admin_script_strings['paymentsSettingsModal'] = array(
4025 - 'title' => __( 'Setup a Payment Gateway first', 'formidable' ),
4026 - 'msg' => __( 'To use the payment fields, please install and configure a payment gateway in your account settings.', 'formidable' ),
4027 - 'closeText' => __( 'Close', 'formidable' ),
4028 - 'actionUrl' => $payments_settings_url,
4029 - 'actionText' => __( 'Go to Payment Settings', 'formidable' ),
4030 - 'noCenter' => true,
4031 - );
4032 - }
4033 -
4034 - // This modal shows on load once after upgrading the plugin.
4035 - $show_pricing_fields_modal = get_option( 'frm_show_pricing_fields_modal' );
4036 -
4037 - if ( ! $show_pricing_fields_modal ) {
4038 - return;
4039 - }
4040 -
4041 - $admin_script_strings['pricingFieldsModal'] = array(
4042 - 'title' => esc_html__( 'Start Accepting Payments Today!', 'formidable' ),
4043 - 'img' => esc_url( self::plugin_url() . '/images/upsell/pricing-fields.png' ),
4044 - 'noCenter' => true,
4045 - );
4046 -
4047 - if ( $gateway_connected ) {
4048 - $gateway_texts = array();
4049 -
4050 - if ( $stripe_connected ) {
4051 - $gateway_texts['stripe'] = esc_html__( 'Stripe', 'formidable' );
4052 - }
4053 -
4054 - if ( $square_connected ) {
4055 - $gateway_texts['square'] = esc_html__( 'Square', 'formidable' );
4056 - }
4057 -
4058 - if ( $paypal_connected ) {
4059 - $gateway_texts['paypal'] = esc_html__( 'PayPal', 'formidable' );
4060 - }
4061 -
4062 - $admin_script_strings['pricingFieldsModal']['msg'] = sprintf(
4063 - // translators: %s: Stripe, Square, or PayPal.
4064 - esc_html__( 'You already have %s connected, so these have already been unlocked.', 'formidable' ),
4065 - esc_html( implode( ' ' . esc_html__( 'and', 'formidable' ) . ' ', $gateway_texts ) )
4066 - );
4067 - } else {
4068 - $admin_script_strings['pricingFieldsModal']['closeText'] = __( 'I\'ll do it later!', 'formidable' );
4069 - $admin_script_strings['pricingFieldsModal']['actionText'] = __( 'Setup Payments Now', 'formidable' );
4070 - $admin_script_strings['pricingFieldsModal']['actionUrl'] = $payments_settings_url;
4071 - // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
4072 - $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' );
4073 - }//end if
4074 -
4075 - delete_option( 'frm_show_pricing_fields_modal' );
4076 - }
4077 -
4078 - /**
4079 - * Get the no label text.
4080 - *
4081 - * @since 6.25.1
4082 - *
4083 - * @return string
4084 - */
4085 - public static function get_no_label_text() {
4086 - return __( '(no label)', 'formidable' );
4087 - }
4088 -
4089 - /**
4090 3214 * @since 6.5
4091 3215 *
4092 3216 * @return string
4093 3217 */
@@ -4129,10 +3253,8 @@
4129 3253 *
4130 3254 * @since 1.07.10
4131 3255 *
4132 3256 * @param float $min_version The version the add-on requires.
4133 - *
4134 - * @return void
4135 3257 */
4136 3258 public static function min_version_notice( $min_version ) {
4137 3259 $frm_version = self::plugin_version();
4138 3260
@@ -4141,11 +3263,11 @@
4141 3263 return;
4142 3264 }
4143 3265
4144 3266 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
4145 - 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
4146 - esc_html__( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
4147 - '</div></td></tr>';
3267 + 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">' .
3268 + esc_html__( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) .
3269 + '</div></td></tr>';
4148 3270 }
4149 3271
4150 3272 /**
4151 3273 * If Pro is far outdated, show a message.
@@ -4151,10 +3273,8 @@
4151 3273 * If Pro is far outdated, show a message.
4152 3274 *
4153 3275 * @since 4.0.01
4154 3276 *
4155 - * @param string $min_version
4156 - *
4157 3277 * @return void
4158 3278 */
4159 3279 public static function min_pro_version_notice( $min_version ) {
4160 3280 if ( ! self::is_formidable_admin() ) {
@@ -4164,14 +3284,26 @@
4164 3284
4165 3285 self::php_version_notice();
4166 3286
4167 3287 $is_pro = self::pro_is_installed() && class_exists( 'FrmProDb' );
4168 -
4169 3288 if ( ! $is_pro || self::meets_min_pro_version( $min_version ) ) {
4170 3289 return;
4171 3290 }
4172 3291
4173 - include self::plugin_path() . '/classes/views/addons/min-version-notice.php';
3292 + $pro_version = FrmProDb::$plug_version;
3293 + $expired = FrmAddonsController::is_license_expired();
3294 + ?>
3295 + <div class="frm-banner-alert frm_error_style frm_previous_install">
3296 + <?php
3297 + esc_html_e( 'You are running a version of Formidable Forms that may not be compatible with your version of Formidable Forms Pro.', 'formidable' );
3298 + if ( empty( $expired ) ) {
3299 + echo ' Please <a href="' . esc_url( admin_url( 'plugins.php?s=formidable%20forms%20pro' ) ) . '">update now</a>.';
3300 + } else {
3301 + echo '<br/>Please <a href="https://formidableforms.com/account/downloads/?utm_source=WordPress&utm_medium=outdated">renew now</a> to get the latest version.';
3302 + }
3303 + ?>
3304 + </div>
3305 + <?php
4174 3306 }
4175 3307
4176 3308 /**
4177 3309 * If Pro is installed, check the version number.
@@ -4176,12 +3308,8 @@
4176 3308 /**
4177 3309 * If Pro is installed, check the version number.
4178 3310 *
4179 3311 * @since 4.0.01
4180 - *
4181 - * @param string $min_version
4182 - *
4183 - * @return bool
4184 3312 */
4185 3313 public static function meets_min_pro_version( $min_version ) {
4186 3314 return ! class_exists( 'FrmProDb' ) || version_compare( FrmProDb::$plug_version, $min_version, '>=' );
4187 3315 }
@@ -4186,22 +3314,24 @@
4186 3314 return ! class_exists( 'FrmProDb' ) || version_compare( FrmProDb::$plug_version, $min_version, '>=' );
4187 3315 }
4188 3316
4189 3317 /**
4190 - * Show a message if the PHP version is below the recommendations.
3318 + * Show a message if the browser or PHP version is below the recommendations.
4191 3319 *
4192 3320 * @since 4.0.02
4193 - *
4194 - * @return void
4195 3321 */
4196 3322 private static function php_version_notice() {
4197 3323 $message = array();
3324 + if ( version_compare( phpversion(), '5.6', '<' ) ) {
3325 + $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' );
3326 + }
4198 3327
4199 - if ( version_compare( phpversion(), '7.0', '<' ) ) {
4200 - $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
3328 + $browser = self::get_server_value( 'HTTP_USER_AGENT' );
3329 + $is_ie = strpos( $browser, 'MSIE' ) !== false;
3330 + if ( $is_ie ) {
3331 + $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' );
4201 3332 }
4202 3333
4203 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
4204 3334 foreach ( $message as $m ) {
4205 3335 ?>
4206 3336 <div class="frm-banner-alert frm_error_style frm_previous_install">
4207 3337 <?php echo esc_html( $m ); ?>
@@ -4207,14 +3337,12 @@
4207 3337 <?php echo esc_html( $m ); ?>
4208 3338 </div>
4209 3339 <?php
4210 3340 }
4211 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
4212 3341 }
4213 3342
4214 3343 /**
4215 3344 * @param string $type
4216 - *
4217 3345 * @return array<string,string>
4218 3346 */
4219 3347 public static function locales( $type = 'date' ) {
4220 3348 $locales = array(
@@ -4308,12 +3436,12 @@
4308 3436 'zu' => __( 'Zulu', 'formidable' ),
4309 3437 );
4310 3438
4311 3439 if ( $type === 'captcha' ) {
4312 - // Remove the languages unavailable for the captcha
3440 + // remove the languages unavailable for the captcha
4313 3441 $unset = array( 'sq', 'bs', 'eo', 'fo', 'fr-CH', 'sr-SR', 'ar-DZ', 'be', 'cy-GB', 'kk', 'km', 'ky', 'lb', 'mk', 'nb', 'nn', 'rm', 'tj' );
4314 3442 } else {
4315 - // Remove the languages unavailable for the datepicker
3443 + // remove the languages unavailable for the datepicker
4316 3444 $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' );
4317 3445 }
4318 3446
4319 3447 $locales = array_diff_key( $locales, array_flip( $unset ) );
@@ -4324,27 +3452,32 @@
4324 3452 * @since 5.4.5 Added $args parameter with type.
4325 3453 *
4326 3454 * @param array<string,string> $locales
4327 3455 * @param array $args {
4328 - *
4329 3456 * @type string $type
4330 3457 * }
4331 3458 */
4332 - return apply_filters( 'frm_locales', $locales, compact( 'type' ) );
3459 + $locales = apply_filters( 'frm_locales', $locales, compact( 'type' ) );
3460 +
3461 + return $locales;
4333 3462 }
4334 3463
4335 3464 /**
4336 - * @return string
3465 + * Output HTML containing reference text for accessibility
3466 + *
3467 + * @deprecated 5.1
4337 3468 */
3469 + public static function multiselect_accessibility() {
3470 + _deprecated_function( __METHOD__, '5.1' );
3471 + }
3472 +
4338 3473 public static function get_menu_icon_class() {
4339 3474 if ( is_callable( 'FrmProAppHelper::get_settings' ) ) {
4340 3475 $settings = FrmProAppHelper::get_settings();
4341 -
4342 3476 if ( is_object( $settings ) && ! empty( $settings->menu_icon ) ) {
4343 3477 return $settings->menu_icon;
4344 3478 }
4345 3479 }
4346 -
4347 3480 return 'frmfont frm_logo_icon';
4348 3481 }
4349 3482
4350 3483 /**
@@ -4362,9 +3495,10 @@
4362 3495 * @type array $input_attrs Attributes of value input.
4363 3496 * }
4364 3497 */
4365 3498 public static function images_dropdown( $args ) {
4366 - $args = self::fill_default_images_dropdown_args( $args );
3499 + $args = self::fill_default_images_dropdown_args( $args );
3500 +
4367 3501 $input_attrs_str = self::get_images_dropdown_input_attrs( $args );
4368 3502 ob_start();
4369 3503 include self::plugin_path() . '/classes/views/shared/images-dropdown.php';
4370 3504 $output = ob_get_clean();
@@ -4385,9 +3519,8 @@
4385 3519 *
4386 3520 * @since 5.0.04
4387 3521 *
4388 3522 * @param array $args The arguments.
4389 - *
4390 3523 * @return array
4391 3524 */
4392 3525 private static function fill_default_images_dropdown_args( $args ) {
4393 3526 $defaults = array(
@@ -4400,8 +3533,14 @@
4400 3533
4401 3534 $new_args['options'] = (array) $new_args['options'];
4402 3535 $new_args['input_attrs'] = (array) $new_args['input_attrs'];
4403 3536
3537 + // Set the number of columns.
3538 + $new_args['col_class'] = ceil( 12 / count( $new_args['options'] ) );
3539 + if ( $new_args['col_class'] > 6 ) {
3540 + $new_args['col_class'] = ceil( $new_args['col_class'] / 2 );
3541 + }
3542 +
4404 3543 /**
4405 3544 * Allows modifying the arguments of images_dropdown() method.
4406 3545 *
4407 3546 * @since 5.0.04
@@ -4417,9 +3556,8 @@
4417 3556 *
4418 3557 * @since 5.0.04
4419 3558 *
4420 3559 * @param array $args The arguments.
4421 - *
4422 3560 * @return string
4423 3561 */
4424 3562 private static function get_images_dropdown_input_attrs( $args ) {
4425 3563 $input_attrs = $args['input_attrs'];
@@ -4426,9 +3564,8 @@
4426 3564 $input_attrs['type'] = 'radio';
4427 3565 $input_attrs['name'] = $args['name'];
4428 3566
4429 3567 $input_attrs_str = '';
4430 -
4431 3568 foreach ( $input_attrs as $key => $input_attr ) {
4432 3569 $input_attrs_str .= ' ' . sprintf( '%s="%s"', esc_attr( $key ), esc_attr( $input_attr ) );
4433 3570 }
4434 3571
@@ -4444,13 +3581,8 @@
4444 3581 }
4445 3582
4446 3583 /**
4447 3584 * @since 6.7.1
4448 - *
4449 - * @param array $option Option data.
4450 - * @param array $args The arguments of images_dropdown() method.
4451 - *
4452 - * @return array
4453 3585 */
4454 3586 public static function get_images_dropdown_atts( $option, $args ) {
4455 3587 $image = self::get_images_dropdown_option_image( $option, $args );
4456 3588 $classes = self::get_images_dropdown_option_classes( $option, $args );
@@ -4464,9 +3596,8 @@
4464 3596 * @since 5.0.04
4465 3597 *
4466 3598 * @param array $option Option data.
4467 3599 * @param array $args The arguments of images_dropdown() method.
4468 - *
4469 3600 * @return string
4470 3601 */
4471 3602 private static function get_images_dropdown_option_image( $option, $args ) {
4472 3603 $image = self::icon_by_class(
@@ -4471,9 +3602,9 @@
4471 3602 private static function get_images_dropdown_option_image( $option, $args ) {
4472 3603 $image = self::icon_by_class(
4473 3604 'frmfont ' . $option['svg'],
4474 3605 array(
4475 - 'echo' => false,
3606 + 'echo' => false,
4476 3607 )
4477 3608 );
4478 3609
4479 3610 $args['option'] = $option;
@@ -4495,9 +3626,8 @@
4495 3626 * @since 5.0.04
4496 3627 *
4497 3628 * @param array $option Option data.
4498 3629 * @param array $args The arguments of images_dropdown() method.
4499 - *
4500 3630 * @return string
4501 3631 */
4502 3632 private static function get_images_dropdown_option_classes( $option, $args ) {
4503 3633 $classes = '';
@@ -4525,19 +3655,17 @@
4525 3655 * @since 5.0.04
4526 3656 *
4527 3657 * @param array $option Option data.
4528 3658 * @param array $args The arguments of images_dropdown() method.
4529 - *
4530 3659 * @return string
4531 3660 */
4532 3661 private static function get_images_dropdown_option_html_attrs( $option, $args ) {
4533 3662 $html_attrs = '';
4534 -
4535 3663 if ( ! empty( $option['custom_attrs'] ) && is_array( $option['custom_attrs'] ) ) {
4536 3664 $html_attrs_arr = array();
4537 3665
4538 3666 foreach ( $option['custom_attrs'] as $key => $value ) {
4539 - if ( in_array( $key, array( 'type', 'class', 'data-value' ), true ) ) {
3667 + if ( in_array( $key, array( 'type', 'class', 'data-value' ) ) ) {
4540 3668 continue;
4541 3669 }
4542 3670
4543 3671 $html_attrs_arr[] = sprintf( '%s="%s"', esc_attr( $key ), esc_attr( $value ) );
@@ -4595,13 +3723,14 @@
4595 3723 * @since 5.0.07
4596 3724 *
4597 3725 * @param array $values
4598 3726 * @param array $keys
4599 - *
4600 3727 * @return array
4601 3728 */
4602 3729 public static function maybe_filter_array( $values, $keys ) {
4603 - if ( self::allow_unfiltered_html() ) {
3730 + $allow_unfiltered_html = self::allow_unfiltered_html();
3731 +
3732 + if ( $allow_unfiltered_html ) {
4604 3733 return $values;
4605 3734 }
4606 3735
4607 3736 foreach ( $keys as $key ) {
@@ -4613,9 +3742,9 @@
4613 3742 return $values;
4614 3743 }
4615 3744
4616 3745 /**
4617 - * Some back end fields allow privileged users to add scripts.
3746 + * Some back end fields allow privleged users to add scripts.
4618 3747 * A site that uses the DISALLOW_UNFILTERED_HTML always remove scripts on echo.
4619 3748 *
4620 3749 * @since 5.0.13
4621 3750 *
@@ -4620,80 +3749,29 @@
4620 3749 * @since 5.0.13
4621 3750 *
4622 3751 * @param string $value
4623 3752 * @param array|string $allowed 'all' for everything included as defaults.
4624 - *
4625 3753 * @return string
4626 3754 */
4627 3755 public static function maybe_kses( $value, $allowed = 'all' ) {
4628 3756 if ( self::should_never_allow_unfiltered_html() ) {
4629 - return self::kses( $value, $allowed );
3757 + $value = self::kses( $value, $allowed );
4630 3758 }
4631 3759 return $value;
4632 3760 }
4633 3761
4634 3762 /**
4635 - * Check if an option attribute used in an [input] shortcode is safe.
3763 + * @since 5.0.16
4636 3764 *
4637 - * @since 6.11.2
4638 - *
4639 - * @param string $key
4640 - * @param string $context Either 'display' or 'update'. On update, we want to allow a few keys that are never displayed.
4641 - *
4642 3765 * @return bool
4643 3766 */
4644 - public static function input_key_is_safe( $key, $context = 'display' ) {
4645 - if ( 'update' === $context && in_array( $key, array( 'opt', 'label' ), true ) ) {
4646 - $safe = true;
4647 - } elseif ( str_starts_with( $key, 'data-' ) ) {
4648 - // Allow all data attributes.
4649 - $safe = true;
4650 - } elseif ( str_starts_with( $key, 'aria-' ) ) {
4651 - // Allow all aria attributes.
4652 - $safe = true;
4653 - } else {
4654 - $safe_keys = array(
4655 - 'class',
4656 - 'required',
4657 - 'title',
4658 - 'placeholder',
4659 - 'value',
4660 - 'readonly',
4661 - 'disabled',
4662 - 'size',
4663 - 'maxlength',
4664 - 'min',
4665 - 'max',
4666 - 'pattern',
4667 - 'step',
4668 - 'autofocus',
4669 - 'width',
4670 - 'height',
4671 - 'autocomplete',
4672 - 'tabindex',
4673 - 'role',
4674 - 'style',
4675 - );
4676 - $safe = in_array( $key, $safe_keys, true );
4677 - }//end if
4678 -
4679 - /**
4680 - * Filter the $safe value so additional keys can be allowed or disallowed.
4681 - *
4682 - * @since 6.11.2
4683 - *
4684 - * @param bool $safe True if the key is considered safe.
4685 - * @param string $key
4686 - * @param string $context Either 'display' or 'update'.
4687 - */
4688 - return (bool) apply_filters( 'frm_input_key_is_safe', $safe, $key, $context );
3767 + public static function show_landing_pages() {
3768 + return self::show_new_feature( 'landing' );
4689 3769 }
4690 3770
4691 3771 /**
4692 3772 * @since 5.0.16
4693 3773 *
4694 - * @param string $medium
4695 - *
4696 3774 * @return array
4697 3775 */
4698 3776 public static function get_landing_page_upgrade_data_params( $medium = 'landing' ) {
4699 3777 $params = array(
@@ -4700,9 +3778,8 @@
4700 3778 'medium' => $medium,
4701 3779 'upgrade' => __( 'Form Landing Pages', 'formidable' ),
4702 3780 'message' => __( 'Easily manage a landing page for your form. Upgrade to get form landing pages.', 'formidable' ),
4703 3781 'screenshot' => 'landing.png',
4704 - 'learn-more' => self::get_doc_url( 'landing-page-forms', 'form-landing-page-settings', false ),
4705 3782 );
4706 3783 return self::get_upgrade_data_params( 'landing', $params );
4707 3784 }
4708 3785
@@ -4708,10 +3785,20 @@
4708 3785
4709 3786 /**
4710 3787 * @since 5.0.17
4711 3788 *
3789 + * @param string $plugin
3790 + * @return string|false
3791 + */
3792 + private static function get_plan_required( $plugin ) {
3793 + $link = FrmAddonsController::install_link( $plugin );
3794 + return FrmFormsHelper::get_plan_required( $link );
3795 + }
3796 +
3797 + /**
3798 + * @since 5.0.17
3799 + *
4712 3800 * @param string $feature
4713 - *
4714 3801 * @return bool
4715 3802 */
4716 3803 public static function show_new_feature( $feature ) {
4717 3804 $link = FrmAddonsController::install_link( $feature );
@@ -4718,21 +3805,16 @@
4718 3805 return array_key_exists( 'status', $link ) || array_key_exists( 'class', $link );
4719 3806 }
4720 3807
4721 3808 /**
4722 - * Enhances upgrade data parameters with installation link and plan requirement information.
4723 - *
4724 3809 * @since 5.0.17
4725 3810 *
4726 - * @param string $plugin The plugin slug to get installation data for.
4727 - * @param array $params Initial parameters for the upgrade data.
4728 - * @param bool $detailed Whether to include detailed information.
4729 - *
4730 - * @return array Modified parameters with installation data.
3811 + * @param string $plugin
3812 + * @param array $params
3813 + * @return array
4731 3814 */
4732 - public static function get_upgrade_data_params( $plugin, $params, $detailed = false ) {
3815 + public static function get_upgrade_data_params( $plugin, $params ) {
4733 3816 $link = FrmAddonsController::install_link( $plugin );
4734 -
4735 3817 if ( ! $link ) {
4736 3818 return $params;
4737 3819 }
4738 3820
@@ -4738,20 +3820,15 @@
4738 3820
4739 3821 if ( ! empty( $link['url'] ) && self::pro_is_installed() ) {
4740 3822 $params['oneclick'] = json_encode( $link );
4741 3823 unset( $params['message'] );
4742 -
4743 3824 if ( ! isset( $params['medium'] ) ) {
4744 3825 $params['medium'] = $plugin;
4745 3826 }
4746 3827 } else {
4747 - $params['requires'] = $params['requires'] ?? FrmFormsHelper::get_plan_required( $link );
3828 + $params['requires'] = FrmFormsHelper::get_plan_required( $link );
4748 3829 }
4749 3830
4750 - if ( $detailed ) {
4751 - $params['plugin-status'] = $link['status'] ?? '';
4752 - }
4753 -
4754 3831 return $params;
4755 3832 }
4756 3833
4757 3834 /**
@@ -4760,9 +3837,8 @@
4760 3837 *
4761 3838 * @since 5.0.17
4762 3839 *
4763 3840 * @param string $text
4764 - *
4765 3841 * @return bool
4766 3842 */
4767 3843 public static function ctype_xdigit( $text ) {
4768 3844 if ( function_exists( 'ctype_xdigit' ) ) {
@@ -4777,14 +3853,12 @@
4777 3853 * @since 5.2.01
4778 3854 */
4779 3855 public static function set_current_screen_and_hook_suffix() {
4780 3856 global $hook_suffix;
4781 -
4782 3857 if ( is_null( $hook_suffix ) ) {
4783 3858 // $hook_suffix gets used in substr so make sure it's not null. PHP 8.1 deprecates null in substr.
4784 3859 $hook_suffix = ''; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
4785 3860 }
4786 -
4787 3861 set_current_screen();
4788 3862 }
4789 3863
4790 3864 /**
@@ -4791,9 +3865,9 @@
4791 3865 * Shows pill text.
4792 3866 *
4793 3867 * @since 5.2.02
4794 3868 *
4795 - * @param string|null $text Text in the pill. Default is NEW.
3869 + * @param string $text Text in the pill. Default is NEW.
4796 3870 */
4797 3871 public static function show_pill_text( $text = null ) {
4798 3872 if ( null === $text ) {
4799 3873 $text = __( 'NEW', 'formidable' );
@@ -4806,10 +3880,9 @@
4806 3880 *
4807 3881 * @since 5.2.07
4808 3882 *
4809 3883 * @param mixed $num Number.
4810 - *
4811 - * @return false|int Returns `false` if the passed parameter is not number.
3884 + * @return int|false Returns `false` if the passed parameter is not number.
4812 3885 */
4813 3886 public static function count_decimals( $num ) {
4814 3887 if ( ! is_numeric( $num ) ) {
4815 3888 return false;
@@ -4816,9 +3889,8 @@
4816 3889 }
4817 3890
4818 3891 $num = (string) $num;
4819 3892 $parts = explode( '.', $num );
4820 -
4821 3893 if ( 1 === count( $parts ) ) {
4822 3894 return 0;
4823 3895 }
4824 3896
@@ -4841,9 +3913,9 @@
4841 3913 }
4842 3914
4843 3915 add_filter(
4844 3916 'option_gmt_offset',
4845 - function ( $offset ) {
3917 + function( $offset ) {
4846 3918 if ( ! is_string( $offset ) || is_numeric( $offset ) ) {
4847 3919 // Leave a valid value alone.
4848 3920 return $offset;
4849 3921 }
@@ -4900,20 +3972,17 @@
4900 3972 * @since 5.5.5
4901 3973 *
4902 3974 * @param string $url
4903 3975 * @param string $expected_extension
4904 - *
4905 3976 * @return bool
4906 3977 */
4907 3978 public static function validate_url_is_in_s3_bucket( $url, $expected_extension ) {
4908 - $file_is_in_expected_s3_bucket = str_starts_with( $url, 'https://s3.amazonaws.com/fp.strategy11.com' );
4909 -
3979 + $file_is_in_expected_s3_bucket = 0 === strpos( $url, 'https://s3.amazonaws.com/fp.strategy11.com' );
4910 3980 if ( ! $file_is_in_expected_s3_bucket ) {
4911 3981 return false;
4912 3982 }
4913 3983
4914 3984 $parsed = parse_url( $url );
4915 -
4916 3985 if ( ! is_array( $parsed ) ) {
4917 3986 // URL is malformed.
4918 3987 return false;
4919 3988 }
@@ -4919,13 +3988,74 @@
4919 3988 }
4920 3989
4921 3990 $path = $parsed['path'];
4922 3991 $ext = pathinfo( $path, PATHINFO_EXTENSION );
4923 - // The URL isn't to an XML file.
4924 - return $expected_extension === $ext;
3992 + if ( $expected_extension !== $ext ) {
3993 + // The URL isn't to an XML file.
3994 + return false;
3995 + }
3996 +
3997 + return true;
4925 3998 }
4926 3999
4927 4000 /**
4001 + * @since 4.08
4002 + * @deprecated 4.09.01
4003 + */
4004 + public static function expiring_message() {
4005 + _deprecated_function( __METHOD__, '4.09.01', 'FrmProAddonsController::expiring_message' );
4006 + if ( is_callable( 'FrmProAddonsController::expiring_message' ) ) {
4007 + FrmProAddonsController::expiring_message();
4008 + }
4009 + }
4010 +
4011 + /**
4012 + * Use the WP 4.7 wp_doing_ajax function
4013 + *
4014 + * @since 2.05.07
4015 + * @deprecated 4.04.04
4016 + */
4017 + public static function wp_doing_ajax() {
4018 + _deprecated_function( __METHOD__, '4.04.04', 'wp_doing_ajax' );
4019 + return wp_doing_ajax();
4020 + }
4021 +
4022 + /**
4023 + * @deprecated 4.0
4024 + */
4025 + public static function insert_opt_html( $args ) {
4026 + _deprecated_function( __METHOD__, '4.0', 'FrmFormsHelper::insert_opt_html' );
4027 + FrmFormsHelper::insert_opt_html( $args );
4028 + }
4029 +
4030 + /**
4031 + * @deprecated 3.01
4032 + * @codeCoverageIgnore
4033 + */
4034 + public static function sanitize_array( &$values ) {
4035 + FrmDeprecated::sanitize_array( $values );
4036 + }
4037 +
4038 + /**
4039 + * @since 2.0
4040 + * @deprecated 5.0.13
4041 + *
4042 + * @return string The base Google APIS url for the current version of jQuery UI
4043 + */
4044 + public static function jquery_ui_base_url() {
4045 + _deprecated_function( __FUNCTION__, '5.0.13', 'FrmProAppHelper::jquery_ui_base_url' );
4046 + return is_callable( 'FrmProAppHelper::jquery_ui_base_url' ) ? FrmProAppHelper::jquery_ui_base_url() : '';
4047 + }
4048 +
4049 + /**
4050 + * @since 4.07
4051 + * @deprecated 6.0
4052 + */
4053 + public static function renewal_message() {
4054 + _deprecated_function( __METHOD__, '6.0', 'FrmProAddonsController::renewal_message' );
4055 + }
4056 +
4057 + /**
4928 4058 * Display a dismissable warning message and save its dismissal state.
4929 4059 *
4930 4060 * @since 6.3
4931 4061 *
@@ -4930,9 +4060,8 @@
4930 4060 * @since 6.3
4931 4061 *
4932 4062 * @param string $message The warning message to display.
4933 4063 * @param string $option The unique identifier for the dismissal state of the message and the WP Ajax action.
4934 - *
4935 4064 * @return void
4936 4065 */
4937 4066 public static function add_dismissable_warning_message( $message = '', $option = '' ) {
4938 4067 if ( ! $message || ! $option ) {
@@ -4938,9 +4067,9 @@
4938 4067 if ( ! $message || ! $option ) {
4939 4068 return;
4940 4069 }
4941 4070
4942 - $ajax_callback = function () use ( $option ) {
4071 + $ajax_callback = function() use ( $option ) {
4943 4072 self::dismiss_warning_message( $option );
4944 4073 };
4945 4074
4946 4075 // We're handling JS codes with `doJsonPost` and it adds 'frm_' to the beginning of the action.
@@ -4948,9 +4077,9 @@
4948 4077 add_action( 'wp_ajax_frm_' . $option, $ajax_callback );
4949 4078
4950 4079 add_filter(
4951 4080 'frm_message_list',
4952 - function ( $show_messages ) use ( $message, $option ) {
4081 + function( $show_messages ) use ( $message, $option ) {
4953 4082 if ( get_option( $option, false ) ) {
4954 4083 return $show_messages;
4955 4084 }
4956 4085
@@ -4957,9 +4086,9 @@
4957 4086 $dismiss_icon = self::icon_by_class(
4958 4087 'frmfont frm_close_icon',
4959 4088 array(
4960 4089 'aria-label' => _x( 'Dismiss', 'warning message: close icon label', 'formidable' ),
4961 - 'echo' => false,
4090 + 'echo' => false,
4962 4091 )
4963 4092 );
4964 4093
4965 4094 $show_messages[] = $message;
@@ -4975,9 +4104,8 @@
4975 4104 *
4976 4105 * @since 6.3
4977 4106 *
4978 4107 * @param string $option The unique identifier for the dismissal state of the message.
4979 - *
4980 4108 * @return void
4981 4109 */
4982 4110 public static function dismiss_warning_message( $option = '' ) {
4983 4111 self::permission_check( 'frm_change_settings' );
@@ -4983,9 +4111,9 @@
4983 4111 self::permission_check( 'frm_change_settings' );
4984 4112 check_ajax_referer( 'frm_ajax', 'nonce' );
4985 4113
4986 4114 if ( $option ) {
4987 - update_option( $option, true, false );
4115 + update_option( $option, true, 'no' );
4988 4116 }
4989 4117
4990 4118 wp_send_json_success();
4991 4119 }
@@ -4999,166 +4127,16 @@
4999 4127 * @return string
5000 4128 */
5001 4129 public static function copy_for_lite_license() {
5002 4130 $message = __( 'You\'re using Formidable Forms Lite - no license needed. Enjoy!', 'formidable' ) . ' 🙂';
5003 - return apply_filters( 'frm_license_type_text', $message );
5004 - }
5005 4131
5006 - /**
5007 - * Removes scripts that are unnecessarily loaded across the pages!
5008 - *
5009 - * @since 6.9
5010 - *
5011 - * @return void
5012 - */
5013 - public static function dequeue_extra_global_scripts() {
5014 - wp_dequeue_script( 'frm-surveys-admin' );
5015 - wp_dequeue_script( 'frm-quizzes-form-action' );
5016 - }
5017 -
5018 - /**
5019 - * Shows tooltip icon.
5020 - *
5021 - * @since 6.12
5022 - *
5023 - * @param string $tooltip_text Tooltip text.
5024 - * @param array $atts Tooltip wrapper HTML attributes.
5025 - *
5026 - * @return void
5027 - */
5028 - public static function tooltip_icon( $tooltip_text, $atts = array() ) {
5029 - $atts['title'] = $tooltip_text;
5030 -
5031 - if ( isset( $atts['class'] ) ) {
5032 - $atts['class'] .= ' frm_help';
5033 - } else {
5034 - $atts['class'] = 'frm_help';
5035 - }
5036 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
5037 - ?>
5038 - <span <?php self::array_to_html_params( $atts, true ); ?>>
5039 - <?php self::icon_by_class( 'frmfont frm_tooltip_icon' ); ?>
5040 - </span>
5041 - <?php
5042 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
5043 - }
5044 -
5045 - /**
5046 - * Prints errors for settings in onboarding wizard or template settings.
5047 - *
5048 - * @since 6.15
5049 - *
5050 - * @param array $args Args.
5051 - *
5052 - * @return void
5053 - */
5054 - public static function print_setting_error( $args ) {
5055 - $args = wp_parse_args(
5056 - $args,
5057 - array(
5058 - 'id' => '',
5059 - 'errors' => array(),
5060 - 'class' => '',
5061 - )
5062 - );
5063 -
5064 - $args['class'] .= ' frm-validation-error frm-mt-xs frm_hidden';
5065 -
5066 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
5067 - ?>
5068 - <span id="<?php echo esc_attr( $args['id'] ); ?>" class="<?php echo esc_attr( $args['class'] ); ?>">
5069 - <?php
5070 - if ( is_array( $args['errors'] ) ) {
5071 - foreach ( $args['errors'] as $key => $msg ) {
5072 - ?>
5073 - <span frm-error="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $msg ); ?></span>
5074 - <?php
5075 - }
5076 - } else {
5077 - echo '<span>' . esc_html( $args['errors'] ) . '</span>';
4132 + if ( is_callable( 'FrmProAddonsController::get_readable_license_type' ) && ! class_exists( 'FrmProDashboardController' ) ) {
4133 + // Manage PRO versions without PRO dashboard functionality.
4134 + $license_type = FrmProAddonsController::get_readable_license_type();
4135 + if ( 'lite' !== strtolower( $license_type ) ) {
4136 + $message = 'Formidable Pro ' . $license_type;
5078 4137 }
5079 - ?>
5080 - </span>
5081 - <?php
5082 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
5083 - }
5084 -
5085 - /**
5086 - * Check if GDPR is enabled.
5087 - *
5088 - * @since 6.19
5089 - *
5090 - * @return bool
5091 - */
5092 - public static function is_gdpr_enabled() {
5093 - $frm_settings = self::get_settings();
5094 - return $frm_settings->enable_gdpr || $frm_settings->no_ips || $frm_settings->custom_header_ip || $frm_settings->no_gdpr_cookies;
5095 - }
5096 -
5097 - /**
5098 - * Check if GDPR cookies are disabled.
5099 - *
5100 - * @since 6.19
5101 - *
5102 - * @return bool
5103 - */
5104 - public static function no_gdpr_cookies() {
5105 - $frm_settings = self::get_settings();
5106 - return $frm_settings->enable_gdpr && $frm_settings->no_gdpr_cookies;
5107 - }
5108 -
5109 - /**
5110 - * Check if a string is valid UTF-8.
5111 - *
5112 - * @since 6.24
5113 - *
5114 - * @param string|null $string The string to check.
5115 - *
5116 - * @return bool
5117 - */
5118 - public static function is_valid_utf8( $string ) {
5119 - if ( is_null( $string ) ) {
5120 - // Return true so we do not attempt to change encoding on a null value.
5121 - return true;
5122 4138 }
5123 4139
5124 - // wp_is_valid_utf8 is added in WP 6.9.
5125 - if ( function_exists( 'wp_is_valid_utf8' ) ) {
5126 - return wp_is_valid_utf8( $string );
5127 - }
5128 -
5129 - // As of WP 6.9, seems_utf8 is deprecated.
5130 - return function_exists( 'seems_utf8' ) ? seems_utf8( $string ) : false;
5131 - }
5132 -
5133 - /**
5134 - * Get a documentation URL with UTM parameters and affiliate tracking.
5135 - *
5136 - * @since 6.26
5137 - *
5138 - * @param string $path The relative path to append to the base URL.
5139 - * @param string $campaign The campaign to use for UTM parameters.
5140 - * @param bool $add_kb_base Whether to prepend 'knowledgebase/' to the path. Default true.
5141 - *
5142 - * @return string The processed URL with UTM parameters and affiliate tracking.
5143 - */
5144 - public static function get_doc_url( $path, $campaign, $add_kb_base = true ) {
5145 - $path = trim( $path, '/' );
5146 -
5147 - if ( $add_kb_base ) {
5148 - $path = 'knowledgebase/' . $path;
5149 - }
5150 -
5151 - return self::maybe_add_missing_utm( 'https://formidableforms.com/' . $path, array( 'campaign' => $campaign ) );
5152 - }
5153 -
5154 - /**
5155 - * @since 5.0.16
5156 - * @deprecated 6.26
5157 - *
5158 - * @return bool
5159 - */
5160 - public static function show_landing_pages() {
5161 - _deprecated_function( __METHOD__, '6.26' );
5162 - return true;
4140 + return apply_filters( 'frm_license_type_text', $message );
5163 4141 }
5164 4142 }