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