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