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