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