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