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