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