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