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