PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7.2
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/FrmFormsHelper.php +290 -639 6.27 → 6.7.2 View file →
@@ -5,43 +5,21 @@
5 5
6 6 class FrmFormsHelper {
7 7
8 8 /**
9 - * Store and re-use field type data for the insert_opt_html function (to avoid multiple calls to FrmField::all_field_selection).
10 - *
11 - * @since 6.10
12 - *
13 - * @var array|null
14 - */
15 - private static $field_type_data_for_insert_opt_html;
16 -
17 - /**
18 9 * @since 2.2.10
19 - *
20 - * @return string
21 10 */
22 11 public static function form_error_class() {
23 12 return apply_filters( 'frm_form_error_class', 'frm_error_style' );
24 13 }
25 14
26 - /**
27 - * @param string $key
28 - * @param false|object $form
29 - *
30 - * @return string
31 - */
32 15 public static function get_direct_link( $key, $form = false ) {
33 16 $target_url = esc_url( admin_url( 'admin-ajax.php?action=frm_forms_preview&form=' . $key ) );
34 - return apply_filters( 'frm_direct_link', $target_url, $key, $form );
17 + $target_url = apply_filters( 'frm_direct_link', $target_url, $key, $form );
18 +
19 + return $target_url;
35 20 }
36 21
37 - /**
38 - * @param string $field_name
39 - * @param int|string $field_value
40 - * @param array $args
41 - *
42 - * @return void
43 - */
44 22 public static function forms_dropdown( $field_name, $field_value = '', $args = array() ) {
45 23 $defaults = array(
46 24 'blank' => true,
47 25 'field_id' => false,
@@ -56,9 +34,8 @@
56 34 $args['field_id'] = $field_name;
57 35 }
58 36
59 37 $query = array();
60 -
61 38 if ( $args['exclude'] ) {
62 39 $query['id !'] = $args['exclude'];
63 40 }
64 41
@@ -72,13 +49,13 @@
72 49 <select name="<?php echo esc_attr( $field_name ); ?>"
73 50 id="<?php echo esc_attr( $args['field_id'] ); ?>"
74 51 <?php echo wp_strip_all_tags( implode( ' ', $add_html ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
75 52 <?php if ( $args['blank'] ) { ?>
76 - <option value=""><?php echo $args['blank'] == 1 ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; // phpcs:ignore Universal.Operators.StrictComparisons ?></option>
53 + <option value=""><?php echo ( $args['blank'] == 1 ) ? ' ' : '- ' . esc_attr( $args['blank'] ) . ' -'; ?></option>
77 54 <?php } ?>
78 55 <?php foreach ( $forms as $form ) { ?>
79 56 <option value="<?php echo esc_attr( $form->id ); ?>" <?php selected( $field_value, $form->id ); ?>>
80 - <?php echo esc_html( '' === $form->name ? self::get_no_title_text() : FrmAppHelper::truncate( $form->name, 50 ) . ( $form->parent_form_id ? __( ' (child)', 'formidable' ) : '' ) ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
57 + <?php echo esc_html( '' === $form->name ? __( '(no title)', 'formidable' ) : FrmAppHelper::truncate( $form->name, 50 ) . ( $form->parent_form_id ? __( ' (child)', 'formidable' ) : '' ) ); ?>
81 58 </option>
82 59 <?php } ?>
83 60 </select>
84 61 <?php
@@ -84,28 +61,24 @@
84 61 <?php
85 62 }
86 63
87 64 /**
88 - * @since 2.0.6
89 - *
90 65 * @param string $class
91 66 * @param string $param
92 67 * @param array $add_html
93 68 *
94 - * @return void
69 + * @since 2.0.6
95 70 */
96 71 public static function add_html_attr( $class, $param, &$add_html ) {
97 - if ( $class ) {
72 + if ( ! empty( $class ) ) {
98 73 $add_html[ $param ] = sanitize_title( $param ) . '="' . esc_attr( trim( sanitize_text_field( $class ) ) ) . '"';
99 74 }
100 75 }
101 76
102 77 /**
103 - * @param false|object|string $selected - The label for the placeholder, or the form object.
104 - *
105 - * @return void
78 + * @param string|object|false $selected - The label for the placeholder, or the form object.
106 79 */
107 - public static function form_switcher( $selected = false ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh, Generic.Metrics.CyclomaticComplexity.MaxExceeded, SlevomatCodingStandard.Files.LineLength.LineTooLong
80 + public static function form_switcher( $selected = false ) {
108 81 $where = apply_filters( 'frm_forms_dropdown', array(), '' );
109 82 $forms = FrmForm::get_published_forms( $where );
110 83
111 84 $args = array(
@@ -111,9 +84,8 @@
111 84 $args = array(
112 85 'id' => 0,
113 86 'form' => 0,
114 87 );
115 -
116 88 if ( isset( $_GET['id'] ) && ! isset( $_GET['form'] ) ) {
117 89 unset( $args['form'] );
118 90 } elseif ( isset( $_GET['form'] ) && ! isset( $_GET['id'] ) ) {
119 91 unset( $args['id'] );
@@ -119,13 +91,12 @@
119 91 unset( $args['id'] );
120 92 }
121 93
122 94 $frm_action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
123 -
124 - if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $frm_action, array( 'edit', 'show', 'destroy', 'destroy_all' ), true ) ) {
95 + if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $frm_action, array( 'edit', 'show', 'destroy', 'destroy_all' ) ) ) {
125 96 $args['frm_action'] = 'list';
126 97 $args['form'] = 0;
127 - } elseif ( FrmAppHelper::is_admin_page( 'formidable' ) && in_array( $frm_action, array( 'new', 'duplicate' ), true ) ) {
98 + } elseif ( FrmAppHelper::is_admin_page( 'formidable' ) && in_array( $frm_action, array( 'new', 'duplicate' ) ) ) {
128 99 $args['frm_action'] = 'edit';
129 100 } elseif ( FrmAppHelper::is_style_editor_page() ) {
130 101 // Avoid passing style into form switcher on style page.
131 102 unset( $args['id'] );
@@ -131,28 +102,25 @@
131 102 unset( $args['id'] );
132 103 $query_args = array(
133 104 'page' => 'formidable-styles',
134 105 );
135 -
136 106 if ( $frm_action ) {
137 107 $query_args['frm_action'] = $frm_action;
138 108 }
139 -
140 109 $base = add_query_arg( $query_args, admin_url( 'admin.php' ) );
141 110 } elseif ( isset( $_GET['post'] ) ) {
142 111 $args['form'] = 0;
143 112 $base = admin_url( 'edit.php?post_type=frm_display' );
144 - }//end if
113 + }
145 114
146 115 $form_id = 0;
147 -
148 116 if ( is_object( $selected ) ) {
149 117 $form_id = $selected->id;
150 118 $selected = $selected->name;
151 119 }
152 120
153 - $name = $selected === false ? __( 'Switch Form', 'formidable' ) : $selected;
154 - $name = '' === $name || is_null( $name ) ? self::get_no_title_text() : strip_tags( $name );
121 + $name = ( $selected === false ) ? __( 'Switch Form', 'formidable' ) : $selected;
122 + $name = '' === $name ? __( '(no title)', 'formidable' ) : strip_tags( $name );
155 123 $truncated_name = FrmAppHelper::truncate( $name, 25 );
156 124
157 125 if ( count( $forms ) < 2 ) {
158 126 ?>
@@ -184,10 +152,8 @@
184 152 array(
185 153 'input_id' => 'dropform',
186 154 'placeholder' => __( 'Search Forms', 'formidable' ),
187 155 'tosearch' => 'frm-dropdown-form',
188 - // Specify a value to avoid the $_REQUEST['s'] default value.
189 - 'value' => '',
190 156 )
191 157 );
192 158 ?>
193 159 </li>
@@ -201,15 +167,14 @@
201 167
202 168 if ( isset( $args['id'] ) ) {
203 169 $args['id'] = $form->id;
204 170 }
205 -
206 171 if ( isset( $args['form'] ) ) {
207 172 $args['form'] = $form->id;
208 173 }
209 174
210 175 $url = isset( $base ) ? add_query_arg( $args, $base ) : add_query_arg( $args );
211 - $form_name = empty( $form->name ) ? self::get_no_title_text() : $form->name;
176 + $form_name = empty( $form->name ) ? __( '(no title)', 'formidable' ) : $form->name;
212 177 ?>
213 178 <li class="frm-dropdown-form">
214 179 <a href="<?php echo esc_url( $url ); ?>" tabindex="-1" class="frm-justify-between">
215 180 <?php echo esc_html( $form_name ); ?>
@@ -234,39 +199,46 @@
234 199 <?php
235 200 }
236 201
237 202 /**
238 - * @param string $col
239 - * @param string $sort_col
240 - * @param string $sort_dir
203 + * @since 3.05
204 + * @deprecated 4.0
241 205 *
242 - * @return void
206 + * @param array $values The form array.
243 207 */
208 + public static function builder_submit_button( $values ) {
209 + FrmDeprecated::builder_submit_button( $values );
210 + }
211 +
244 212 public static function get_sortable_classes( $col, $sort_col, $sort_dir ) {
245 - echo $sort_col == $col ? 'sorted' : 'sortable'; // phpcs:ignore Universal.Operators.StrictComparisons
246 - echo $sort_col == $col && $sort_dir === 'desc' ? ' asc' : ' desc'; // phpcs:ignore Universal.Operators.StrictComparisons
213 + echo ( $sort_col == $col ) ? 'sorted' : 'sortable';
214 + echo ( $sort_col == $col && $sort_dir === 'desc' ) ? ' asc' : ' desc';
247 215 }
248 216
249 217 /**
250 218 * @since 3.0
251 - *
252 - * @param array|string $field_type
253 - *
254 - * @return string
255 219 */
256 220 public static function get_field_link_name( $field_type ) {
257 - return is_array( $field_type ) ? $field_type['name'] : $field_type;
221 + if ( is_array( $field_type ) ) {
222 + $field_label = $field_type['name'];
223 + } else {
224 + $field_label = $field_type;
225 + }
226 +
227 + return $field_label;
258 228 }
259 229
260 230 /**
261 231 * @since 3.0
262 - *
263 - * @param array|string $field_type
264 - *
265 - * @return string
266 232 */
267 233 public static function get_field_link_icon( $field_type ) {
268 - return is_array( $field_type ) && isset( $field_type['icon'] ) ? $field_type['icon'] : 'frmfont frm_pencil_icon';
234 + if ( is_array( $field_type ) && isset( $field_type['icon'] ) ) {
235 + $icon = $field_type['icon'];
236 + } else {
237 + $icon = 'frm_icon_font frm_pencil_icon';
238 + }
239 +
240 + return $icon;
269 241 }
270 242
271 243 /**
272 244 * Get the invalid form error message
@@ -278,15 +250,14 @@
278 250 * @return string
279 251 */
280 252 public static function get_invalid_error_message( $args ) {
281 253 $settings_args = $args;
282 -
283 254 if ( isset( $args['form'] ) ) {
284 255 $settings_args['current_form'] = $args['form']->id;
285 256 }
286 257
287 258 $frm_settings = FrmAppHelper::get_settings( $settings_args );
288 - $invalid_msg = do_shortcode( $frm_settings->invalid_msg );
259 + $invalid_msg = do_shortcode( $frm_settings->invalid_msg );
289 260 return apply_filters( 'frm_invalid_error_message', $invalid_msg, $args );
290 261 }
291 262
292 263 /**
@@ -297,48 +268,24 @@
297 268 * @type stdClass $form
298 269 * @type int $entry_id
299 270 * @type string $class
300 271 * }
301 - *
302 272 * @return string
303 273 */
304 274 public static function get_success_message( $atts ) {
305 275 $message = apply_filters( 'frm_content', $atts['message'], $atts['form'], $atts['entry_id'] );
306 -
307 - // Only autop if the message includes line breaks.
308 - $autop = str_contains( $message, "\n" );
309 -
310 - /**
311 - * Filters whether to autop the success message.
312 - * This is false by default if the message does not include line breaks.
313 - *
314 - * @since 6.23
315 - *
316 - * @param bool $autop
317 - * @param string $message
318 - * @param object $form
319 - */
320 - $autop = (bool) apply_filters( 'frm_wpautop_success_message', $autop, $message, $atts['form'] );
321 -
322 - if ( $autop ) {
323 - $message = FrmAppHelper::use_wpautop( $message );
324 - }
325 -
326 - $message = do_shortcode( $message );
327 - return '<div class="' . esc_attr( $atts['class'] ) . '" role="status">' . $message . '</div>';
276 + $message = do_shortcode( FrmAppHelper::use_wpautop( $message ) );
277 + $message = '<div class="' . esc_attr( $atts['class'] ) . '" role="status">' . $message . '</div>';
278 + return $message;
328 279 }
329 280
330 281 /**
331 282 * Used when a form is created
332 - *
333 - * @param array $values
334 - *
335 - * @return array
336 283 */
337 284 public static function setup_new_vars( $values = array() ) {
338 285 global $wpdb;
339 286
340 - if ( $values ) {
287 + if ( ! empty( $values ) ) {
341 288 $post_values = $values;
342 289 } else {
343 290 $values = array();
344 291 $post_values = ! empty( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
@@ -347,9 +294,8 @@
347 294 $defaults = array(
348 295 'name' => '',
349 296 'description' => '',
350 297 );
351 -
352 298 foreach ( $defaults as $var => $default ) {
353 299 if ( ! isset( $values[ $var ] ) ) {
354 300 $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
355 301 }
@@ -364,9 +310,8 @@
364 310 'is_template' => 0,
365 311 'status' => 'published',
366 312 'parent_form_id' => 0,
367 313 );
368 -
369 314 foreach ( $defaults as $var => $default ) {
370 315 if ( ! isset( $values[ $var ] ) ) {
371 316 $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
372 317 }
@@ -373,9 +318,9 @@
373 318 }
374 319 unset( $defaults );
375 320
376 321 if ( ! isset( $values['form_key'] ) ) {
377 - $values['form_key'] = $post_values && isset( $post_values['form_key'] ) ? $post_values['form_key'] : FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_forms', 'form_key' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
322 + $values['form_key'] = ( $post_values && isset( $post_values['form_key'] ) ) ? $post_values['form_key'] : FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_forms', 'form_key' );
378 323 }
379 324
380 325 $values = self::fill_default_opts( $values, false, $post_values );
381 326 $values['custom_style'] = FrmAppHelper::custom_style_value( $post_values );
@@ -384,22 +329,16 @@
384 329 }
385 330
386 331 /**
387 332 * Used when editing a form
388 - *
389 - * @param array $values
390 - * @param object $record
391 - * @param array $post_values
392 - *
393 - * @return array
394 333 */
395 334 public static function setup_edit_vars( $values, $record, $post_values = array() ) {
396 - if ( ! $post_values ) {
335 + if ( empty( $post_values ) ) {
397 336 $post_values = wp_unslash( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
398 337 }
399 338
400 - $values['form_key'] = $post_values['form_key'] ?? $record->form_key;
401 - $values['is_template'] = $post_values['is_template'] ?? $record->is_template;
339 + $values['form_key'] = isset( $post_values['form_key'] ) ? $post_values['form_key'] : $record->form_key;
340 + $values['is_template'] = isset( $post_values['is_template'] ) ? $post_values['is_template'] : $record->is_template;
402 341 $values['status'] = $record->status;
403 342
404 343 $values = self::fill_default_opts( $values, $record, $post_values );
405 344
@@ -405,31 +344,23 @@
405 344
406 345 return apply_filters( 'frm_setup_edit_form_vars', $values );
407 346 }
408 347
409 - /**
410 - * @param array $values
411 - * @param false|object $record
412 - * @param array|false $post_values
413 - *
414 - * @return array
415 - */
416 - public static function fill_default_opts( $values, $record, $post_values ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
348 + public static function fill_default_opts( $values, $record, $post_values ) {
417 349
418 350 $defaults = self::get_default_opts();
419 -
420 351 foreach ( $defaults as $var => $default ) {
421 352 if ( is_array( $default ) ) {
422 353 if ( ! isset( $values[ $var ] ) ) {
423 - $values[ $var ] = $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : array();
354 + $values[ $var ] = ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : array();
424 355 }
425 356
426 357 foreach ( $default as $k => $v ) {
427 - $values[ $var ][ $k ] = $post_values && isset( $post_values[ $var ][ $k ] ) ? $post_values[ $var ][ $k ] : ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) ? $record->options[ $var ][ $k ] : $v ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
358 + $values[ $var ][ $k ] = ( $post_values && isset( $post_values[ $var ][ $k ] ) ) ? $post_values[ $var ][ $k ] : ( ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) ) ? $record->options[ $var ][ $k ] : $v );
428 359
429 360 if ( is_array( $v ) ) {
430 361 foreach ( $v as $k1 => $v1 ) {
431 - $values[ $var ][ $k ][ $k1 ] = $post_values && isset( $post_values[ $var ][ $k ][ $k1 ] ) ? $post_values[ $var ][ $k ][ $k1 ] : ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) && isset( $record->options[ $var ][ $k ][ $k1 ] ) ? $record->options[ $var ][ $k ][ $k1 ] : $v1 ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
362 + $values[ $var ][ $k ][ $k1 ] = ( $post_values && isset( $post_values[ $var ][ $k ][ $k1 ] ) ) ? $post_values[ $var ][ $k ][ $k1 ] : ( ( $record && isset( $record->options[ $var ] ) && isset( $record->options[ $var ][ $k ] ) && isset( $record->options[ $var ][ $k ][ $k1 ] ) ) ? $record->options[ $var ][ $k ][ $k1 ] : $v1 );
432 363 unset( $k1, $v1 );
433 364 }
434 365 }
435 366
@@ -435,9 +366,9 @@
435 366
436 367 unset( $k, $v );
437 368 }
438 369 } else {
439 - $values[ $var ] = $post_values && isset( $post_values['options'][ $var ] ) ? $post_values['options'][ $var ] : ( $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : $default ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
370 + $values[ $var ] = ( $post_values && isset( $post_values['options'][ $var ] ) ) ? $post_values['options'][ $var ] : ( ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : $default );
440 371 }
441 372
442 373 unset( $var, $default );
443 374 }//end foreach
@@ -456,9 +387,9 @@
456 387 'success_action' => 'message',
457 388 'success_msg' => $frm_settings->success_msg,
458 389 'show_form' => 0,
459 390 'akismet' => '',
460 - 'stopforumspam' => 0,
391 + 'honeypot' => 'basic',
461 392 'antispam' => 0,
462 393 'no_save' => 0,
463 394 'ajax_load' => 0,
464 395 'js_validate' => 0,
@@ -473,20 +404,17 @@
473 404 );
474 405 }
475 406
476 407 /**
477 - * @since 2.0.6
478 - *
479 408 * @param array $options
480 409 * @param array $values
481 410 *
482 - * @return void
411 + * @since 2.0.6
483 412 */
484 413 public static function fill_form_options( &$options, $values ) {
485 414 $defaults = self::get_default_opts();
486 -
487 415 foreach ( $defaults as $var => $default ) {
488 - $options[ $var ] = $values['options'][ $var ] ?? $default;
416 + $options[ $var ] = isset( $values['options'][ $var ] ) ? $values['options'][ $var ] : $default;
489 417 unset( $var, $default );
490 418 }
491 419 }
492 420
@@ -491,10 +419,8 @@
491 419 }
492 420
493 421 /**
494 422 * @param string $loc
495 - *
496 - * @return string
497 423 */
498 424 public static function get_default_html( $loc ) {
499 425 if ( $loc === 'submit' ) {
500 426 $draft_link = self::get_draft_link();
@@ -519,13 +445,12 @@
519 445
520 446 return $default_html;
521 447 }
522 448
523 - /**
524 - * @return string
525 - */
526 449 public static function get_draft_link() {
527 - return '[if save_draft]<button class="frm_save_draft" [draft_hook]>[draft_label]</button>[/if save_draft]';
450 + $link = '[if save_draft]<a href="#" tabindex="0" class="frm_save_draft" [draft_hook]>[draft_label]</a>[/if save_draft]';
451 +
452 + return $link;
528 453 }
529 454
530 455 /**
531 456 * Gets start over button shortcode.
@@ -537,21 +462,11 @@
537 462 public static function get_start_over_shortcode() {
538 463 return '[if start_over]<a href="#" tabindex="0" class="frm_start_over" [start_over_hook]>[start_over_label]</a>[/if start_over]';
539 464 }
540 465
541 - /**
542 - * @param string $html
543 - * @param object $form
544 - * @param string $submit
545 - * @param object|null $form_action
546 - * @param array $values
547 - *
548 - * @return void
549 - */
550 466 public static function get_custom_submit( $html, $form, $submit, $form_action, $values ) {
551 467 $button = self::replace_shortcodes( $html, $form, $submit, $form_action, $values );
552 -
553 - if ( ! str_contains( $button, '[button_action]' ) ) {
468 + if ( ! strpos( $button, '[button_action]' ) ) {
554 469 echo FrmAppHelper::maybe_kses( $button ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
555 470 return;
556 471 }
557 472
@@ -558,21 +473,18 @@
558 473 /**
559 474 * @since 5.0.06
560 475 */
561 476 $button = apply_filters( 'frm_submit_button_html', $button, compact( 'form' ) );
562 -
563 477 if ( FrmAppHelper::should_never_allow_unfiltered_html() ) {
564 478 $button = FrmAppHelper::kses_submit_button( $button );
565 479 }
566 -
567 480 $button_parts = explode( '[button_action]', $button );
568 - $classes = apply_filters( 'frm_submit_button_class', array(), $form );
569 481
570 - if ( $classes ) {
482 + $classes = apply_filters( 'frm_submit_button_class', array(), $form );
483 + if ( ! empty( $classes ) ) {
571 484 $classes = implode( ' ', $classes );
572 - $button_class = 'frm_button_submit';
573 -
574 - if ( preg_match( '/\bclass="[^"]*?\b' . preg_quote( $button_class, '/' ) . '\b[^"]*?"/', $button_parts[0] ) ) {
485 + $button_class = ' class="frm_button_submit';
486 + if ( strpos( $button_parts[0], $button_class ) !== false ) {
575 487 $button_parts[0] = str_replace( $button_class, $button_class . ' ' . esc_attr( $classes ), $button_parts[0] );
576 488 } else {
577 489 $button_parts[0] .= ' class="' . esc_attr( $classes ) . '"';
578 490 }
@@ -584,56 +496,54 @@
584 496 }
585 497
586 498 /**
587 499 * @since 4.0
588 - *
589 - * @return array
590 500 */
591 501 public static function html_shortcodes() {
592 502 $codes = array(
593 - 'id' => array(
503 + 'id' => array(
594 504 'label' => __( 'Field ID', 'formidable' ),
595 505 'class' => 'show_field_custom_html',
596 506 ),
597 - 'key' => array(
507 + 'key' => array(
598 508 'label' => __( 'Field Key', 'formidable' ),
599 509 'class' => 'show_field_custom_html',
600 510 ),
601 - 'field_name' => array(
511 + 'field_name' => array(
602 512 'label' => __( 'Field Name', 'formidable' ),
603 513 'class' => 'show_field_custom_html',
604 514 ),
605 - 'description' => array(
515 + 'description' => array(
606 516 'label' => __( 'Field Description', 'formidable' ),
607 517 'class' => 'show_field_custom_html',
608 518 ),
609 - 'label_position' => array(
519 + 'label_position' => array(
610 520 'label' => __( 'Label Position', 'formidable' ),
611 521 'class' => 'show_field_custom_html',
612 522 ),
613 - 'required_label' => array(
523 + 'required_label' => array(
614 524 'label' => __( 'Required Label', 'formidable' ),
615 525 'class' => 'show_field_custom_html',
616 526 ),
617 - 'input' => array(
527 + 'input' => array(
618 528 'label' => __( 'Input Field', 'formidable' ),
619 529 'class' => 'show_field_custom_html',
620 530 ),
621 - 'input opt=1' => array(
531 + 'input opt=1' => array(
622 532 'label' => __( 'Single Option', 'formidable' ),
623 533 'title' => __( 'Show a single radio or checkbox option by replacing 1 with the order of the option', 'formidable' ),
624 534 'class' => 'show_field_custom_html',
625 535 ),
626 - 'input label=0' => array(
536 + 'input label=0' => array(
627 537 'label' => __( 'Hide Option Label', 'formidable' ),
628 538 'class' => 'show_field_custom_html',
629 539 ),
630 - 'required_class' => array(
540 + 'required_class' => array(
631 541 'label' => __( 'Required Class', 'formidable' ),
632 542 'title' => __( 'Add class name if field is required', 'formidable' ),
633 543 'class' => 'show_field_custom_html',
634 544 ),
635 - 'error_class' => array(
545 + 'error_class' => array(
636 546 'label' => __( 'Error Class', 'formidable' ),
637 547 'title' => __( 'Add class name if field has an error on form submit', 'formidable' ),
638 548 'class' => 'show_field_custom_html',
639 549 ),
@@ -654,13 +564,13 @@
654 564 'label' => __( 'Delete Entry Link', 'formidable' ),
655 565 'class' => 'show_before_html show_after_html',
656 566 ),
657 567
658 - 'button_label' => array(
568 + 'button_label' => array(
659 569 'label' => __( 'Button Label', 'formidable' ),
660 570 'class' => 'show_submit_html',
661 571 ),
662 - 'button_action' => array(
572 + 'button_action' => array(
663 573 'label' => __( 'Button Hook', 'formidable' ),
664 574 'class' => 'show_submit_html',
665 575 ),
666 576 );
@@ -672,17 +582,14 @@
672 582 }
673 583
674 584 /**
675 585 * @since 4.0
676 - *
677 586 * @param array $args
678 - *
679 - * @return void
680 587 */
681 588 public static function insert_opt_html( $args ) {
682 - $class = $args['class'] ?? '';
683 - $fields = self::get_field_type_data_for_insert_opt_html();
684 - $field = $fields[ $args['type'] ] ?? array();
589 + $class = isset( $args['class'] ) ? $args['class'] : '';
590 + $fields = FrmField::all_field_selection();
591 + $field = isset( $fields[ $args['type'] ] ) ? $fields[ $args['type'] ] : array();
685 592
686 593 self::prepare_field_type( $field );
687 594
688 595 if ( ! isset( $field['icon'] ) ) {
@@ -689,9 +596,8 @@
689 596 $field['icon'] = 'frmfont frm_pencil_icon';
690 597 }
691 598
692 599 $possible_email_field = FrmFieldFactory::field_has_property( $args['type'], 'holds_email_values' );
693 -
694 600 if ( $possible_email_field ) {
695 601 $class .= ' show_frm_not_email_to';
696 602 }
697 603
@@ -697,32 +603,23 @@
697 603
698 604 if ( 'url' === $args['type'] ) {
699 605 $class .= ' frm_insert_url';
700 606 }
701 -
702 - $truncated_name = FrmAppHelper::truncate( $args['name'], 60 );
703 -
704 607 ?>
705 608 <li class="<?php echo esc_attr( $class ); ?>">
706 - <a href="javascript:void(0)" class="frmids frm_insert_code" data-code="<?php echo esc_attr( $args['id'] ); ?>">
707 - <?php
708 - if ( isset( $field['icon'] ) ) {
709 - FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) );
710 - }
711 -
712 - echo esc_html( $truncated_name );
713 - ?>
714 - <span>[<?php echo esc_attr( $args['id_label'] ?? $args['id'] ); ?>]</span>
609 + <a href="javascript:void(0)" class="frmids frm_insert_code"
610 + data-code="<?php echo esc_attr( $args['id'] ); ?>">
611 + <?php FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) ); ?>
612 + <?php echo esc_attr( FrmAppHelper::truncate( $args['name'], 60 ) ); ?>
613 + <span>[<?php echo esc_attr( isset( $args['id_label'] ) ? $args['id_label'] : $args['id'] ); ?>]</span>
715 614 </a>
716 - <a href="javascript:void(0)" class="frmkeys frm_insert_code frm_hidden" data-code="<?php echo esc_attr( $args['key'] ); ?>">
717 - <?php
718 - if ( isset( $field['icon'] ) ) {
719 - FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) );
720 - }
721 -
722 - echo esc_html( $truncated_name );
723 - ?>
724 - <span>[<?php echo esc_attr( FrmAppHelper::truncate( $args['key_label'] ?? $args['key'], 7 ) ); ?>]</span>
615 + <a href="javascript:void(0)" class="frmkeys frm_insert_code frm_hidden"
616 + data-code="<?php echo esc_attr( $args['key'] ); ?>">
617 + <?php if ( isset( $field['icon'] ) ) { ?>
618 + <?php FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) ); ?>
619 + <?php } ?>
620 + <?php echo esc_attr( FrmAppHelper::truncate( $args['name'], 60 ) ); ?>
621 + <span>[<?php echo esc_attr( FrmAppHelper::truncate( isset( $args['key_label'] ) ? $args['key_label'] : $args['key'], 7 ) ); ?>]</span>
725 622 </a>
726 623 </li>
727 624 <?php
728 625 }
@@ -727,28 +624,10 @@
727 624 <?php
728 625 }
729 626
730 627 /**
731 - * Store and re-use field selection data for use when outputting shortcodes options in shortcode pop up.
732 - * This significantly improves performance by avoiding repeat calls to FrmField::all_field_selection.
733 - *
734 - * @since 6.10
735 - *
736 - * @return array
737 - */
738 - private static function get_field_type_data_for_insert_opt_html() {
739 - if ( ! isset( self::$field_type_data_for_insert_opt_html ) ) {
740 - self::$field_type_data_for_insert_opt_html = FrmField::all_field_selection();
741 - }
742 - return self::$field_type_data_for_insert_opt_html;
743 - }
744 -
745 - /**
746 628 * @since 4.0
747 - *
748 629 * @param array $args
749 - *
750 - * @return void
751 630 */
752 631 public static function insert_code_html( $args ) {
753 632 $defaults = array(
754 633 'class' => '',
@@ -778,18 +657,14 @@
778 657 * Some field types in add-ons may have been added with only
779 658 * a field type and name.
780 659 *
781 660 * @since 4.0
782 - *
783 - * @param array|string $field
784 - *
785 - * @return void
786 661 */
787 662 public static function prepare_field_type( &$field ) {
788 663 if ( ! is_array( $field ) ) {
789 664 $field = array(
790 665 'name' => $field,
791 - 'icon' => 'frmfont frm_pencil_icon',
666 + 'icon' => 'frm_icon_font frm_pencil_icon',
792 667 );
793 668 }
794 669 }
795 670
@@ -797,16 +672,14 @@
797 672 * Automatically add end section fields if they don't exist (2.0 migration)
798 673 *
799 674 * @since 2.0
800 675 *
801 - * @param object $form
802 - * @param array $fields
803 - * @param bool $reset_fields
804 - *
805 - * @return void
676 + * @param object $form
677 + * @param array $fields
678 + * @param boolean $reset_fields
806 679 */
807 680 public static function auto_add_end_section_fields( $form, $fields, &$reset_fields ) {
808 - if ( ! $fields ) {
681 + if ( empty( $fields ) ) {
809 682 return;
810 683 }
811 684
812 685 $end_section_values = apply_filters( 'frm_before_field_created', FrmFieldsHelper::setup_new_vars( 'end_divider', $form->id ) );
@@ -813,12 +686,11 @@
813 686 $open = false;
814 687 $prev_order = false;
815 688 $add_order = 0;
816 689 $last_field = false;
817 -
818 690 foreach ( $fields as $field ) {
819 691 if ( $prev_order === $field->field_order ) {
820 - ++$add_order;
692 + $add_order ++;
821 693 }
822 694
823 695 if ( $add_order ) {
824 696 $reset_fields = true;
@@ -858,17 +730,8 @@
858 730
859 731 /**
860 732 * Create end section field if it doesn't exist. This is for migration from < 2.0
861 733 * Fix any ordering that may be messed up
862 - *
863 - * @param bool $open
864 - * @param bool $reset_fields
865 - * @param int $add_order
866 - * @param array $end_section_values
867 - * @param object $field
868 - * @param string $move
869 - *
870 - * @return void
871 734 */
872 735 public static function maybe_create_end_section( &$open, &$reset_fields, &$add_order, $end_section_values, $field, $move = 'no' ) {
873 736 if ( ! $open ) {
874 737 return;
@@ -877,27 +740,18 @@
877 740 $end_section_values['field_order'] = $field->field_order + 1;
878 741
879 742 FrmField::create( $end_section_values );
880 743
881 - if ( $move === 'move' ) {
744 + if ( $move == 'move' ) {
882 745 // bump the order of current field unless we're at the end of the form
883 746 FrmField::update( $field->id, array( 'field_order' => $field->field_order + 2 ) );
884 747 }
885 748
886 - $add_order += 2;
749 + $add_order += 2;
887 750 $open = false;
888 751 $reset_fields = true;
889 752 }
890 753
891 - /**
892 - * @param string $html
893 - * @param object $form
894 - * @param bool $title
895 - * @param bool $description
896 - * @param array $values
897 - *
898 - * @return string
899 - */
900 754 public static function replace_shortcodes( $html, $form, $title = false, $description = false, $values = array() ) {
901 755 $codes = array(
902 756 'form_name' => $title,
903 757 'form_description' => $description,
@@ -902,9 +756,8 @@
902 756 'form_name' => $title,
903 757 'form_description' => $description,
904 758 'entry_key' => true,
905 759 );
906 -
907 760 foreach ( $codes as $code => $show ) {
908 761 if ( $code === 'form_name' ) {
909 762 $replace_with = $form->name;
910 763 } elseif ( $code === 'form_description' ) {
@@ -914,9 +767,9 @@
914 767 } else {
915 768 $replace_with = '';
916 769 }
917 770
918 - FrmShortcodeHelper::remove_inline_conditions( ( FrmAppHelper::is_true( $show ) && $replace_with != '' ), $code, $replace_with, $html ); // phpcs:ignore Universal.Operators.StrictComparisons, SlevomatCodingStandard.Files.LineLength.LineTooLong
771 + FrmShortcodeHelper::remove_inline_conditions( ( FrmAppHelper::is_true( $show ) && $replace_with != '' ), $code, $replace_with, $html );
919 772 }
920 773
921 774 // Replace [form_key].
922 775 $html = str_replace( '[form_key]', $form->form_key, $html );
@@ -923,9 +776,9 @@
923 776
924 777 // Replace [frmurl].
925 778 $html = str_replace( '[frmurl]', FrmFieldsHelper::dynamic_default_values( 'frmurl' ), $html );
926 779
927 - if ( str_contains( $html, '[button_label]' ) ) {
780 + if ( strpos( $html, '[button_label]' ) ) {
928 781 add_filter( 'frm_submit_button', 'FrmFormsHelper::submit_button_label', 1 );
929 782 $submit_label = apply_filters( 'frm_submit_button', $title, $form );
930 783 $submit_label = esc_attr( do_shortcode( $submit_label ) );
931 784 $html = str_replace( '[button_label]', $submit_label, $html );
@@ -932,17 +785,17 @@
932 785 }
933 786
934 787 $html = apply_filters( 'frm_form_replace_shortcodes', $html, $form, $values );
935 788
936 - if ( str_contains( $html, '[if back_button]' ) ) {
789 + if ( strpos( $html, '[if back_button]' ) ) {
937 790 $html = preg_replace( '/(\[if\s+back_button\])(.*?)(\[\/if\s+back_button\])/mis', '', $html );
938 791 }
939 792
940 - if ( str_contains( $html, '[if save_draft]' ) ) {
793 + if ( strpos( $html, '[if save_draft]' ) ) {
941 794 $html = preg_replace( '/(\[if\s+save_draft\])(.*?)(\[\/if\s+save_draft\])/mis', '', $html );
942 795 }
943 796
944 - if ( str_contains( $html, '[if start_over]' ) ) {
797 + if ( strpos( $html, '[if start_over]' ) ) {
945 798 $html = preg_replace( '/(\[if\s+start_over\])(.*?)(\[\/if\s+start_over\])/mis', '', $html );
946 799 }
947 800
948 801 if ( apply_filters( 'frm_do_html_shortcodes', true ) ) {
@@ -951,13 +804,8 @@
951 804
952 805 return $html;
953 806 }
954 807
955 - /**
956 - * @param string $submit
957 - *
958 - * @return string
959 - */
960 808 public static function submit_button_label( $submit ) {
961 809 if ( ! $submit ) {
962 810 $frm_settings = FrmAppHelper::get_settings();
963 811 $submit = $frm_settings->submit_value;
@@ -970,32 +818,28 @@
970 818 * If the Formidable styling isn't being loaded,
971 819 * use inline styling to hide the element
972 820 *
973 821 * @since 2.03.05
974 - *
975 - * @return void
976 822 */
977 823 public static function maybe_hide_inline() {
978 824 $frm_settings = FrmAppHelper::get_settings();
979 -
980 - if ( $frm_settings->load_style === 'none' ) {
825 + if ( $frm_settings->load_style == 'none' ) {
981 826 echo ' style="display:none;"';
982 - } elseif ( $frm_settings->load_style === 'dynamic' ) {
827 + } elseif ( $frm_settings->load_style == 'dynamic' ) {
983 828 FrmStylesController::enqueue_style();
984 829 }
985 830 }
986 831
987 - /**
988 - * @param array|bool|int|object|string $form
989 - *
990 - * @return string|null
991 - */
992 832 public static function get_form_style_class( $form = false ) {
993 833 $style = self::get_form_style( $form );
994 834 $class = ' with_frm_style';
995 835
996 - if ( ! $style ) {
997 - return FrmAppHelper::is_admin_page( 'formidable-entries' ) ? $class : null;
836 + if ( empty( $style ) ) {
837 + if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) {
838 + return $class;
839 + } else {
840 + return;
841 + }
998 842 }
999 843
1000 844 // If submit button needs to be inline or centered.
1001 845 if ( is_object( $form ) ) {
@@ -1016,9 +860,11 @@
1016 860 } elseif ( 'center' === $submit_align ) {
1017 861 $class .= ' frm_center_submit';
1018 862 }
1019 863
1020 - return apply_filters( 'frm_add_form_style_class', $class, $style, compact( 'form' ) );
864 + $class = apply_filters( 'frm_add_form_style_class', $class, $style, compact( 'form' ) );
865 +
866 + return $class;
1021 867 }
1022 868
1023 869 /**
1024 870 * In order for frm_inline_submit to inline the submit button the form must also have the frm_inline_form that adds the grid-column style rules required for it to work.
@@ -1025,17 +871,16 @@
1025 871 *
1026 872 * @since 5.0.12
1027 873 *
1028 874 * @param array $form
1029 - *
1030 875 * @return bool
1031 876 */
1032 877 private static function form_should_be_inline_and_missing_class( $form ) {
1033 - if ( isset( $form['form_class'] ) && str_contains( ' ' . $form['form_class'] . ' ', ' frm_inline_form ' ) ) {
878 + if ( isset( $form['form_class'] ) && false !== strpos( ' ' . $form['form_class'] . ' ', ' frm_inline_form ' ) ) {
1034 879 // not missing class, avoid adding it twice.
1035 880 return false;
1036 881 }
1037 - return ! empty( $form['submit_html'] ) && str_contains( $form['submit_html'], 'frm_inline_submit' );
882 + return ! empty( $form['submit_html'] ) && false !== strpos( $form['submit_html'], 'frm_inline_submit' );
1038 883 }
1039 884
1040 885 /**
1041 886 * Returns appropriate class if form has top labels
@@ -1060,9 +905,8 @@
1060 905 return false;
1061 906 }
1062 907
1063 908 $fields = $form['fields'];
1064 -
1065 909 if ( count( $fields ) <= 0 ) {
1066 910 return false;
1067 911 }
1068 912
@@ -1067,13 +911,11 @@
1067 911 }
1068 912
1069 913 // Start from the fields closest to the submit button.
1070 914 $fields = array_reverse( $fields );
1071 -
1072 915 foreach ( $fields as $field ) {
1073 - $type = $field['original_type'] ?? $field['type'];
916 + $type = isset( $field['original_type'] ) ? $field['original_type'] : $field['type'];
1074 917 $has_input = FrmFieldFactory::field_has_property( $type, 'has_input' );
1075 -
1076 918 if ( $has_input ) {
1077 919 return self::field_has_top_label( $field, $form );
1078 920 }
1079 921 }
@@ -1084,30 +926,28 @@
1084 926 /**
1085 927 * Check if a field's label position is set to "top"
1086 928 *
1087 929 * @param array $field
1088 - * @param bool|object|string $form
930 + * @param object|string|bool $form
1089 931 *
1090 932 * @return bool
1091 933 */
1092 934 private static function field_has_top_label( $field, $form ) {
1093 935 $label_position = FrmFieldsHelper::label_position( $field['label'], $field, $form );
1094 - return in_array( $label_position, array( 'top', 'inside', 'hidden' ), true );
936 +
937 + return in_array( $label_position, array( 'top', 'inside', 'hidden' ) );
1095 938 }
1096 939
1097 940 /**
1098 - * @param array|bool|int|object|string $form
941 + * @param object|string|boolean $form
1099 942 *
1100 943 * @return string
1101 944 */
1102 945 public static function get_form_style( $form ) {
1103 946 $style = 1;
1104 -
1105 - if ( ! $form || 'default' === $form ) {
947 + if ( empty( $form ) || 'default' === $form ) {
1106 948 return $style;
1107 - }
1108 -
1109 - if ( is_object( $form ) && $form->parent_form_id ) {
949 + } elseif ( is_object( $form ) && $form->parent_form_id ) {
1110 950 // get the parent form if this is a child
1111 951 $form = $form->parent_form_id;
1112 952 } elseif ( is_array( $form ) && ! empty( $form['parent_form_id'] ) ) {
1113 953 $form = $form['parent_form_id'];
@@ -1114,28 +954,28 @@
1114 954 } elseif ( is_array( $form ) && isset( $form['custom_style'] ) ) {
1115 955 $style = $form['custom_style'];
1116 956 }
1117 957
1118 - if ( $form && ( is_string( $form ) || is_int( $form ) ) ) {
958 + if ( $form && is_string( $form ) ) {
1119 959 $form = FrmForm::getOne( $form );
1120 960 }
1121 961
1122 - return $form && is_object( $form ) && isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : $style;
962 + $style = ( $form && is_object( $form ) && isset( $form->options['custom_style'] ) ) ? $form->options['custom_style'] : $style;
963 +
964 + return $style;
1123 965 }
1124 966
1125 967 /**
1126 968 * Display the validation error messages when an entry is submitted
1127 969 *
1128 - * @since 2.0.6
1129 - *
1130 970 * @param array $args Includes img, errors.
1131 971 *
1132 - * @return void
972 + * @since 2.0.6
1133 973 */
1134 974 public static function show_errors( $args ) {
1135 975 $invalid_msg = self::get_invalid_error_message( $args );
1136 976
1137 - if ( ! $invalid_msg ) {
977 + if ( empty( $invalid_msg ) ) {
1138 978 $show_img = false;
1139 979 } else {
1140 980 echo wp_kses_post( $invalid_msg );
1141 981 $show_img = true;
@@ -1154,13 +994,11 @@
1154 994 * Display the error message in the front-end along with the image if set
1155 995 * The image was removed from the styling settings, but it may still be set with a hook
1156 996 * If the message in the global settings is empty, show every validation message in the error box
1157 997 *
1158 - * @since 2.0.6
1159 - *
1160 998 * @param array $args Includes img, errors, and show_img.
1161 999 *
1162 - * @return void
1000 + * @since 2.0.6
1163 1001 */
1164 1002 public static function show_error( $args ) {
1165 1003 // remove any blank messages
1166 1004 $args['errors'] = array_filter( (array) $args['errors'] );
@@ -1165,11 +1003,10 @@
1165 1003 // remove any blank messages
1166 1004 $args['errors'] = array_filter( (array) $args['errors'] );
1167 1005
1168 1006 $line_break_first = $args['show_img'];
1169 -
1170 1007 foreach ( $args['errors'] as $error_key => $error ) {
1171 - if ( $line_break_first && ! is_numeric( $error_key ) && ( $error_key === 'cptch_number' || str_starts_with( $error_key, 'field' ) ) ) {
1008 + if ( $line_break_first && ! is_numeric( $error_key ) && ( $error_key == 'cptch_number' || strpos( $error_key, 'field' ) === 0 ) ) {
1172 1009 continue;
1173 1010 }
1174 1011
1175 1012 $id = str_replace( 'field', 'field_', $error_key );
@@ -1175,9 +1012,9 @@
1175 1012 $id = str_replace( 'field', 'field_', $error_key );
1176 1013 echo '<div id="' . esc_attr( $id ) . '_error">';
1177 1014
1178 1015 if ( $args['show_img'] && ! empty( $args['img'] ) ) {
1179 - echo '<img src="' . esc_url( $args['img'] ) . '" alt="" />';
1016 + echo '<img src="' . esc_attr( $args['img'] ) . '" alt="" />';
1180 1017 } else {
1181 1018 $args['show_img'] = true;
1182 1019 }
1183 1020
@@ -1186,38 +1023,34 @@
1186 1023 echo '</div>';
1187 1024 }
1188 1025 }
1189 1026
1190 - /**
1191 - * @param int|string $id
1192 - *
1193 - * @return void
1194 - */
1195 1027 public static function maybe_get_scroll_js( $id ) {
1196 1028 $offset = apply_filters( 'frm_scroll_offset', 4, array( 'form_id' => $id ) );
1197 -
1198 - // phpcs:ignore Universal.Operators.StrictComparisons
1199 1029 if ( $offset != - 1 ) {
1200 1030 self::get_scroll_js( $id );
1201 1031 }
1202 1032 }
1203 1033
1034 + public static function get_scroll_js( $form_id ) {
1035 + echo '<script type="text/javascript">document.addEventListener(\'DOMContentLoaded\',function(){frmFrontForm.scrollMsg(' . (int) $form_id . ');})</script>';
1036 + }
1037 +
1204 1038 /**
1205 - * @param int|string $form_id
1206 - *
1207 - * @return void
1039 + * @since 3.0
1208 1040 */
1209 - public static function get_scroll_js( $form_id ) {
1210 - echo '<script type="text/javascript">document.addEventListener(\'DOMContentLoaded\',function(){frmFrontForm.scrollMsg(' . (int) $form_id . ');})</script>';
1041 + public static function actions_dropdown( $atts ) {
1042 + if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
1043 + $status = $atts['status'];
1044 + $form_id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
1045 + $trash_link = self::delete_trash_info( $form_id, $status );
1046 + $links = self::get_action_links( $form_id, $status );
1047 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/actions-dropdown.php' );
1048 + }
1211 1049 }
1212 1050
1213 1051 /**
1214 1052 * @since 3.0
1215 - *
1216 - * @param int|object|string $form_id
1217 - * @param mixed $form
1218 - *
1219 - * @return array
1220 1053 */
1221 1054 public static function get_action_links( $form_id, $form ) {
1222 1055 if ( ! is_object( $form ) ) {
1223 1056 $form = FrmForm::getOne( $form_id );
@@ -1224,10 +1057,9 @@
1224 1057 }
1225 1058
1226 1059 $actions = array();
1227 1060 $trash_links = self::delete_trash_links( $form_id );
1228 -
1229 - if ( 'trash' === $form->status ) {
1061 + if ( 'trash' == $form->status ) {
1230 1062 $actions['restore'] = $trash_links['restore'];
1231 1063
1232 1064 if ( current_user_can( 'frm_delete_forms' ) ) {
1233 1065 $actions['trash'] = $trash_links['delete'];
@@ -1233,20 +1065,19 @@
1233 1065 $actions['trash'] = $trash_links['delete'];
1234 1066 }
1235 1067 } elseif ( current_user_can( 'frm_edit_forms' ) ) {
1236 1068 $duplicate_link = '?page=formidable&frm_action=duplicate&id=' . $form_id;
1237 -
1238 1069 if ( $form->is_template ) {
1239 1070 $actions['frm_duplicate'] = array(
1240 1071 'url' => wp_nonce_url( $duplicate_link ),
1241 1072 'label' => __( 'Create Form from Template', 'formidable' ),
1242 - 'icon' => 'frmfont frm_clone_icon',
1073 + 'icon' => 'frm_icon_font frm_clone_icon',
1243 1074 );
1244 1075 } else {
1245 1076 $actions['duplicate'] = array(
1246 1077 'url' => wp_nonce_url( $duplicate_link ),
1247 1078 'label' => __( 'Duplicate Form', 'formidable' ),
1248 - 'icon' => 'frmfont frm_clone_icon',
1079 + 'icon' => 'frm_icon_font frm_clone_icon',
1249 1080 );
1250 1081 }
1251 1082
1252 1083 $actions['trash'] = self::delete_trash_info( $form_id, $form->status );
@@ -1254,13 +1085,8 @@
1254 1085
1255 1086 return $actions;
1256 1087 }
1257 1088
1258 - /**
1259 - * @param int|object|string $data
1260 - *
1261 - * @return string
1262 - */
1263 1089 public static function edit_form_link( $data ) {
1264 1090 $form_id = self::get_form_id_from_data( $data );
1265 1091
1266 1092 if ( ! $form_id ) {
@@ -1267,86 +1093,60 @@
1267 1093 return '';
1268 1094 }
1269 1095
1270 1096 $label = self::edit_form_link_label( $data );
1271 - return '<a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html( $label ) . '</a>';
1097 + $link = '<a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html( $label ) . '</a>';
1098 + return $link;
1272 1099 }
1273 1100
1274 - /**
1275 - * Returns a text used when no title is set.
1276 - *
1277 - * @since 6.16.1
1278 - *
1279 - * @return string
1280 - */
1281 - public static function get_no_title_text() {
1282 - return __( '(no title)', 'formidable' );
1283 - }
1284 -
1285 - /**
1286 - * @param int|object|string $data
1287 - *
1288 - * @return string
1289 - */
1290 1101 public static function edit_form_link_label( $data ) {
1291 1102 $name = self::get_form_name_from_data( $data );
1292 -
1293 1103 if ( ! $name ) {
1294 - return self::get_no_title_text();
1104 + return __( '(no title)', 'formidable' );
1295 1105 }
1296 -
1297 1106 return FrmAppHelper::truncate( $name, 40 );
1298 1107 }
1299 1108
1300 1109 /**
1301 - * @param int|object|string $data
1302 - *
1303 - * @return int|string
1110 + * @param mixed $data
1111 + * @return int
1304 1112 */
1305 1113 private static function get_form_id_from_data( $data ) {
1306 - return is_object( $data ) ? $data->id : $data;
1114 + if ( is_object( $data ) ) {
1115 + $form_id = $data->id;
1116 + } else {
1117 + $form_id = $data;
1118 + }
1119 + return $form_id;
1307 1120 }
1308 1121
1309 1122 /**
1310 1123 * @param mixed $data
1311 - *
1312 1124 * @return string
1313 1125 */
1314 1126 private static function get_form_name_from_data( $data ) {
1315 1127 if ( is_object( $data ) ) {
1316 - return $data->name;
1128 + $form_name = $data->name;
1129 + } else {
1130 + $form_id = $data;
1131 + $form_name = FrmForm::getName( $form_id );
1317 1132 }
1318 -
1319 - $form_id = $data;
1320 - return FrmForm::getName( $form_id );
1133 + return $form_name;
1321 1134 }
1322 1135
1323 - /**
1324 - * @param int $id
1325 - * @param string $status
1326 - * @param string $length
1327 - *
1328 - * @return string
1329 - */
1330 1136 public static function delete_trash_link( $id, $status, $length = 'label' ) {
1331 1137 $link_details = self::delete_trash_info( $id, $status );
1138 +
1332 1139 return self::format_link_html( $link_details, $length );
1333 1140 }
1334 1141
1335 1142 /**
1336 1143 * @since 3.0
1337 - *
1338 - * @param array $link_details
1339 - * @param string $length
1340 - *
1341 - * @return string
1342 1144 */
1343 1145 public static function format_link_html( $link_details, $length = 'label' ) {
1344 1146 $link = '';
1345 -
1346 - if ( $link_details ) {
1147 + if ( ! empty( $link_details ) ) {
1347 1148 $link = '<a href="' . esc_url( $link_details['url'] ) . '" class="frm-trash-link"';
1348 -
1349 1149 if ( isset( $link_details['data'] ) ) {
1350 1150 foreach ( $link_details['data'] as $data => $value ) {
1351 1151 $link .= ' data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '"';
1352 1152 }
@@ -1353,13 +1153,12 @@
1353 1153 } elseif ( isset( $link_details['confirm'] ) ) {
1354 1154 $link .= ' onclick="return confirm(\'' . esc_attr( $link_details['confirm'] ) . '\')"';
1355 1155 }
1356 1156
1357 - $label = $link_details[ $length ] ?? $link_details['label'];
1358 -
1359 - if ( $length === 'icon' && isset( $link_details[ $length ] ) ) {
1157 + $label = ( isset( $link_details[ $length ] ) ? $link_details[ $length ] : $link_details['label'] );
1158 + if ( $length == 'icon' && isset( $link_details[ $length ] ) ) {
1360 1159 $label = '<span class="' . $label . '" title="' . esc_attr( $link_details['label'] ) . '" aria-hidden="true"></span>';
1361 - $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"';
1160 + $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"';
1362 1161 }
1363 1162
1364 1163 $link .= '>' . $label . '</a>';
1365 1164 }
@@ -1368,21 +1167,20 @@
1368 1167 }
1369 1168
1370 1169 /**
1371 1170 * @since 3.0
1372 - *
1373 - * @param int $id
1374 - * @param string $status
1375 - *
1376 - * @return array
1377 1171 */
1378 1172 public static function delete_trash_info( $id, $status ) {
1379 1173 $labels = self::delete_trash_links( $id );
1380 1174
1381 - if ( 'trash' === $status ) {
1175 + if ( 'trash' == $status ) {
1382 1176 $info = $labels['restore'];
1383 1177 } elseif ( current_user_can( 'frm_delete_forms' ) ) {
1384 - $info = EMPTY_TRASH_DAYS ? $labels['trash'] : $labels['delete'];
1178 + if ( EMPTY_TRASH_DAYS ) {
1179 + $info = $labels['trash'];
1180 + } else {
1181 + $info = $labels['delete'];
1182 + }
1385 1183 } else {
1386 1184 $info = array();
1387 1185 }
1388 1186
@@ -1390,12 +1188,8 @@
1390 1188 }
1391 1189
1392 1190 /**
1393 1191 * @since 3.0
1394 - *
1395 - * @param int $id
1396 - *
1397 - * @return array
1398 1192 */
1399 1193 public static function delete_trash_links( $id ) {
1400 1194 $current_page = FrmAppHelper::get_simple_request( array( 'param' => 'form_type' ) );
1401 1195 $base_url = '?page=formidable&form_type=' . $current_page . '&id=' . $id;
@@ -1409,9 +1203,9 @@
1409 1203 'trash' => array(
1410 1204 'label' => __( 'Move Form to Trash', 'formidable' ),
1411 1205 'short' => __( 'Trash', 'formidable' ),
1412 1206 'url' => wp_nonce_url( $base_url . '&frm_action=trash', 'trash_form_' . absint( $id ) ),
1413 - 'icon' => 'frmfont frm_delete_icon',
1207 + 'icon' => 'frm_icon_font frm_delete_icon',
1414 1208 'data' => array(
1415 1209 'frmverify' => __( 'Do you want to move this form to the trash?', 'formidable' ),
1416 1210 'frmverify-btn' => 'frm-button-red',
1417 1211 ),
@@ -1420,9 +1214,9 @@
1420 1214 'label' => __( 'Delete Permanently', 'formidable' ),
1421 1215 'short' => __( 'Delete', 'formidable' ),
1422 1216 'url' => wp_nonce_url( $base_url . '&frm_action=destroy', 'destroy_form_' . absint( $id ) ),
1423 1217 'confirm' => __( 'Are you sure you want to delete this form and all its entries?', 'formidable' ),
1424 - 'icon' => 'frmfont frm_delete_icon',
1218 + 'icon' => 'frm_icon_font frm_delete_icon',
1425 1219 'data' => array(
1426 1220 'frmverify' => __( 'This will permanently delete the form and all its entries. This is irreversible. Are you sure you want to continue?', 'formidable' ),
1427 1221 'frmverify-btn' => 'frm-button-red',
1428 1222 ),
@@ -1431,38 +1225,36 @@
1431 1225 }
1432 1226
1433 1227 /**
1434 1228 * @since 3.0
1435 - *
1436 - * @return array
1437 1229 */
1438 1230 public static function css_classes() {
1439 1231 $classes = array(
1440 - 'frm_total' => array(
1232 + 'frm_total' => array(
1441 1233 'label' => __( 'Total', 'formidable' ),
1442 1234 'title' => __( 'Add this to a read-only field to display the text in bold without a border or background.', 'formidable' ),
1443 1235 ),
1444 - 'frm_total_big' => array(
1236 + 'frm_total_big' => array(
1445 1237 'label' => __( 'Big Total', 'formidable' ),
1446 1238 'title' => __( 'Add this to a read-only field to display the text in large, bold text without a border or background.', 'formidable' ),
1447 1239 ),
1448 - 'frm_scroll_box' => array(
1240 + 'frm_scroll_box' => array(
1449 1241 'label' => __( 'Scroll Box', 'formidable' ),
1450 - 'title' => __( 'If you have many checkbox or radio button options, you may add this class to allow your user to easily scroll through the options. Or add a scrolling area around content in an HTML field.', 'formidable' ), // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
1242 + 'title' => __( 'If you have many checkbox or radio button options, you may add this class to allow your user to easily scroll through the options. Or add a scrolling area around content in an HTML field.', 'formidable' ),
1451 1243 ),
1452 - 'frm_first' => array(
1244 + 'frm_first' => array(
1453 1245 'label' => __( 'First', 'formidable' ),
1454 1246 'title' => __( 'Add this to the first field in each row along with a width. ie frm_first frm4', 'formidable' ),
1455 1247 ),
1456 - 'frm_alignright' => __( 'Right', 'formidable' ),
1457 - 'frm_grid_first' => __( 'First Grid Row', 'formidable' ),
1458 - 'frm_grid' => __( 'Even Grid Row', 'formidable' ),
1459 - 'frm_grid_odd' => __( 'Odd Grid Row', 'formidable' ),
1248 + 'frm_alignright' => __( 'Right', 'formidable' ),
1249 + 'frm_grid_first' => __( 'First Grid Row', 'formidable' ),
1250 + 'frm_grid' => __( 'Even Grid Row', 'formidable' ),
1251 + 'frm_grid_odd' => __( 'Odd Grid Row', 'formidable' ),
1460 1252 'frm_color_block' => array(
1461 1253 'label' => __( 'Color Block', 'formidable' ),
1462 1254 'title' => __( 'Add a background color to the field or section.', 'formidable' ),
1463 1255 ),
1464 - 'frm_capitalize' => array(
1256 + 'frm_capitalize' => array(
1465 1257 'label' => __( 'Capitalize', 'formidable' ),
1466 1258 'title' => __( 'Automatically capitalize the first letter in each word.', 'formidable' ),
1467 1259 ),
1468 1260 );
@@ -1469,11 +1261,8 @@
1469 1261
1470 1262 return apply_filters( 'frm_layout_classes', $classes );
1471 1263 }
1472 1264
1473 - /**
1474 - * @return array
1475 - */
1476 1265 public static function grid_classes() {
1477 1266 return array(
1478 1267 'frm_half' => '1/2',
1479 1268 'frm_third' => '1/3',
@@ -1487,18 +1276,12 @@
1487 1276 }
1488 1277
1489 1278 /**
1490 1279 * @since 3.0
1491 - *
1492 - * @param mixed $style
1493 - * @param string $class
1494 - *
1495 - * @return string
1496 1280 */
1497 1281 public static function style_class_label( $style, $class ) {
1498 1282 $label = '';
1499 -
1500 - if ( ! $style ) {
1283 + if ( empty( $style ) ) {
1501 1284 $label = $class;
1502 1285 } elseif ( ! is_array( $style ) ) {
1503 1286 $label = $style;
1504 1287 } elseif ( isset( $style['label'] ) ) {
@@ -1507,13 +1290,8 @@
1507 1290
1508 1291 return $label;
1509 1292 }
1510 1293
1511 - /**
1512 - * @param string $status
1513 - *
1514 - * @return string
1515 - */
1516 1294 public static function status_nice_name( $status ) {
1517 1295 $nice_names = array(
1518 1296 'draft' => __( 'Draft', 'formidable' ),
1519 1297 'trash' => __( 'Trash', 'formidable' ),
@@ -1519,13 +1297,15 @@
1519 1297 'trash' => __( 'Trash', 'formidable' ),
1520 1298 'publish' => __( 'Published', 'formidable' ),
1521 1299 );
1522 1300
1523 - if ( ! in_array( $status, array_keys( $nice_names ), true ) ) {
1301 + if ( ! in_array( $status, array_keys( $nice_names ) ) ) {
1524 1302 $status = 'publish';
1525 1303 }
1526 1304
1527 - return $nice_names[ $status ];
1305 + $name = $nice_names[ $status ];
1306 +
1307 + return $name;
1528 1308 }
1529 1309
1530 1310 /**
1531 1311 * Renders a template icon based on the given categories.
@@ -1532,11 +1312,10 @@
1532 1312 *
1533 1313 * @param array $categories The categories to render the icon for.
1534 1314 * @param array $atts {
1535 1315 * Optional. An array of attributes for rendering.
1536 - *
1537 1316 * @type string $html 'span' or 'div'. Default 'span'.
1538 - * @type bool $bg Whether to add a background color or not. Default false.
1317 + * @type boolean $bg Whether to add a background color or not. Default false.
1539 1318 * }
1540 1319 *
1541 1320 * @return void
1542 1321 */
@@ -1542,66 +1321,64 @@
1542 1321 */
1543 1322 public static function template_icon( $categories, $atts = array() ) {
1544 1323 // Define defaults.
1545 1324 $defaults = array(
1546 - 'bg' => true,
1325 + 'bg' => true,
1547 1326 );
1548 - $atts = array_merge( $defaults, $atts );
1327 + $atts = array_merge( $defaults, $atts );
1549 1328
1550 1329 // Filter out ignored categories.
1551 - $ignore = self::get_license_types();
1330 + $ignore = self::ignore_template_categories();
1552 1331 $categories = array_diff( $categories, $ignore );
1553 1332
1554 1333 // Define icons mapping.
1555 1334 $icons = array(
1556 - 'WooCommerce' => array( 'woocommerce', 'var(--purple)' ),
1557 - 'Post' => array( 'wordpress', 'rgb(0,160,210)' ),
1558 - 'User Registration' => array( 'register', 'var(--pink)' ),
1335 + 'WooCommerce' => array( 'woocommerce', 'var(--purple)' ),
1336 + 'Post' => array( 'wordpress', 'rgb(0,160,210)' ),
1337 + 'User Registration' => array( 'register', 'var(--pink)' ),
1559 1338 'Registration and Signup' => array( 'register', 'var(--pink)' ),
1560 - 'PayPal' => array( 'paypal' ),
1561 - 'Stripe' => array( 'credit_card', 'var(--green)' ),
1562 - 'Twilio' => array( 'sms' ),
1563 - 'Payment' => array( 'credit_card' ),
1564 - 'Order Form' => array( 'product' ),
1565 - 'Finance' => array( 'total' ),
1566 - 'Health and Wellness' => array( 'heart', 'var(--pink)' ),
1567 - 'Event Planning' => array( 'calendar', 'var(--orange)' ),
1568 - 'Real Estate' => array( 'house' ),
1569 - 'Nonprofit' => array( 'heart_solid' ),
1570 - 'Calculator' => array( 'calculator', 'var(--purple)' ),
1571 - 'Quiz' => array( 'percent' ),
1572 - 'Registrations' => array( 'address_card' ),
1573 - 'Customer Service' => array( 'users_solid' ),
1574 - 'Education' => array( 'pencil' ),
1575 - 'Marketing' => array( 'eye' ),
1576 - 'Feedback' => array( 'smile' ),
1577 - 'Business Operations' => array( 'case' ),
1578 - 'Contact Form' => array( 'email' ),
1579 - 'Conversational Forms' => array( 'chat_forms' ),
1580 - 'Survey' => array( 'chat_forms', 'var(--orange)' ),
1581 - 'Application' => array( 'align_right' ),
1582 - 'Signature' => array( 'signature' ),
1583 - '' => array( 'align_right' ),
1339 + 'PayPal' => array( 'paypal' ),
1340 + 'Stripe' => array( 'credit_card', 'var(--green)' ),
1341 + 'Twilio' => array( 'sms' ),
1342 + 'Payment' => array( 'credit_card' ),
1343 + 'Order Form' => array( 'product' ),
1344 + 'Finance' => array( 'total' ),
1345 + 'Health and Wellness' => array( 'heart', 'var(--pink)' ),
1346 + 'Event Planning' => array( 'calendar', 'var(--orange)' ),
1347 + 'Real Estate' => array( 'house' ),
1348 + 'Nonprofit' => array( 'heart_solid' ),
1349 + 'Calculator' => array( 'calculator', 'var(--purple)' ),
1350 + 'Quiz' => array( 'percent' ),
1351 + 'Registrations' => array( 'address_card' ),
1352 + 'Customer Service' => array( 'users_solid' ),
1353 + 'Education' => array( 'pencil' ),
1354 + 'Marketing' => array( 'eye' ),
1355 + 'Feedback' => array( 'smile' ),
1356 + 'Business Operations' => array( 'case' ),
1357 + 'Contact Form' => array( 'email' ),
1358 + 'Conversational Forms' => array( 'chat_forms' ),
1359 + 'Survey' => array( 'chat_forms', 'var(--orange)' ),
1360 + 'Application' => array( 'align_right' ),
1361 + 'Signature' => array( 'signature' ),
1362 + '' => array( 'align_right' ),
1584 1363 );
1585 1364
1586 1365 // Determine the icon to be used.
1587 1366 $icon = $icons[''];
1588 -
1589 1367 if ( count( $categories ) === 1 ) {
1590 1368 $category = reset( $categories );
1591 - $icon = $icons[ $category ] ?? $icon;
1592 - } elseif ( $categories ) {
1369 + $icon = isset( $icons[ $category ] ) ? $icons[ $category ] : $icon;
1370 + } elseif ( ! empty( $categories ) ) {
1593 1371 $icons = array_intersect_key( $icons, array_flip( $categories ) );
1594 - $icon = reset( $icons );
1372 + $icon = reset( $icons );
1595 1373 }
1596 1374
1597 1375 // Prepare variables for output.
1598 1376 $icon_name = $icon[0];
1599 - $bg_color = $icon[1] ?? '';
1377 + $bg_color = isset( $icon[1] ) ? $icon[1] : '';
1600 1378
1601 1379 // Render the icon.
1602 1380 echo '<span class="frm-category-icon frm-icon-wrapper"';
1603 -
1604 1381 if ( $bg_color && $atts['bg'] ) {
1605 1382 echo ' style="background-color:' . esc_attr( $bg_color ) . '"';
1606 1383 }
1607 1384 echo '>';
@@ -1609,8 +1386,19 @@
1609 1386 echo '</span>';
1610 1387 }
1611 1388
1612 1389 /**
1390 + * Retrieves the list of template categories to ignore.
1391 + *
1392 + * @since 4.03.01
1393 + *
1394 + * @return string[] Array of categories to ignore.
1395 + */
1396 + public static function ignore_template_categories() {
1397 + return array( 'Business', 'Elite', 'Personal', 'Creator', 'Basic', 'free' );
1398 + }
1399 +
1400 + /**
1613 1401 * Get template install link.
1614 1402 *
1615 1403 * @since 4.02
1616 1404 *
@@ -1615,9 +1403,8 @@
1615 1403 * @since 4.02
1616 1404 *
1617 1405 * @param array $template Template details.
1618 1406 * @param array $args Additional arguments.
1619 - *
1620 1407 * @return array The link attributes.
1621 1408 */
1622 1409 public static function get_template_install_link( $template, $args ) {
1623 1410 $defaults = array(
@@ -1633,8 +1420,13 @@
1633 1420 'class' => 'frm-install-template',
1634 1421 'href' => 'rel',
1635 1422 'atts' => '',
1636 1423 );
1424 + } elseif ( self::plan_is_allowed( $args ) ) {
1425 + $link = array(
1426 + 'url' => FrmAppHelper::admin_upgrade_link( 'addons', 'account/downloads/' ) . '&utm_content=' . $template['slug'],
1427 + 'label' => __( 'Renew', 'formidable' ),
1428 + );
1637 1429 } else {
1638 1430 $link = array(
1639 1431 'url' => $args['pricing'],
1640 1432 'label' => __( 'Upgrade', 'formidable' ),
@@ -1649,9 +1441,8 @@
1649 1441 *
1650 1442 * @since 4.02.02
1651 1443 *
1652 1444 * @param array $args
1653 - *
1654 1445 * @return bool
1655 1446 */
1656 1447 public static function plan_is_allowed( $args ) {
1657 1448 if ( empty( $args['license_type'] ) ) {
@@ -1670,9 +1461,8 @@
1670 1461 foreach ( $plans as $plan ) {
1671 1462 if ( $included || $plan === $license_type ) {
1672 1463 break;
1673 1464 }
1674 -
1675 1465 $included = $plan === $plan_required;
1676 1466 }
1677 1467
1678 1468 return $included;
@@ -1682,22 +1472,17 @@
1682 1472 * If a template or add-on cannot be installed, show a message
1683 1473 * about which plan is required.
1684 1474 *
1685 1475 * @since 4.0
1686 - *
1687 - * @param string $requires
1688 - * @param string $link
1689 - *
1690 - * @return void
1691 1476 */
1692 1477 public static function show_plan_required( $requires, $link ) {
1693 - if ( ! $requires ) {
1478 + if ( empty( $requires ) ) {
1694 1479 return;
1695 1480 }
1696 1481
1697 1482 ?>
1698 1483 <p class="frm_plan_required">
1699 - <?php esc_html_e( 'Plan required:', 'formidable' ); ?>
1484 + <?php esc_html_e( 'License plan required:', 'formidable' ); ?>
1700 1485 <a href="<?php echo esc_url( $link ); ?>" target="_blank" rel="noopener">
1701 1486 <?php echo esc_html( $requires ); ?>
1702 1487 </a>
1703 1488 </p>
@@ -1707,10 +1492,9 @@
1707 1492 /**
1708 1493 * @since 4.0
1709 1494 *
1710 1495 * @param array $item
1711 - *
1712 - * @return false|string
1496 + * @return string|false
1713 1497 */
1714 1498 public static function get_plan_required( &$item ) {
1715 1499 if ( ! isset( $item['categories'] ) || ! is_array( $item['categories'] ) || ! empty( $item['url'] ) ) {
1716 1500 return false;
@@ -1715,14 +1499,20 @@
1715 1499 if ( ! isset( $item['categories'] ) || ! is_array( $item['categories'] ) || ! empty( $item['url'] ) ) {
1716 1500 return false;
1717 1501 }
1718 1502
1719 - $plans = self::get_license_types();
1503 + $plans = array( 'free', 'Basic', 'Personal', 'Plus', 'Creator', 'Business', 'Elite' );
1720 1504
1721 1505 foreach ( $item['categories'] as $k => $category ) {
1722 1506 if ( in_array( $category, $plans, true ) ) {
1723 1507 unset( $item['categories'][ $k ] );
1724 - return self::convert_legacy_package_names( $category );
1508 +
1509 + if ( in_array( $category, array( 'Creator', 'Personal' ), true ) ) {
1510 + // Show the current package name.
1511 + $category = 'Plus';
1512 + }
1513 +
1514 + return $category;
1725 1515 }
1726 1516 }
1727 1517
1728 1518 return false;
@@ -1728,53 +1518,8 @@
1728 1518 return false;
1729 1519 }
1730 1520
1731 1521 /**
1732 - * Converts legacy package names to the current standard package name.
1733 - *
1734 - * @since 6.15
1735 - *
1736 - * @param string $package_name
1737 - *
1738 - * @return string The updated package name.
1739 - */
1740 - public static function convert_legacy_package_names( $package_name ) {
1741 - if ( in_array( $package_name, array( 'Creator', 'Personal' ), true ) ) {
1742 - $package_name = 'Plus';
1743 - }
1744 -
1745 - return $package_name;
1746 - }
1747 -
1748 - /**
1749 - * Get the license types.
1750 - *
1751 - * @since 6.15
1752 - *
1753 - * @param array $args
1754 - *
1755 - * @return array
1756 - */
1757 - public static function get_license_types( $args = array() ) {
1758 - $defaults = array(
1759 - 'include_all' => true,
1760 - 'case_lower' => false,
1761 - );
1762 - $args = wp_parse_args( $args, $defaults );
1763 - $license_types = array( 'Basic', 'Plus', 'Business', 'Elite' );
1764 -
1765 - if ( $args['include_all'] ) {
1766 - $license_types = array_merge( array( 'free', 'Personal', 'Creator' ), $license_types );
1767 - }
1768 -
1769 - if ( $args['case_lower'] ) {
1770 - $license_types = array_map( 'strtolower', $license_types );
1771 - }
1772 -
1773 - return $license_types;
1774 - }
1775 -
1776 - /**
1777 1522 * Checks for warnings to be displayed after form settings are saved.
1778 1523 *
1779 1524 * @since 4.04
1780 1525 *
@@ -1782,9 +1527,10 @@
1782 1527 *
1783 1528 * @return array An array of warnings or an empty array.
1784 1529 */
1785 1530 public static function check_for_warnings( $values ) {
1786 - $warnings = array();
1531 + $warnings = array();
1532 +
1787 1533 $redirect_warning = self::check_redirect_url_for_unsafe_params( $values );
1788 1534
1789 1535 if ( $redirect_warning ) {
1790 1536 $warnings[] = $redirect_warning;
@@ -1809,9 +1555,9 @@
1809 1555
1810 1556 $options = $values['options'];
1811 1557 FrmAppHelper::sanitize_with_html( $options );
1812 1558
1813 - if ( ! isset( $options['success_action'] ) || $options['success_action'] !== 'redirect' || ! isset( $options['success_url'] ) ) {
1559 + if ( ( ! isset( $options['success_action'] ) ) || $options['success_action'] !== 'redirect' || ! isset( $options['success_url'] ) ) {
1814 1560 return false;
1815 1561 }
1816 1562
1817 1563 $unsafe_params_in_redirect = self::get_unsafe_params( $options['success_url'] );
@@ -1829,13 +1575,11 @@
1829 1575 * @return array An array of params whose names are reserved words or an empty array.
1830 1576 */
1831 1577 private static function get_unsafe_params( $url ) {
1832 1578 $redirect_components = parse_url( $url );
1833 -
1834 1579 if ( empty( $redirect_components['query'] ) ) {
1835 1580 return array();
1836 1581 }
1837 -
1838 1582 parse_str( $redirect_components['query'], $redirect_params );
1839 1583 $redirect_param_names = array_keys( $redirect_params );
1840 1584 $reserved_words = self::reserved_words();
1841 1585 $unsafe_params_in_redirect = array_intersect( $redirect_param_names, $reserved_words );
@@ -1861,17 +1605,17 @@
1861 1605 if ( $count === 0 ) {
1862 1606 return false;
1863 1607 }
1864 1608
1865 - if ( $count === 1 ) {
1609 + if ( $count == 1 ) {
1866 1610 /* translators: %s: the name of a single parameter in the redirect URL */
1867 - return sprintf( esc_html__( 'The redirect URL is using the parameter "%s", which is reserved by WordPress. ', 'formidable' ), $unsafe_params_in_redirect[0] ) . $caution . $reserved_words_link; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
1611 + return sprintf( esc_html__( 'The redirect URL is using the parameter "%s", which is reserved by WordPress. ', 'formidable' ), $unsafe_params_in_redirect[0] ) . $caution . $reserved_words_link;
1868 1612 }
1869 1613
1870 1614 $unsafe_params_string = implode( '", "', $unsafe_params_in_redirect );
1871 1615
1872 1616 /* translators: %s: the names of two or more parameters in the redirect URL, separated by commas */
1873 - return sprintf( esc_html__( 'The redirect URL is using the parameters "%s", which are reserved by WordPress. ', 'formidable' ), $unsafe_params_string ) . $caution . $reserved_words_link; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
1617 + return sprintf( esc_html__( 'The redirect URL is using the parameters "%s", which are reserved by WordPress. ', 'formidable' ), $unsafe_params_string ) . $caution . $reserved_words_link;
1874 1618 }
1875 1619
1876 1620 /**
1877 1621 * Returns an array of common reserved words in WordPress.
@@ -1937,19 +1681,17 @@
1937 1681 * @since 5.0.16
1938 1682 *
1939 1683 * @param string $url
1940 1684 * @param int $form_id
1941 - *
1942 1685 * @return string
1943 1686 */
1944 1687 public static function maybe_add_sanitize_url_attr( $url, $form_id ) {
1945 - if ( ! str_contains( $url, '[' ) ) {
1688 + if ( false === strpos( $url, '[' ) ) {
1946 1689 // Do nothing if no shortcodes are detected.
1947 1690 return $url;
1948 1691 }
1949 1692
1950 1693 $parsed = wp_parse_url( $url );
1951 -
1952 1694 if ( empty( $parsed['query'] ) ) {
1953 1695 // Do nothing if no query can be detected in the url string.
1954 1696 return $url;
1955 1697 }
@@ -1955,10 +1697,10 @@
1955 1697 }
1956 1698
1957 1699 $original_query = $parsed['query'];
1958 1700 $query = $parsed['query'];
1959 - $shortcodes = FrmFieldsHelper::get_shortcodes( $query, $form_id );
1960 1701
1702 + $shortcodes = FrmFieldsHelper::get_shortcodes( $query, $form_id );
1961 1703 if ( empty( $shortcodes[0] ) ) {
1962 1704 // No shortcodes found, do nothing.
1963 1705 return $url;
1964 1706 }
@@ -1970,21 +1712,20 @@
1970 1712 // Skip if shortcodes.
1971 1713 continue;
1972 1714 }
1973 1715
1974 - if ( str_contains( $options, 'sanitize_url=' ) || str_contains( $options, 'sanitize=' ) ) {
1716 + if ( false !== strpos( $options, 'sanitize_url=' ) || false !== strpos( $options, 'sanitize=' ) ) {
1975 1717 // A sanitize option is already set so leave it alone.
1976 1718 continue;
1977 1719 }
1978 1720
1979 1721 $new_shortcode = '[' . $shortcodes[2][ $key ];
1980 -
1981 1722 if ( $options ) {
1982 1723 $new_shortcode .= ' ' . $options;
1983 1724 }
1725 + $new_shortcode .= ' sanitize_url=1]';
1984 1726
1985 - $new_shortcode .= ' sanitize_url=1]';
1986 - $query = str_replace( $shortcode, $new_shortcode, $query );
1727 + $query = str_replace( $shortcode, $new_shortcode, $query );
1987 1728 }//end foreach
1988 1729
1989 1730 if ( $query === $original_query ) {
1990 1731 return $url;
@@ -1993,8 +1734,20 @@
1993 1734 return str_replace( $original_query, $query, $url );
1994 1735 }
1995 1736
1996 1737 /**
1738 + * Check if Pro isn't up to date yet.
1739 + * If Pro is active but using a version earlier than v6.2 fallback to Pro for AJAX submit (so things don't all happen twice).
1740 + *
1741 + * @since 6.2
1742 + *
1743 + * @return bool
1744 + */
1745 + public static function should_use_pro_for_ajax_submit() {
1746 + return is_callable( 'FrmProForm::is_ajax_on' ) && ! is_callable( 'FrmProFormsHelper::lite_supports_ajax_submit' );
1747 + }
1748 +
1749 + /**
1997 1750 * Outputs the appropriate button text in the publish box.
1998 1751 *
1999 1752 * @return void
2000 1753 */
@@ -2009,127 +1762,25 @@
2009 1762 }
2010 1763 }
2011 1764
2012 1765 /**
2013 - * Strip characters similar to the WordPress sanitize_html_class function, but allow for [ and ].
2014 - * This allows shortcodes inside of the layout classes setting.
2015 - *
2016 - * @since 6.16
2017 - *
2018 - * @param string $classname
2019 - *
2020 - * @return string
1766 + * @since 4.02
1767 + * @deprecated 6.7
2021 1768 */
2022 - public static function sanitize_layout_class( $classname ) {
2023 - // Strip out any percent-encoded characters.
2024 - $sanitized = preg_replace( '|%[a-fA-F0-9][a-fA-F0-9]|', '', $classname );
2025 -
2026 - // Limit to A-Z, a-z, 0-9, '_', '-', '[', ']'.
2027 - return preg_replace( '/[^A-Za-z0-9_\-\[\]]/', '', $sanitized );
1769 + public static function template_install_html( $link, $class = '' ) {
1770 + _deprecated_function( __METHOD__, '6.7' );
2028 1771 }
2029 1772
2030 1773 /**
2031 - * Returns true if the preview should be blocked.
1774 + * Check an array of templates, determine how many the logged in user can use
2032 1775 *
2033 - * @since 6.20
1776 + * @deprecated 6.7
2034 1777 *
2035 - * @param string $form_key
2036 - *
2037 - * @return bool
1778 + * @param array $templates
1779 + * @param array $args
1780 + * @return int
2038 1781 */
2039 - public static function should_block_preview( $form_key ) {
2040 - $should_block = in_array( $form_key, array( 'contact-form', 'contact-us' ), true ) && ! current_user_can( 'frm_view_forms' );
2041 - /**
2042 - * Filters whether the form preview should be blocked.
2043 - *
2044 - * @since 6.20
2045 - *
2046 - * @param bool $should_block
2047 - * @param string $form_key
2048 - */
2049 - return (bool) apply_filters( 'frm_block_preview', $should_block, $form_key );
2050 - }
2051 -
2052 - /**
2053 - * Checks if the form is loaded by API.
2054 - *
2055 - * @since 6.21
2056 - *
2057 - * @return bool
2058 - */
2059 - public static function form_is_loaded_by_api() {
2060 - global $frm_vars;
2061 -
2062 - if ( ! empty( $frm_vars['inplace_edit'] ) ) {
2063 - return true;
2064 - }
2065 -
2066 - return self::is_formidable_api_form() || self::is_gutenberg_editor() || self::is_elementor_ajax() || self::is_visual_views_preview();
2067 - }
2068 -
2069 - /**
2070 - * @since 6.21
2071 - *
2072 - * @return bool
2073 - */
2074 - private static function is_visual_views_preview() {
2075 - return 'frm_views_process_box_preview' === FrmAppHelper::get_post_param( 'action' );
2076 - }
2077 -
2078 - /**
2079 - * @since 6.21
2080 - *
2081 - * @return bool
2082 - */
2083 - private static function is_elementor_ajax() {
2084 - return 'elementor_ajax' === FrmAppHelper::get_post_param( 'action' );
2085 - }
2086 -
2087 - /**
2088 - * @since 6.21
2089 - *
2090 - * @return bool
2091 - */
2092 - private static function is_gutenberg_editor() {
2093 - $url = FrmAppHelper::get_server_value( 'REQUEST_URI' );
2094 -
2095 - if ( str_contains( $url, '/wp-json/wp/v2/block-renderer/formidable/simple-form' ) ) {
2096 - return true;
2097 - }
2098 -
2099 - if ( str_contains( urldecode( $url ), 'rest_route=/wp/v2/block-renderer/formidable/' ) ) {
2100 - return true;
2101 - }
2102 -
2103 - global $pagenow;
2104 - return 'post.php' === $pagenow;
2105 - }
2106 -
2107 - /**
2108 - * @since 6.21
2109 - *
2110 - * @return bool
2111 - */
2112 - private static function is_formidable_api_form() {
2113 - if ( ! class_exists( 'FrmAPIAppController' ) ) {
2114 - return false;
2115 - }
2116 -
2117 - $url = FrmAppHelper::get_server_value( 'REQUEST_URI' );
2118 -
2119 - if ( str_contains( $url, '/wp-json/frm/v2/forms/' ) ) {
2120 - // Prevent the honeypot from appearing for an API loaded form.
2121 - // This is to prevent conflicts where the script is not working.
2122 - return true;
2123 - }
2124 -
2125 - if ( is_callable( 'FrmProFormState::get_from_request' ) ) {
2126 - $api = FrmProFormState::get_from_request( 'a', 0 );
2127 -
2128 - if ( $api ) {
2129 - return true;
2130 - }
2131 - }
2132 -
2133 - return false;
1782 + public static function available_count( $templates, $args ) {
1783 + _deprecated_function( __METHOD__, '6.7' );
1784 + return 0;
2134 1785 }
2135 1786 }