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