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