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