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