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