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