PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.3.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.3.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 +239 -780 6.26.1 → 5.3.2 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,63 +240,27 @@
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 - /**
307 - * @param array $atts {
308 - * The success message details.
309 - *
310 - * @type string $message
311 - * @type stdClass $form
312 - * @type int $entry_id
313 - * @type string $class
314 - * }
315 - *
316 - * @return string
317 - */
318 253 public static function get_success_message( $atts ) {
319 254 $message = apply_filters( 'frm_content', $atts['message'], $atts['form'], $atts['entry_id'] );
255 + $message = do_shortcode( FrmAppHelper::use_wpautop( $message ) );
256 + $message = '<div class="' . esc_attr( $atts['class'] ) . '" role="status">' . $message . '</div>';
320 257
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 );
341 - $message = '<div class="' . esc_attr( $atts['class'] ) . '" role="status">' . $message . '</div>';
342 258 return $message;
343 259 }
344 260
345 261 /**
346 262 * Used when a form is created
347 - *
348 - * @param array $values
349 - *
350 - * @return array
351 263 */
352 264 public static function setup_new_vars( $values = array() ) {
353 265 global $wpdb;
354 266
@@ -355,9 +267,9 @@
355 267 if ( ! empty( $values ) ) {
356 268 $post_values = $values;
357 269 } else {
358 270 $values = array();
359 - $post_values = ! empty( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
271 + $post_values = isset( $_POST ) ? $_POST : array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
360 272 }
361 273
362 274 $defaults = array(
363 275 'name' => '',
@@ -362,9 +274,8 @@
362 274 $defaults = array(
363 275 'name' => '',
364 276 'description' => '',
365 277 );
366 -
367 278 foreach ( $defaults as $var => $default ) {
368 279 if ( ! isset( $values[ $var ] ) ) {
369 280 $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
370 281 }
@@ -379,9 +290,8 @@
379 290 'is_template' => 0,
380 291 'status' => 'published',
381 292 'parent_form_id' => 0,
382 293 );
383 -
384 294 foreach ( $defaults as $var => $default ) {
385 295 if ( ! isset( $values[ $var ] ) ) {
386 296 $values[ $var ] = FrmAppHelper::get_param( $var, $default, 'get', 'sanitize_text_field' );
387 297 }
@@ -388,9 +298,9 @@
388 298 }
389 299 unset( $defaults );
390 300
391 301 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' );
302 + $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 303 }
394 304
395 305 $values = self::fill_default_opts( $values, false, $post_values );
396 306 $values['custom_style'] = FrmAppHelper::custom_style_value( $post_values );
@@ -399,14 +309,8 @@
399 309 }
400 310
401 311 /**
402 312 * Used when editing a form
403 - *
404 - * @param array $values
405 - * @param object $record
406 - * @param array $post_values
407 - *
408 - * @return array
409 313 */
410 314 public static function setup_edit_vars( $values, $record, $post_values = array() ) {
411 315 if ( empty( $post_values ) ) {
412 316 $post_values = wp_unslash( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
@@ -411,10 +315,10 @@
411 315 if ( empty( $post_values ) ) {
412 316 $post_values = wp_unslash( $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
413 317 }
414 318
415 - $values['form_key'] = $post_values['form_key'] ?? $record->form_key;
416 - $values['is_template'] = $post_values['is_template'] ?? $record->is_template;
319 + $values['form_key'] = isset( $post_values['form_key'] ) ? $post_values['form_key'] : $record->form_key;
320 + $values['is_template'] = isset( $post_values['is_template'] ) ? $post_values['is_template'] : $record->is_template;
417 321 $values['status'] = $record->status;
418 322
419 323 $values = self::fill_default_opts( $values, $record, $post_values );
420 324
@@ -420,31 +324,23 @@
420 324
421 325 return apply_filters( 'frm_setup_edit_form_vars', $values );
422 326 }
423 327
424 - /**
425 - * @param array $values
426 - * @param false|object $record
427 - * @param array|false $post_values
428 - *
429 - * @return array
430 - */
431 328 public static function fill_default_opts( $values, $record, $post_values ) {
432 329
433 330 $defaults = self::get_default_opts();
434 -
435 331 foreach ( $defaults as $var => $default ) {
436 332 if ( is_array( $default ) ) {
437 333 if ( ! isset( $values[ $var ] ) ) {
438 - $values[ $var ] = $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : array();
334 + $values[ $var ] = ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : array();
439 335 }
440 336
441 337 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 );
338 + $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 339
444 340 if ( is_array( $v ) ) {
445 341 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 );
342 + $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 343 unset( $k1, $v1 );
448 344 }
449 345 }
450 346
@@ -450,13 +346,13 @@
450 346
451 347 unset( $k, $v );
452 348 }
453 349 } else {
454 - $values[ $var ] = $post_values && isset( $post_values['options'][ $var ] ) ? $post_values['options'][ $var ] : ( $record && isset( $record->options[ $var ] ) ? $record->options[ $var ] : $default );
350 + $values[ $var ] = ( $post_values && isset( $post_values['options'][ $var ] ) ) ? $post_values['options'][ $var ] : ( ( $record && isset( $record->options[ $var ] ) ) ? $record->options[ $var ] : $default );
455 351 }
456 352
457 353 unset( $var, $default );
458 - }//end foreach
354 + }
459 355
460 356 return $values;
461 357 }
462 358
@@ -471,9 +367,9 @@
471 367 'success_action' => 'message',
472 368 'success_msg' => $frm_settings->success_msg,
473 369 'show_form' => 0,
474 370 'akismet' => '',
475 - 'stopforumspam' => 0,
371 + 'honeypot' => 'basic',
476 372 'antispam' => 0,
477 373 'no_save' => 0,
478 374 'ajax_load' => 0,
479 375 'js_validate' => 0,
@@ -483,25 +379,21 @@
483 379 'after_html' => '',
484 380 'submit_html' => self::get_default_html( 'submit' ),
485 381 'show_title' => 0,
486 382 'show_description' => 0,
487 - 'ajax_submit' => 0,
488 383 );
489 384 }
490 385
491 386 /**
492 - * @since 2.0.6
493 - *
494 387 * @param array $options
495 388 * @param array $values
496 389 *
497 - * @return void
390 + * @since 2.0.6
498 391 */
499 392 public static function fill_form_options( &$options, $values ) {
500 393 $defaults = self::get_default_opts();
501 -
502 394 foreach ( $defaults as $var => $default ) {
503 - $options[ $var ] = $values['options'][ $var ] ?? $default;
395 + $options[ $var ] = isset( $values['options'][ $var ] ) ? $values['options'][ $var ] : $default;
504 396 unset( $var, $default );
505 397 }
506 398 }
507 399
@@ -506,24 +398,20 @@
506 398 }
507 399
508 400 /**
509 401 * @param string $loc
510 - *
511 - * @return string
512 402 */
513 403 public static function get_default_html( $loc ) {
514 - if ( $loc === 'submit' ) {
404 + if ( $loc == 'submit' ) {
515 405 $draft_link = self::get_draft_link();
516 - $start_over = self::get_start_over_shortcode();
517 406 $default_html = <<<SUBMIT_HTML
518 -<div class="frm_submit frm_flex">
407 +<div class="frm_submit">
408 +[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 409 <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 410 $draft_link
522 -$start_over
523 411 </div>
524 412 SUBMIT_HTML;
525 - } elseif ( $loc === 'before' ) {
413 + } elseif ( $loc == 'before' ) {
526 414 $default_html = <<<BEFORE_HTML
527 415 <legend class="frm_screen_reader">[form_name]</legend>
528 416 [if form_name]<h3 class="frm_form_title">[form_name]</h3>[/if form_name]
529 417 [if form_description]<div class="frm_description">[form_description]</div>[/if form_description]
@@ -534,40 +422,16 @@
534 422
535 423 return $default_html;
536 424 }
537 425
538 - /**
539 - * @return string
540 - */
541 426 public static function get_draft_link() {
542 - $link = '[if save_draft]<button class="frm_save_draft" [draft_hook]>[draft_label]</button>[/if save_draft]';
427 + $link = '[if save_draft]<a href="#" tabindex="0" class="frm_save_draft" [draft_hook]>[draft_label]</a>[/if save_draft]';
543 428
544 429 return $link;
545 430 }
546 431
547 - /**
548 - * Gets start over button shortcode.
549 - *
550 - * @since 5.4
551 - *
552 - * @return string
553 - */
554 - public static function get_start_over_shortcode() {
555 - return '[if start_over]<a href="#" tabindex="0" class="frm_start_over" [start_over_hook]>[start_over_label]</a>[/if start_over]';
556 - }
557 -
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 432 public static function get_custom_submit( $html, $form, $submit, $form_action, $values ) {
568 433 $button = self::replace_shortcodes( $html, $form, $submit, $form_action, $values );
569 -
570 434 if ( ! strpos( $button, '[button_action]' ) ) {
571 435 echo FrmAppHelper::maybe_kses( $button ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
572 436 return;
573 437 }
@@ -575,22 +439,18 @@
575 439 /**
576 440 * @since 5.0.06
577 441 */
578 442 $button = apply_filters( 'frm_submit_button_html', $button, compact( 'form' ) );
579 -
580 443 if ( FrmAppHelper::should_never_allow_unfiltered_html() ) {
581 444 $button = FrmAppHelper::kses_submit_button( $button );
582 445 }
583 -
584 446 $button_parts = explode( '[button_action]', $button );
585 447
586 448 $classes = apply_filters( 'frm_submit_button_class', array(), $form );
587 -
588 449 if ( ! empty( $classes ) ) {
589 450 $classes = implode( ' ', $classes );
590 - $button_class = 'frm_button_submit';
591 -
592 - if ( preg_match( '/\bclass="[^"]*?\b' . preg_quote( $button_class, '/' ) . '\b[^"]*?"/', $button_parts[0] ) ) {
451 + $button_class = ' class="frm_button_submit';
452 + if ( strpos( $button_parts[0], $button_class ) !== false ) {
593 453 $button_parts[0] = str_replace( $button_class, $button_class . ' ' . esc_attr( $classes ), $button_parts[0] );
594 454 } else {
595 455 $button_parts[0] .= ' class="' . esc_attr( $classes ) . '"';
596 456 }
@@ -602,56 +462,54 @@
602 462 }
603 463
604 464 /**
605 465 * @since 4.0
606 - *
607 - * @return array
608 466 */
609 467 public static function html_shortcodes() {
610 468 $codes = array(
611 - 'id' => array(
469 + 'id' => array(
612 470 'label' => __( 'Field ID', 'formidable' ),
613 471 'class' => 'show_field_custom_html',
614 472 ),
615 - 'key' => array(
473 + 'key' => array(
616 474 'label' => __( 'Field Key', 'formidable' ),
617 475 'class' => 'show_field_custom_html',
618 476 ),
619 - 'field_name' => array(
477 + 'field_name' => array(
620 478 'label' => __( 'Field Name', 'formidable' ),
621 479 'class' => 'show_field_custom_html',
622 480 ),
623 - 'description' => array(
481 + 'description' => array(
624 482 'label' => __( 'Field Description', 'formidable' ),
625 483 'class' => 'show_field_custom_html',
626 484 ),
627 - 'label_position' => array(
485 + 'label_position' => array(
628 486 'label' => __( 'Label Position', 'formidable' ),
629 487 'class' => 'show_field_custom_html',
630 488 ),
631 - 'required_label' => array(
489 + 'required_label' => array(
632 490 'label' => __( 'Required Label', 'formidable' ),
633 491 'class' => 'show_field_custom_html',
634 492 ),
635 - 'input' => array(
493 + 'input' => array(
636 494 'label' => __( 'Input Field', 'formidable' ),
637 495 'class' => 'show_field_custom_html',
638 496 ),
639 - 'input opt=1' => array(
497 + 'input opt=1' => array(
640 498 'label' => __( 'Single Option', 'formidable' ),
641 499 'title' => __( 'Show a single radio or checkbox option by replacing 1 with the order of the option', 'formidable' ),
642 500 'class' => 'show_field_custom_html',
643 501 ),
644 - 'input label=0' => array(
502 + 'input label=0' => array(
645 503 'label' => __( 'Hide Option Label', 'formidable' ),
646 504 'class' => 'show_field_custom_html',
647 505 ),
648 - 'required_class' => array(
506 + 'required_class' => array(
649 507 'label' => __( 'Required Class', 'formidable' ),
650 508 'title' => __( 'Add class name if field is required', 'formidable' ),
651 509 'class' => 'show_field_custom_html',
652 510 ),
653 - 'error_class' => array(
511 + 'error_class' => array(
654 512 'label' => __( 'Error Class', 'formidable' ),
655 513 'title' => __( 'Add class name if field has an error on form submit', 'formidable' ),
656 514 'class' => 'show_field_custom_html',
657 515 ),
@@ -672,13 +530,13 @@
672 530 'label' => __( 'Delete Entry Link', 'formidable' ),
673 531 'class' => 'show_before_html show_after_html',
674 532 ),
675 533
676 - 'button_label' => array(
534 + 'button_label' => array(
677 535 'label' => __( 'Button Label', 'formidable' ),
678 536 'class' => 'show_submit_html',
679 537 ),
680 - 'button_action' => array(
538 + 'button_action' => array(
681 539 'label' => __( 'Button Hook', 'formidable' ),
682 540 'class' => 'show_submit_html',
683 541 ),
684 542 );
@@ -690,17 +548,14 @@
690 548 }
691 549
692 550 /**
693 551 * @since 4.0
694 - *
695 552 * @param array $args
696 - *
697 - * @return void
698 553 */
699 554 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();
555 + $class = isset( $args['class'] ) ? $args['class'] : '';
556 + $fields = FrmField::all_field_selection();
557 + $field = isset( $fields[ $args['type'] ] ) ? $fields[ $args['type'] ] : array();
703 558
704 559 self::prepare_field_type( $field );
705 560
706 561 if ( ! isset( $field['icon'] ) ) {
@@ -707,9 +562,8 @@
707 562 $field['icon'] = 'frmfont frm_pencil_icon';
708 563 }
709 564
710 565 $possible_email_field = FrmFieldFactory::field_has_property( $args['type'], 'holds_email_values' );
711 -
712 566 if ( $possible_email_field ) {
713 567 $class .= ' show_frm_not_email_to';
714 568 }
715 569
@@ -715,37 +569,23 @@
715 569
716 570 if ( 'url' === $args['type'] ) {
717 571 $class .= ' frm_insert_url';
718 572 }
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 573 ?>
734 574 <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>
575 + <a href="javascript:void(0)" class="frmids frm_insert_code"
576 + data-code="<?php echo esc_attr( $args['id'] ); ?>">
577 + <span>[<?php echo esc_attr( isset( $args['id_label'] ) ? $args['id_label'] : $args['id'] ); ?>]</span>
578 + <?php FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) ); ?>
579 + <?php echo esc_attr( FrmAppHelper::truncate( $args['name'], 60 ) ); ?>
741 580 </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>
581 + <a href="javascript:void(0)" class="frmkeys frm_insert_code frm_hidden"
582 + data-code="<?php echo esc_attr( $args['key'] ); ?>">
583 + <span>[<?php echo esc_attr( FrmAppHelper::truncate( isset( $args['key_label'] ) ? $args['key_label'] : $args['key'], 7 ) ); ?>]</span>
584 + <?php if ( isset( $field['icon'] ) ) { ?>
585 + <?php FrmAppHelper::icon_by_class( $field['icon'], array( 'aria-hidden' => 'true' ) ); ?>
586 + <?php } ?>
587 + <?php echo esc_attr( FrmAppHelper::truncate( $args['name'], 60 ) ); ?>
748 588 </a>
749 589 </li>
750 590 <?php
751 591 }
@@ -750,28 +590,10 @@
750 590 <?php
751 591 }
752 592
753 593 /**
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 594 * @since 4.0
770 - *
771 595 * @param array $args
772 - *
773 - * @return void
774 596 */
775 597 public static function insert_code_html( $args ) {
776 598 $defaults = array(
777 599 'class' => '',
@@ -787,12 +609,12 @@
787 609 <li class="<?php echo esc_attr( $args['class'] ); ?>">
788 610 <a href="javascript:void(0)" class="frm_insert_code <?php echo $has_tooltip ? 'frm_help' : ''; ?>"
789 611 <?php echo $has_tooltip ? 'title="' . esc_attr( $args['title'] ) . '"' : ''; ?>
790 612 data-code="<?php echo esc_attr( $args['code'] ); ?>">
791 - <?php echo esc_attr( FrmAppHelper::truncate( $args['label'], 60 ) ); ?>
792 613 <span>
793 614 [<?php echo esc_attr( FrmAppHelper::truncate( $args['code'], 10 ) ); ?>]
794 615 </span>
616 + <?php echo esc_attr( FrmAppHelper::truncate( $args['label'], 60 ) ); ?>
795 617 </a>
796 618 </li>
797 619 <?php
798 620 }
@@ -801,12 +623,8 @@
801 623 * Some field types in add-ons may have been added with only
802 624 * a field type and name.
803 625 *
804 626 * @since 4.0
805 - *
806 - * @param array|string $field
807 - *
808 - * @return void
809 627 */
810 628 public static function prepare_field_type( &$field ) {
811 629 if ( ! is_array( $field ) ) {
812 630 $field = array(
@@ -820,13 +638,9 @@
820 638 * Automatically add end section fields if they don't exist (2.0 migration)
821 639 *
822 640 * @since 2.0
823 641 *
824 - * @param object $form
825 - * @param array $fields
826 - * @param bool $reset_fields
827 - *
828 - * @return void
642 + * @param boolean $reset_fields
829 643 */
830 644 public static function auto_add_end_section_fields( $form, $fields, &$reset_fields ) {
831 645 if ( empty( $fields ) ) {
832 646 return;
@@ -836,12 +650,11 @@
836 650 $open = false;
837 651 $prev_order = false;
838 652 $add_order = 0;
839 653 $last_field = false;
840 -
841 654 foreach ( $fields as $field ) {
842 655 if ( $prev_order === $field->field_order ) {
843 - ++$add_order;
656 + $add_order ++;
844 657 }
845 658
846 659 if ( $add_order ) {
847 660 $reset_fields = true;
@@ -868,14 +681,14 @@
868 681 }
869 682
870 683 // There is already an end section here, so there is no need to create one.
871 684 $open = false;
872 - }//end switch
685 + }
873 686 $prev_order = $field->field_order;
874 687
875 688 $last_field = $field;
876 689 unset( $field );
877 - }//end foreach
690 + }
878 691
879 692 self::maybe_create_end_section( $open, $reset_fields, $add_order, $end_section_values, $last_field );
880 693 }
881 694
@@ -881,17 +694,8 @@
881 694
882 695 /**
883 696 * Create end section field if it doesn't exist. This is for migration from < 2.0
884 697 * 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 698 */
895 699 public static function maybe_create_end_section( &$open, &$reset_fields, &$add_order, $end_section_values, $field, $move = 'no' ) {
896 700 if ( ! $open ) {
897 701 return;
@@ -900,27 +704,18 @@
900 704 $end_section_values['field_order'] = $field->field_order + 1;
901 705
902 706 FrmField::create( $end_section_values );
903 707
904 - if ( $move === 'move' ) {
708 + if ( $move == 'move' ) {
905 709 // bump the order of current field unless we're at the end of the form
906 710 FrmField::update( $field->id, array( 'field_order' => $field->field_order + 2 ) );
907 711 }
908 712
909 - $add_order += 2;
713 + $add_order += 2;
910 714 $open = false;
911 715 $reset_fields = true;
912 716 }
913 717
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 718 public static function replace_shortcodes( $html, $form, $title = false, $description = false, $values = array() ) {
924 719 $codes = array(
925 720 'form_name' => $title,
926 721 'form_description' => $description,
@@ -925,15 +720,14 @@
925 720 'form_name' => $title,
926 721 'form_description' => $description,
927 722 'entry_key' => true,
928 723 );
929 -
930 724 foreach ( $codes as $code => $show ) {
931 725 if ( $code === 'form_name' ) {
932 726 $replace_with = $form->name;
933 727 } elseif ( $code === 'form_description' ) {
934 728 $replace_with = FrmAppHelper::use_wpautop( $form->description );
935 - } elseif ( $code === 'entry_key' && ! empty( $_GET ) && isset( $_GET['entry'] ) ) {
729 + } elseif ( $code === 'entry_key' && isset( $_GET ) && isset( $_GET['entry'] ) ) {
936 730 $replace_with = FrmAppHelper::simple_get( 'entry' );
937 731 } else {
938 732 $replace_with = '';
939 733 }
@@ -940,12 +734,12 @@
940 734
941 735 FrmShortcodeHelper::remove_inline_conditions( ( FrmAppHelper::is_true( $show ) && $replace_with != '' ), $code, $replace_with, $html );
942 736 }
943 737
944 - // Replace [form_key].
738 + //replace [form_key]
945 739 $html = str_replace( '[form_key]', $form->form_key, $html );
946 740
947 - // Replace [frmurl].
741 + //replace [frmurl]
948 742 $html = str_replace( '[frmurl]', FrmFieldsHelper::dynamic_default_values( 'frmurl' ), $html );
949 743
950 744 if ( strpos( $html, '[button_label]' ) ) {
951 745 add_filter( 'frm_submit_button', 'FrmFormsHelper::submit_button_label', 1 );
@@ -963,12 +757,8 @@
963 757 if ( strpos( $html, '[if save_draft]' ) ) {
964 758 $html = preg_replace( '/(\[if\s+save_draft\])(.*?)(\[\/if\s+save_draft\])/mis', '', $html );
965 759 }
966 760
967 - if ( strpos( $html, '[if start_over]' ) ) {
968 - $html = preg_replace( '/(\[if\s+start_over\])(.*?)(\[\/if\s+start_over\])/mis', '', $html );
969 - }
970 -
971 761 if ( apply_filters( 'frm_do_html_shortcodes', true ) ) {
972 762 $html = do_shortcode( $html );
973 763 }
974 764
@@ -974,13 +764,8 @@
974 764
975 765 return $html;
976 766 }
977 767
978 - /**
979 - * @param string $submit
980 - *
981 - * @return string
982 - */
983 768 public static function submit_button_label( $submit ) {
984 769 if ( ! $submit ) {
985 770 $frm_settings = FrmAppHelper::get_settings();
986 771 $submit = $frm_settings->submit_value;
@@ -993,26 +778,18 @@
993 778 * If the Formidable styling isn't being loaded,
994 779 * use inline styling to hide the element
995 780 *
996 781 * @since 2.03.05
997 - *
998 - * @return void
999 782 */
1000 783 public static function maybe_hide_inline() {
1001 784 $frm_settings = FrmAppHelper::get_settings();
1002 -
1003 - if ( $frm_settings->load_style === 'none' ) {
785 + if ( $frm_settings->load_style == 'none' ) {
1004 786 echo ' style="display:none;"';
1005 - } elseif ( $frm_settings->load_style === 'dynamic' ) {
787 + } elseif ( $frm_settings->load_style == 'dynamic' ) {
1006 788 FrmStylesController::enqueue_style();
1007 789 }
1008 790 }
1009 791
1010 - /**
1011 - * @param array|bool|int|object|string $form
1012 - *
1013 - * @return string|null
1014 - */
1015 792 public static function get_form_style_class( $form = false ) {
1016 793 $style = self::get_form_style( $form );
1017 794 $class = ' with_frm_style';
1018 795
@@ -1018,10 +795,11 @@
1018 795
1019 796 if ( empty( $style ) ) {
1020 797 if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) ) {
1021 798 return $class;
799 + } else {
800 + return;
1022 801 }
1023 - return;
1024 802 }
1025 803
1026 804 // If submit button needs to be inline or centered.
1027 805 if ( is_object( $form ) ) {
@@ -1053,9 +831,8 @@
1053 831 *
1054 832 * @since 5.0.12
1055 833 *
1056 834 * @param array $form
1057 - *
1058 835 * @return bool
1059 836 */
1060 837 private static function form_should_be_inline_and_missing_class( $form ) {
1061 838 if ( isset( $form['form_class'] ) && false !== strpos( ' ' . $form['form_class'] . ' ', ' frm_inline_form ' ) ) {
@@ -1067,9 +844,9 @@
1067 844
1068 845 /**
1069 846 * Returns appropriate class if form has top labels
1070 847 *
1071 - * @param array $form
848 + * @param $form
1072 849 *
1073 850 * @return string
1074 851 */
1075 852 private static function maybe_align_fields_top( $form ) {
@@ -1078,9 +855,9 @@
1078 855
1079 856 /**
1080 857 * Determine if a form has fields with top labels so submit button can be aligned properly
1081 858 *
1082 - * @param array $form
859 + * @param $form
1083 860 *
1084 861 * @return bool
1085 862 */
1086 863 private static function form_has_top_labels( $form ) {
@@ -1088,20 +865,16 @@
1088 865 return false;
1089 866 }
1090 867
1091 868 $fields = $form['fields'];
1092 -
1093 869 if ( count( $fields ) <= 0 ) {
1094 870 return false;
1095 871 }
1096 872
1097 - // Start from the fields closest to the submit button.
1098 - $fields = array_reverse( $fields );
1099 -
873 + $fields = array_reverse( $fields ); // start from the fields closest to the submit button
1100 874 foreach ( $fields as $field ) {
1101 - $type = $field['original_type'] ?? $field['type'];
875 + $type = isset( $field['original_type'] ) ? $field['original_type'] : $field['type'];
1102 876 $has_input = FrmFieldFactory::field_has_property( $type, 'has_input' );
1103 -
1104 877 if ( $has_input ) {
1105 878 return self::field_has_top_label( $field, $form );
1106 879 }
1107 880 }
@@ -1111,10 +884,10 @@
1111 884
1112 885 /**
1113 886 * Check if a field's label position is set to "top"
1114 887 *
1115 - * @param array $field
1116 - * @param bool|object|string $form
888 + * @param $field
889 + * @param $form
1117 890 *
1118 891 * @return bool
1119 892 */
1120 893 private static function field_has_top_label( $field, $form ) {
@@ -1123,33 +896,30 @@
1123 896 return in_array( $label_position, array( 'top', 'inside', 'hidden' ) );
1124 897 }
1125 898
1126 899 /**
1127 - * @param array|bool|int|object|string $form
900 + * @param object|string|boolean $form
1128 901 *
1129 902 * @return string
1130 903 */
1131 904 public static function get_form_style( $form ) {
1132 905 $style = 1;
1133 -
1134 906 if ( empty( $form ) || 'default' === $form ) {
1135 907 return $style;
1136 - }
1137 -
1138 - if ( is_object( $form ) && $form->parent_form_id ) {
908 + } elseif ( is_object( $form ) && $form->parent_form_id ) {
1139 909 // get the parent form if this is a child
1140 910 $form = $form->parent_form_id;
1141 - } elseif ( is_array( $form ) && ! empty( $form['parent_form_id'] ) ) {
911 + } elseif ( is_array( $form ) && isset( $form['parent_form_id'] ) && $form['parent_form_id'] ) {
1142 912 $form = $form['parent_form_id'];
1143 913 } elseif ( is_array( $form ) && isset( $form['custom_style'] ) ) {
1144 914 $style = $form['custom_style'];
1145 915 }
1146 916
1147 - if ( $form && ( is_string( $form ) || is_int( $form ) ) ) {
917 + if ( $form && is_string( $form ) ) {
1148 918 $form = FrmForm::getOne( $form );
1149 919 }
1150 920
1151 - $style = $form && is_object( $form ) && isset( $form->options['custom_style'] ) ? $form->options['custom_style'] : $style;
921 + $style = ( $form && is_object( $form ) && isset( $form->options['custom_style'] ) ) ? $form->options['custom_style'] : $style;
1152 922
1153 923 return $style;
1154 924 }
1155 925
@@ -1155,13 +925,11 @@
1155 925
1156 926 /**
1157 927 * Display the validation error messages when an entry is submitted
1158 928 *
929 + * @param array $args - includes img, errors
930 + *
1159 931 * @since 2.0.6
1160 - *
1161 - * @param array $args Includes img, errors.
1162 - *
1163 - * @return void
1164 932 */
1165 933 public static function show_errors( $args ) {
1166 934 $invalid_msg = self::get_invalid_error_message( $args );
1167 935
@@ -1185,13 +953,11 @@
1185 953 * Display the error message in the front-end along with the image if set
1186 954 * The image was removed from the styling settings, but it may still be set with a hook
1187 955 * If the message in the global settings is empty, show every validation message in the error box
1188 956 *
957 + * @param array $args - includes img, errors, and show_img
958 + *
1189 959 * @since 2.0.6
1190 - *
1191 - * @param array $args Includes img, errors, and show_img.
1192 - *
1193 - * @return void
1194 960 */
1195 961 public static function show_error( $args ) {
1196 962 // remove any blank messages
1197 963 $args['errors'] = array_filter( (array) $args['errors'] );
@@ -1196,11 +962,10 @@
1196 962 // remove any blank messages
1197 963 $args['errors'] = array_filter( (array) $args['errors'] );
1198 964
1199 965 $line_break_first = $args['show_img'];
1200 -
1201 966 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 ) ) {
967 + if ( $line_break_first && ! is_numeric( $error_key ) && ( $error_key == 'cptch_number' || strpos( $error_key, 'field' ) === 0 ) ) {
1203 968 continue;
1204 969 }
1205 970
1206 971 $id = str_replace( 'field', 'field_', $error_key );
@@ -1206,9 +971,9 @@
1206 971 $id = str_replace( 'field', 'field_', $error_key );
1207 972 echo '<div id="' . esc_attr( $id ) . '_error">';
1208 973
1209 974 if ( $args['show_img'] && ! empty( $args['img'] ) ) {
1210 - echo '<img src="' . esc_url( $args['img'] ) . '" alt="" />';
975 + echo '<img src="' . esc_attr( $args['img'] ) . '" alt="" />';
1211 976 } else {
1212 977 $args['show_img'] = true;
1213 978 }
1214 979
@@ -1217,37 +982,34 @@
1217 982 echo '</div>';
1218 983 }
1219 984 }
1220 985
1221 - /**
1222 - * @param int|string $id
1223 - *
1224 - * @return void
1225 - */
1226 986 public static function maybe_get_scroll_js( $id ) {
1227 987 $offset = apply_filters( 'frm_scroll_offset', 4, array( 'form_id' => $id ) );
1228 -
1229 988 if ( $offset != - 1 ) {
1230 989 self::get_scroll_js( $id );
1231 990 }
1232 991 }
1233 992
993 + public static function get_scroll_js( $form_id ) {
994 + echo '<script type="text/javascript">document.addEventListener(\'DOMContentLoaded\',function(){frmFrontForm.scrollMsg(' . (int) $form_id . ');})</script>';
995 + }
996 +
1234 997 /**
1235 - * @param int|string $form_id
1236 - *
1237 - * @return void
998 + * @since 3.0
1238 999 */
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>';
1000 + public static function actions_dropdown( $atts ) {
1001 + if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
1002 + $status = $atts['status'];
1003 + $form_id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
1004 + $trash_link = self::delete_trash_info( $form_id, $status );
1005 + $links = self::get_action_links( $form_id, $status );
1006 + include( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/actions-dropdown.php' );
1007 + }
1241 1008 }
1242 1009
1243 1010 /**
1244 1011 * @since 3.0
1245 - *
1246 - * @param int|object|string $form_id
1247 - * @param mixed $form
1248 - *
1249 - * @return array
1250 1012 */
1251 1013 public static function get_action_links( $form_id, $form ) {
1252 1014 if ( ! is_object( $form ) ) {
1253 1015 $form = FrmForm::getOne( $form_id );
@@ -1254,9 +1016,8 @@
1254 1016 }
1255 1017
1256 1018 $actions = array();
1257 1019 $trash_links = self::delete_trash_links( $form_id );
1258 -
1259 1020 if ( 'trash' == $form->status ) {
1260 1021 $actions['restore'] = $trash_links['restore'];
1261 1022
1262 1023 if ( current_user_can( 'frm_delete_forms' ) ) {
@@ -1263,9 +1024,8 @@
1263 1024 $actions['trash'] = $trash_links['delete'];
1264 1025 }
1265 1026 } elseif ( current_user_can( 'frm_edit_forms' ) ) {
1266 1027 $duplicate_link = '?page=formidable&frm_action=duplicate&id=' . $form_id;
1267 -
1268 1028 if ( $form->is_template ) {
1269 1029 $actions['frm_duplicate'] = array(
1270 1030 'url' => wp_nonce_url( $duplicate_link ),
1271 1031 'label' => __( 'Create Form from Template', 'formidable' ),
@@ -1279,18 +1039,13 @@
1279 1039 );
1280 1040 }
1281 1041
1282 1042 $actions['trash'] = self::delete_trash_info( $form_id, $form->status );
1283 - }//end if
1043 + }
1284 1044
1285 1045 return $actions;
1286 1046 }
1287 1047
1288 - /**
1289 - * @param int|object|string $data
1290 - *
1291 - * @return string
1292 - */
1293 1048 public static function edit_form_link( $data ) {
1294 1049 $form_id = self::get_form_id_from_data( $data );
1295 1050
1296 1051 if ( ! $form_id ) {
@@ -1301,37 +1056,19 @@
1301 1056 $link = '<a href="' . esc_url( FrmForm::get_edit_link( $form_id ) ) . '">' . esc_html( $label ) . '</a>';
1302 1057 return $link;
1303 1058 }
1304 1059
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 1060 public static function edit_form_link_label( $data ) {
1322 1061 $name = self::get_form_name_from_data( $data );
1323 -
1324 1062 if ( ! $name ) {
1325 - return self::get_no_title_text();
1063 + return __( '(no title)', 'formidable' );
1326 1064 }
1327 1065 return FrmAppHelper::truncate( $name, 40 );
1328 1066 }
1329 1067
1330 1068 /**
1331 - * @param int|object|string $data
1332 - *
1333 - * @return int|string
1069 + * @param mixed data
1070 + * @return int
1334 1071 */
1335 1072 private static function get_form_id_from_data( $data ) {
1336 1073 if ( is_object( $data ) ) {
1337 1074 $form_id = $data->id;
@@ -1342,9 +1079,8 @@
1342 1079 }
1343 1080
1344 1081 /**
1345 1082 * @param mixed $data
1346 - *
1347 1083 * @return string
1348 1084 */
1349 1085 private static function get_form_name_from_data( $data ) {
1350 1086 if ( is_object( $data ) ) {
@@ -1355,15 +1091,8 @@
1355 1091 }
1356 1092 return $form_name;
1357 1093 }
1358 1094
1359 - /**
1360 - * @param int $id
1361 - * @param string $status
1362 - * @param string $length
1363 - *
1364 - * @return string
1365 - */
1366 1095 public static function delete_trash_link( $id, $status, $length = 'label' ) {
1367 1096 $link_details = self::delete_trash_info( $id, $status );
1368 1097
1369 1098 return self::format_link_html( $link_details, $length );
@@ -1370,20 +1099,13 @@
1370 1099 }
1371 1100
1372 1101 /**
1373 1102 * @since 3.0
1374 - *
1375 - * @param array $link_details
1376 - * @param string $length
1377 - *
1378 - * @return string
1379 1103 */
1380 1104 public static function format_link_html( $link_details, $length = 'label' ) {
1381 1105 $link = '';
1382 -
1383 1106 if ( ! empty( $link_details ) ) {
1384 1107 $link = '<a href="' . esc_url( $link_details['url'] ) . '" class="frm-trash-link"';
1385 -
1386 1108 if ( isset( $link_details['data'] ) ) {
1387 1109 foreach ( $link_details['data'] as $data => $value ) {
1388 1110 $link .= ' data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '"';
1389 1111 }
@@ -1390,13 +1112,12 @@
1390 1112 } elseif ( isset( $link_details['confirm'] ) ) {
1391 1113 $link .= ' onclick="return confirm(\'' . esc_attr( $link_details['confirm'] ) . '\')"';
1392 1114 }
1393 1115
1394 - $label = ( $link_details[ $length ] ?? $link_details['label'] );
1395 -
1396 - if ( $length === 'icon' && isset( $link_details[ $length ] ) ) {
1116 + $label = ( isset( $link_details[ $length ] ) ? $link_details[ $length ] : $link_details['label'] );
1117 + if ( $length == 'icon' && isset( $link_details[ $length ] ) ) {
1397 1118 $label = '<span class="' . $label . '" title="' . esc_attr( $link_details['label'] ) . '" aria-hidden="true"></span>';
1398 - $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"';
1119 + $link .= ' aria-label="' . esc_attr( $link_details['label'] ) . '"';
1399 1120 }
1400 1121
1401 1122 $link .= '>' . $label . '</a>';
1402 1123 }
@@ -1405,18 +1126,13 @@
1405 1126 }
1406 1127
1407 1128 /**
1408 1129 * @since 3.0
1409 - *
1410 - * @param int $id
1411 - * @param string $status
1412 - *
1413 - * @return array
1414 1130 */
1415 1131 public static function delete_trash_info( $id, $status ) {
1416 1132 $labels = self::delete_trash_links( $id );
1417 1133
1418 - if ( 'trash' === $status ) {
1134 + if ( 'trash' == $status ) {
1419 1135 $info = $labels['restore'];
1420 1136 } elseif ( current_user_can( 'frm_delete_forms' ) ) {
1421 1137 if ( EMPTY_TRASH_DAYS ) {
1422 1138 $info = $labels['trash'];
@@ -1431,14 +1147,10 @@
1431 1147 }
1432 1148
1433 1149 /**
1434 1150 * @since 3.0
1435 - *
1436 - * @param int $id
1437 - *
1438 - * @return array
1439 1151 */
1440 - public static function delete_trash_links( $id ) {
1152 + private static function delete_trash_links( $id ) {
1441 1153 $current_page = FrmAppHelper::get_simple_request( array( 'param' => 'form_type' ) );
1442 1154 $base_url = '?page=formidable&form_type=' . $current_page . '&id=' . $id;
1443 1155
1444 1156 return array(
@@ -1451,12 +1163,9 @@
1451 1163 'label' => __( 'Move Form to Trash', 'formidable' ),
1452 1164 'short' => __( 'Trash', 'formidable' ),
1453 1165 'url' => wp_nonce_url( $base_url . '&frm_action=trash', 'trash_form_' . absint( $id ) ),
1454 1166 '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 - ),
1167 + 'data' => array( 'frmverify' => __( 'Do you want to move this form to the trash?', 'formidable' ) ),
1459 1168 ),
1460 1169 'delete' => array(
1461 1170 'label' => __( 'Delete Permanently', 'formidable' ),
1462 1171 'short' => __( 'Delete', 'formidable' ),
@@ -1462,12 +1171,9 @@
1462 1171 'short' => __( 'Delete', 'formidable' ),
1463 1172 'url' => wp_nonce_url( $base_url . '&frm_action=destroy', 'destroy_form_' . absint( $id ) ),
1464 1173 'confirm' => __( 'Are you sure you want to delete this form and all its entries?', 'formidable' ),
1465 1174 '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 - ),
1175 + '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 1176 ),
1471 1177 );
1472 1178 }
1473 1179
@@ -1472,38 +1178,36 @@
1472 1178 }
1473 1179
1474 1180 /**
1475 1181 * @since 3.0
1476 - *
1477 - * @return array
1478 1182 */
1479 1183 public static function css_classes() {
1480 1184 $classes = array(
1481 - 'frm_total' => array(
1185 + 'frm_total' => array(
1482 1186 'label' => __( 'Total', 'formidable' ),
1483 1187 'title' => __( 'Add this to a read-only field to display the text in bold without a border or background.', 'formidable' ),
1484 1188 ),
1485 - 'frm_total_big' => array(
1189 + 'frm_total_big' => array(
1486 1190 'label' => __( 'Big Total', 'formidable' ),
1487 1191 'title' => __( 'Add this to a read-only field to display the text in large, bold text without a border or background.', 'formidable' ),
1488 1192 ),
1489 - 'frm_scroll_box' => array(
1193 + 'frm_scroll_box' => array(
1490 1194 'label' => __( 'Scroll Box', 'formidable' ),
1491 1195 '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 1196 ),
1493 - 'frm_first' => array(
1197 + 'frm_first' => array(
1494 1198 'label' => __( 'First', 'formidable' ),
1495 1199 'title' => __( 'Add this to the first field in each row along with a width. ie frm_first frm4', 'formidable' ),
1496 1200 ),
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' ),
1201 + 'frm_alignright' => __( 'Right', 'formidable' ),
1202 + 'frm_grid_first' => __( 'First Grid Row', 'formidable' ),
1203 + 'frm_grid' => __( 'Even Grid Row', 'formidable' ),
1204 + 'frm_grid_odd' => __( 'Odd Grid Row', 'formidable' ),
1501 1205 'frm_color_block' => array(
1502 1206 'label' => __( 'Color Block', 'formidable' ),
1503 1207 'title' => __( 'Add a background color to the field or section.', 'formidable' ),
1504 1208 ),
1505 - 'frm_capitalize' => array(
1209 + 'frm_capitalize' => array(
1506 1210 'label' => __( 'Capitalize', 'formidable' ),
1507 1211 'title' => __( 'Automatically capitalize the first letter in each word.', 'formidable' ),
1508 1212 ),
1509 1213 );
@@ -1510,11 +1214,8 @@
1510 1214
1511 1215 return apply_filters( 'frm_layout_classes', $classes );
1512 1216 }
1513 1217
1514 - /**
1515 - * @return array
1516 - */
1517 1218 public static function grid_classes() {
1518 1219 return array(
1519 1220 'frm_half' => '1/2',
1520 1221 'frm_third' => '1/3',
@@ -1528,17 +1229,11 @@
1528 1229 }
1529 1230
1530 1231 /**
1531 1232 * @since 3.0
1532 - *
1533 - * @param mixed $style
1534 - * @param string $class
1535 - *
1536 - * @return string
1537 1233 */
1538 1234 public static function style_class_label( $style, $class ) {
1539 1235 $label = '';
1540 -
1541 1236 if ( empty( $style ) ) {
1542 1237 $label = $class;
1543 1238 } elseif ( ! is_array( $style ) ) {
1544 1239 $label = $style;
@@ -1548,13 +1243,8 @@
1548 1243
1549 1244 return $label;
1550 1245 }
1551 1246
1552 - /**
1553 - * @param string $status
1554 - *
1555 - * @return string
1556 - */
1557 1247 public static function status_nice_name( $status ) {
1558 1248 $nice_names = array(
1559 1249 'draft' => __( 'Draft', 'formidable' ),
1560 1250 'trash' => __( 'Trash', 'formidable' ),
@@ -1560,9 +1250,9 @@
1560 1250 'trash' => __( 'Trash', 'formidable' ),
1561 1251 'publish' => __( 'Published', 'formidable' ),
1562 1252 );
1563 1253
1564 - if ( ! in_array( $status, array_keys( $nice_names ), true ) ) {
1254 + if ( ! in_array( $status, array_keys( $nice_names ) ) ) {
1565 1255 $status = 'publish';
1566 1256 }
1567 1257
1568 1258 $name = $nice_names[ $status ];
@@ -1569,99 +1259,70 @@
1569 1259
1570 1260 return $name;
1571 1261 }
1572 1262
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();
1263 + public static function template_icon( $categories ) {
1264 + $ignore = self::ignore_template_categories();
1595 1265 $categories = array_diff( $categories, $ignore );
1596 1266
1597 - // Define icons mapping.
1598 1267 $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' ),
1268 + 'WooCommerce' => array( 'woocommerce', 'var(--purple)' ),
1269 + 'Post' => array( 'wordpress', 'rgb(0,160,210)' ),
1270 + 'User Registration' => array( 'register', 'var(--pink)' ),
1271 + 'PayPal' => array( 'paypal' ),
1272 + 'Stripe' => array( 'credit_card', 'var(--green)' ),
1273 + 'Twilio' => array( 'sms', 'rgb(0,160,210)' ),
1274 + 'Payment' => array( 'credit_card', 'var(--green)' ),
1275 + 'Health and Wellness' => array( 'heart', 'var(--pink)' ),
1276 + 'Event Planning' => array( 'calendar', 'var(--orange)' ),
1277 + 'Real Estate' => array( 'house', 'var(--purple)' ),
1278 + 'Calculator' => array( 'calculator', 'var(--purple)' ),
1279 + 'Registrations' => array( 'address_card' ),
1280 + 'Customer Service' => array( 'users_solid', 'var(--pink)' ),
1281 + 'Education' => array( 'pencil', 'var(--primary-color)' ),
1282 + 'Marketing' => array( 'eye', 'rgb(0,160,210)' ),
1283 + 'Feedback' => array( 'smile', 'var(--green)' ),
1284 + 'Business Operations' => array( 'case' ),
1285 + 'Contact Form' => array( 'email' ),
1286 + 'Survey' => array( 'comment', 'var(--primary-color)' ),
1287 + 'Application Form' => array( 'align_right', 'rgb(0,160,210)' ),
1288 + 'Quiz' => array( 'percent' ),
1289 + '' => array( 'align_right' ),
1627 1290 );
1628 1291
1629 - // Determine the icon to be used.
1292 + $icons[ __( 'My Templates', 'formidable' ) ] = array( 'user', 'var(--orange)' );
1293 +
1630 1294 $icon = $icons[''];
1631 1295
1632 1296 if ( count( $categories ) === 1 ) {
1633 1297 $category = reset( $categories );
1634 - $icon = $icons[ $category ] ?? $icon;
1298 + $icon = isset( $icons[ $category ] ) ? $icons[ $category ] : $icon;
1635 1299 } elseif ( ! empty( $categories ) ) {
1636 - $icons = array_intersect_key( $icons, array_flip( $categories ) );
1637 - $icon = reset( $icons );
1300 + foreach ( $icons as $cat => $icon ) {
1301 + if ( ! in_array( $cat, $categories ) ) {
1302 + unset( $icons[ $cat ] );
1303 + }
1304 + }
1305 + $icon = reset( $icons );
1638 1306 }
1639 1307
1640 - // Prepare variables for output.
1641 - $icon_name = $icon[0];
1642 - $bg_color = $icon[1] ?? '';
1308 + echo '<span class="frm-inner-circle" ' . ( isset( $icon[1] ) ? 'style="background-color:' . esc_attr( $icon[1] ) : '' ) . '">';
1309 + FrmAppHelper::icon_by_class( 'frmfont frm_' . $icon[0] . '_icon' );
1310 + echo '<span class="frm_hidden">';
1311 + FrmAppHelper::icon_by_class( 'frmfont frm_lock_icon' );
1312 + echo '</span>';
1313 + echo '</span>';
1314 + }
1643 1315
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' );
1652 - echo '</span>';
1316 + /**
1317 + * @since 4.03.01
1318 + */
1319 + public static function ignore_template_categories() {
1320 + return array( 'Business', 'Elite', 'Personal', 'Creator', 'Basic', 'free' );
1653 1321 }
1654 1322
1655 1323 /**
1656 - * Get template install link.
1657 - *
1658 1324 * @since 4.02
1659 - *
1660 - * @param array $template Template details.
1661 - * @param array $args Additional arguments.
1662 - *
1663 - * @return array The link attributes.
1664 1325 */
1665 1326 public static function get_template_install_link( $template, $args ) {
1666 1327 $defaults = array(
1667 1328 'class' => 'install-now',
@@ -1676,8 +1337,13 @@
1676 1337 'class' => 'frm-install-template',
1677 1338 'href' => 'rel',
1678 1339 'atts' => '',
1679 1340 );
1341 + } elseif ( self::plan_is_allowed( $args ) ) {
1342 + $link = array(
1343 + 'url' => FrmAppHelper::admin_upgrade_link( 'addons', 'account/downloads/' ) . '&utm_content=' . $template['slug'],
1344 + 'label' => __( 'Renew', 'formidable' ),
1345 + );
1680 1346 } else {
1681 1347 $link = array(
1682 1348 'url' => $args['pricing'],
1683 1349 'label' => __( 'Upgrade', 'formidable' ),
@@ -1700,23 +1366,20 @@
1700 1366 if ( empty( $args['license_type'] ) ) {
1701 1367 return false;
1702 1368 }
1703 1369
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;
1370 + $included = $args['license_type'] === strtolower( $args['plan_required'] );
1708 1371
1709 - if ( $included || ! in_array( $plan_required, $plans, true ) ) {
1372 + $plans = array( 'free', 'personal', 'business', 'elite' );
1373 + if ( $included || ! in_array( strtolower( $args['plan_required'] ), $plans, true ) ) {
1710 1374 return $included;
1711 1375 }
1712 1376
1713 1377 foreach ( $plans as $plan ) {
1714 - if ( $included || $plan === $license_type ) {
1378 + if ( $included || $plan === $args['license_type'] ) {
1715 1379 break;
1716 1380 }
1717 -
1718 - $included = $plan === $plan_required;
1381 + $included = $plan === strtolower( $args['plan_required'] );
1719 1382 }
1720 1383
1721 1384 return $included;
1722 1385 }
@@ -1721,17 +1384,20 @@
1721 1384 return $included;
1722 1385 }
1723 1386
1724 1387 /**
1388 + * @since 4.02
1389 + */
1390 + public static function template_install_html( $link, $class = '' ) {
1391 + $link['class'] .= ' ' . $class;
1392 + 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"' : '' ) . '>';
1393 + }
1394 +
1395 + /**
1725 1396 * If a template or add-on cannot be installed, show a message
1726 1397 * about which plan is required.
1727 1398 *
1728 1399 * @since 4.0
1729 - *
1730 - * @param string $requires
1731 - * @param string $link
1732 - *
1733 - * @return void
1734 1400 */
1735 1401 public static function show_plan_required( $requires, $link ) {
1736 1402 if ( empty( $requires ) ) {
1737 1403 return;
@@ -1738,9 +1404,9 @@
1738 1404 }
1739 1405
1740 1406 ?>
1741 1407 <p class="frm_plan_required">
1742 - <?php esc_html_e( 'Plan required:', 'formidable' ); ?>
1408 + <?php esc_html_e( 'License plan required:', 'formidable' ); ?>
1743 1409 <a href="<?php echo esc_url( $link ); ?>" target="_blank" rel="noopener">
1744 1410 <?php echo esc_html( $requires ); ?>
1745 1411 </a>
1746 1412 </p>
@@ -1750,10 +1416,9 @@
1750 1416 /**
1751 1417 * @since 4.0
1752 1418 *
1753 1419 * @param array $item
1754 - *
1755 - * @return false|string
1420 + * @return string|false
1756 1421 */
1757 1422 public static function get_plan_required( &$item ) {
1758 1423 if ( ! isset( $item['categories'] ) || ! is_array( $item['categories'] ) || ! empty( $item['url'] ) ) {
1759 1424 return false;
@@ -1758,15 +1423,18 @@
1758 1423 if ( ! isset( $item['categories'] ) || ! is_array( $item['categories'] ) || ! empty( $item['url'] ) ) {
1759 1424 return false;
1760 1425 }
1761 1426
1762 - $plans = self::get_license_types();
1427 + $plans = array( 'free', 'Basic', 'Personal', 'Plus', 'Creator', 'Business', 'Elite' );
1763 1428
1764 1429 foreach ( $item['categories'] as $k => $category ) {
1765 1430 if ( in_array( $category, $plans, true ) ) {
1766 1431 unset( $item['categories'][ $k ] );
1767 1432
1768 - $category = self::convert_legacy_package_names( $category );
1433 + if ( in_array( $category, array( 'Creator', 'Personal' ), true ) ) {
1434 + // Show the current package name.
1435 + $category = 'Plus';
1436 + }
1769 1437
1770 1438 return $category;
1771 1439 }
1772 1440 }
@@ -1774,54 +1442,8 @@
1774 1442 return false;
1775 1443 }
1776 1444
1777 1445 /**
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 1446 * Checks for warnings to be displayed after form settings are saved.
1825 1447 *
1826 1448 * @since 4.04
1827 1449 *
@@ -1857,9 +1479,9 @@
1857 1479
1858 1480 $options = $values['options'];
1859 1481 FrmAppHelper::sanitize_with_html( $options );
1860 1482
1861 - if ( ! isset( $options['success_action'] ) || $options['success_action'] !== 'redirect' || ! isset( $options['success_url'] ) ) {
1483 + if ( ( ! isset( $options['success_action'] ) ) || $options['success_action'] !== 'redirect' || ! isset( $options['success_url'] ) ) {
1862 1484 return false;
1863 1485 }
1864 1486
1865 1487 $unsafe_params_in_redirect = self::get_unsafe_params( $options['success_url'] );
@@ -1877,9 +1499,8 @@
1877 1499 * @return array An array of params whose names are reserved words or an empty array.
1878 1500 */
1879 1501 private static function get_unsafe_params( $url ) {
1880 1502 $redirect_components = parse_url( $url );
1881 -
1882 1503 if ( empty( $redirect_components['query'] ) ) {
1883 1504 return array();
1884 1505 }
1885 1506 parse_str( $redirect_components['query'], $redirect_params );
@@ -1977,8 +1598,34 @@
1977 1598 );
1978 1599 }
1979 1600
1980 1601 /**
1602 + * Check an array of templates, determine how many the logged in user can use
1603 + *
1604 + * @param array $templates
1605 + * @param array $args
1606 + * @return int
1607 + */
1608 + public static function available_count( $templates, $args ) {
1609 + return array_reduce(
1610 + $templates,
1611 + function( $total, $template ) use ( $args ) {
1612 + if ( ! empty( $template['url'] ) ) {
1613 + return $total + 1;
1614 + }
1615 +
1616 + $args['plan_required'] = self::get_plan_required( $template );
1617 + if ( self::plan_is_allowed( $args ) ) {
1618 + return $total + 1;
1619 + }
1620 +
1621 + return $total;
1622 + },
1623 + 0
1624 + );
1625 + }
1626 +
1627 + /**
1981 1628 * Make sure the field shortcodes in a url always add the sanitize_url=1 option if nothing is defined.
1982 1629 * This is to prevent some field characters like ', @, and | from being stripped from the redirect URL.
1983 1630 *
1984 1631 * @since 5.0.16
@@ -1984,9 +1631,8 @@
1984 1631 * @since 5.0.16
1985 1632 *
1986 1633 * @param string $url
1987 1634 * @param int $form_id
1988 - *
1989 1635 * @return string
1990 1636 */
1991 1637 public static function maybe_add_sanitize_url_attr( $url, $form_id ) {
1992 1638 if ( false === strpos( $url, '[' ) ) {
@@ -1994,9 +1640,8 @@
1994 1640 return $url;
1995 1641 }
1996 1642
1997 1643 $parsed = wp_parse_url( $url );
1998 -
1999 1644 if ( empty( $parsed['query'] ) ) {
2000 1645 // Do nothing if no query can be detected in the url string.
2001 1646 return $url;
2002 1647 }
@@ -2004,9 +1649,8 @@
2004 1649 $original_query = $parsed['query'];
2005 1650 $query = $parsed['query'];
2006 1651
2007 1652 $shortcodes = FrmFieldsHelper::get_shortcodes( $query, $form_id );
2008 -
2009 1653 if ( empty( $shortcodes[0] ) ) {
2010 1654 // No shortcodes found, do nothing.
2011 1655 return $url;
2012 1656 }
@@ -2024,17 +1668,15 @@
2024 1668 continue;
2025 1669 }
2026 1670
2027 1671 $new_shortcode = '[' . $shortcodes[2][ $key ];
2028 -
2029 1672 if ( $options ) {
2030 1673 $new_shortcode .= ' ' . $options;
2031 1674 }
2032 -
2033 1675 $new_shortcode .= ' sanitize_url=1]';
2034 1676
2035 1677 $query = str_replace( $shortcode, $new_shortcode, $query );
2036 - }//end foreach
1678 + }
2037 1679
2038 1680 if ( $query === $original_query ) {
2039 1681 return $url;
2040 1682 }
@@ -2039,189 +1681,6 @@
2039 1681 return $url;
2040 1682 }
2041 1683
2042 1684 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 1685 }
2227 1686 }