PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.13
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.13
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/FrmEntriesHelper.php +135 -254 6.32.1 → 6.13 View file →
@@ -8,9 +8,8 @@
8 8 /**
9 9 * "Submitted" entry status.
10 10 *
11 11 * @since 6.4.2
12 - *
13 12 * @var int
14 13 */
15 14 const SUBMITTED_ENTRY_STATUS = 0;
16 15
@@ -17,21 +16,12 @@
17 16 /**
18 17 * "Draft" entry status.
19 18 *
20 19 * @since 6.4.2
21 - *
22 20 * @var int
23 21 */
24 22 const DRAFT_ENTRY_STATUS = 1;
25 23
26 - /**
27 - * @param mixed $fields
28 - * @param object|string $form
29 - * @param bool $reset
30 - * @param array $args
31 - *
32 - * @return array
33 - */
34 24 public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) {
35 25 remove_action( 'media_buttons', 'FrmFormsController::insert_form_button' );
36 26
37 27 $values = array(
@@ -40,10 +30,9 @@
40 30 'item_key' => '',
41 31 );
42 32
43 33 $values['fields'] = array();
44 -
45 - if ( ! $fields ) {
34 + if ( empty( $fields ) ) {
46 35 return apply_filters( 'frm_setup_new_entry', $values );
47 36 }
48 37
49 38 foreach ( (array) $fields as $field ) {
@@ -48,15 +37,16 @@
48 37
49 38 foreach ( (array) $fields as $field ) {
50 39 $original_default = $field->default_value;
51 40 self::prepare_field_default_value( $field );
52 - $new_value = self::get_field_value_for_new_entry( $field, $reset, $args );
41 + $new_value = self::get_field_value_for_new_entry( $field, $reset, $args );
42 +
53 43 $field_array = FrmAppHelper::start_field_array( $field );
54 44 $field_array['value'] = $new_value;
55 45 $field_array['type'] = apply_filters( 'frm_field_type', $field->type, $field, $new_value );
56 - $field_array['parent_form_id'] = $args['parent_form_id'] ?? $field->form_id;
46 + $field_array['parent_form_id'] = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id;
57 47 $field_array['reset_value'] = $reset;
58 - $field_array['in_embed_form'] = $args['in_embed_form'] ?? '0';
48 + $field_array['in_embed_form'] = isset( $args['in_embed_form'] ) ? $args['in_embed_form'] : '0';
59 49 $field_array['original_default'] = $original_default;
60 50
61 51 FrmFieldsHelper::prepare_new_front_field( $field_array, $field, $args );
62 52
@@ -73,9 +63,8 @@
73 63 }
74 64 }//end foreach
75 65
76 66 FrmAppHelper::unserialize_or_decode( $form->options );
77 -
78 67 if ( is_array( $form->options ) ) {
79 68 $values = array_merge( $values, $form->options );
80 69 }
81 70
@@ -90,10 +79,8 @@
90 79 /**
91 80 * @since 2.05
92 81 *
93 82 * @param object $field
94 - *
95 - * @return void
96 83 */
97 84 private static function prepare_field_default_value( &$field ) {
98 85 // If checkbox, multi-select dropdown, or checkbox data from entries field, the value should be an array.
99 86 $return_array = FrmField::is_field_with_multiple_values( $field );
@@ -118,9 +105,9 @@
118 105 * @param object $field - this is passed by reference since it is an object.
119 106 * @param bool $reset
120 107 * @param array $args
121 108 *
122 - * @return array|string New value.
109 + * @return array|string $new_value
123 110 */
124 111 private static function get_field_value_for_new_entry( $field, $reset, $args ) {
125 112 $new_value = $field->default_value;
126 113
@@ -128,9 +115,9 @@
128 115 self::get_posted_value( $field, $new_value, $args );
129 116 }
130 117
131 118 if ( ! is_array( $new_value ) ) {
132 - return str_replace( '"', '"', $new_value );
119 + $new_value = str_replace( '"', '"', $new_value );
133 120 }
134 121
135 122 return $new_value;
136 123 }
@@ -142,36 +129,26 @@
142 129 *
143 130 * @param object $field
144 131 * @param array $args
145 132 *
146 - * @return bool True if a value is posted.
133 + * @return bool $value_is_posted
147 134 */
148 135 public static function value_is_posted( $field, $args ) {
149 136 $value_is_posted = false;
150 -
151 - if ( ! $_POST ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
152 - return $value_is_posted;
153 - }
154 -
155 - $repeating = ! empty( $args['repeating'] );
156 -
157 - if ( $repeating ) {
158 - if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
137 + if ( $_POST ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
138 + $repeating = isset( $args['repeating'] ) && $args['repeating'];
139 + if ( $repeating ) {
140 + if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
141 + $value_is_posted = true;
142 + }
143 + } elseif ( isset( $_POST['item_meta'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
159 144 $value_is_posted = true;
160 145 }
161 - } elseif ( isset( $_POST['item_meta'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
162 - $value_is_posted = true;
163 146 }
164 147
165 148 return $value_is_posted;
166 149 }
167 150
168 - /**
169 - * @param array $values
170 - * @param object $record
171 - *
172 - * @return array
173 - */
174 151 public static function setup_edit_vars( $values, $record ) {
175 152 remove_action( 'media_buttons', 'FrmFormsController::insert_form_button' );
176 153
177 154 $values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' );
@@ -180,22 +157,16 @@
180 157
181 158 return apply_filters( 'frm_setup_edit_entry_vars', $values, $record );
182 159 }
183 160
184 - /**
185 - * @param string $message
186 - * @param array $atts
187 - *
188 - * @return string
189 - */
190 161 public static function replace_default_message( $message, $atts ) {
191 - if ( ! str_contains( $message, '[default-message' ) &&
192 - ! str_contains( $message, '[default_message' ) &&
193 - $message ) {
162 + if ( strpos( $message, '[default-message' ) === false &&
163 + strpos( $message, '[default_message' ) === false &&
164 + ! empty( $message ) ) {
194 165 return $message;
195 166 }
196 167
197 - if ( ! $message ) {
168 + if ( empty( $message ) ) {
198 169 $message = '[default-message]';
199 170 }
200 171
201 172 preg_match_all( "/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER );
@@ -200,12 +171,17 @@
200 171
201 172 preg_match_all( "/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER );
202 173
203 174 foreach ( $shortcodes[0] as $short_key => $tag ) {
204 - $add_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] );
205 - $this_atts = $add_atts ? array_merge( $atts, $add_atts ) : $atts;
206 - $default = FrmEntriesController::show_entry_shortcode( $this_atts );
175 + $add_atts = FrmShortcodeHelper::get_shortcode_attribute_array( $shortcodes[2][ $short_key ] );
176 + if ( ! empty( $add_atts ) ) {
177 + $this_atts = array_merge( $atts, $add_atts );
178 + } else {
179 + $this_atts = $atts;
180 + }
207 181
182 + $default = FrmEntriesController::show_entry_shortcode( $this_atts );
183 +
208 184 // Add the default message.
209 185 $message = str_replace( $shortcodes[0][ $short_key ], $default, $message );
210 186 }
211 187
@@ -215,25 +191,22 @@
215 191 /**
216 192 * @param stdClass $entry
217 193 * @param stdClass $field
218 194 * @param array $atts
219 - *
220 195 * @return string
221 196 */
222 197 public static function prepare_display_value( $entry, $field, $atts ) {
223 - $field_value = $entry->metas[ $field->id ] ?? false;
198 + $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false;
224 199
225 200 if ( FrmAppHelper::pro_is_installed() ) {
226 - $empty = ! $field_value;
201 + $empty = empty( $field_value );
227 202 FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value );
228 -
229 - if ( $empty && $field_value ) {
203 + if ( $empty && ! empty( $field_value ) ) {
230 204 // We've got an entry id, so switch it to a value.
231 205 $atts['force_id'] = true;
232 206 }
233 207 }
234 208
235 - // phpcs:ignore Universal.Operators.StrictComparisons
236 209 if ( $field->form_id == $entry->form_id || empty( $atts['embedded_field_id'] ) ) {
237 210 return self::display_value( $field_value, $field, $atts );
238 211 }
239 212
@@ -239,20 +212,19 @@
239 212
240 213 if ( ! FrmAppHelper::pro_is_installed() ) {
241 214 return '';
242 215 }
243 -
244 216 if ( is_callable( 'FrmProEntriesHelper::prepare_child_display_value' ) ) {
245 217 return FrmProEntriesHelper::prepare_child_display_value( $entry, $field, $atts );
246 218 }
247 219
248 220 // This is an embedded form.
249 - if ( str_starts_with( $atts['embedded_field_id'], 'form' ) ) {
221 + if ( strpos( $atts['embedded_field_id'], 'form' ) === 0 ) {
250 222 // This is a repeating section.
251 223 $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ), '', '', true );
252 224 } else {
253 225 // Get all values for this field.
254 - $child_values = $entry->metas[ $atts['embedded_field_id'] ] ?? false;
226 + $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false;
255 227
256 228 if ( $child_values ) {
257 229 $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) );
258 230 }
@@ -257,14 +229,14 @@
257 229 $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) );
258 230 }
259 231 }
260 232
233 + $field_value = array();
234 +
261 235 if ( empty( $child_entries ) ) {
262 236 return '';
263 237 }
264 238
265 - $field_value = array();
266 -
267 239 foreach ( $child_entries as $child_entry ) {
268 240 $atts['item_id'] = $child_entry->id;
269 241 $atts['post_id'] = $child_entry->post_id;
270 242
@@ -271,9 +243,9 @@
271 243 // Fet the value for this field -- check for post values as well.
272 244 $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value( $child_entry, $field );
273 245
274 246 if ( $entry_val || '0' === $entry_val ) {
275 - // For each entry get display_value.
247 + // foreach entry get display_value.
276 248 $field_value[] = self::display_value( $entry_val, $field, $atts );
277 249 }
278 250
279 251 unset( $child_entry );
@@ -279,13 +251,11 @@
279 251 unset( $child_entry );
280 252 }
281 253
282 254 $sep = ', ';
283 -
284 - if ( str_contains( implode( ' ', $field_value ), '<img' ) ) {
255 + if ( strpos( implode( ' ', $field_value ), '<img' ) !== false ) {
285 256 $sep = '<br/>';
286 257 }
287 -
288 258 $val = implode( $sep, $field_value );
289 259
290 260 return FrmAppHelper::kses( $val, 'all' );
291 261 }
@@ -299,8 +269,9 @@
299 269 *
300 270 * @return string
301 271 */
302 272 public static function display_value( $value, $field, $atts = array() ) {
273 +
303 274 $defaults = array(
304 275 'type' => '',
305 276 'html' => false,
306 277 'show_filename' => true,
@@ -321,12 +292,8 @@
321 292 }
322 293
323 294 $atts = apply_filters( 'frm_display_value_atts', $atts, $field, $value );
324 295
325 - if ( is_string( $field->field_options ) ) {
326 - $field->field_options = array();
327 - }
328 -
329 296 if ( ! isset( $field->field_options['post_field'] ) ) {
330 297 $field->field_options['post_field'] = '';
331 298 }
332 299
@@ -336,15 +303,14 @@
336 303
337 304 if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] === 'tag' ) ) {
338 305 $atts['pre_truncate'] = $atts['truncate'];
339 306 $atts['truncate'] = true;
340 - $atts['exclude_cat'] = $field->field_options['exclude_cat'] ?? 0;
307 + $atts['exclude_cat'] = isset( $field->field_options['exclude_cat'] ) ? $field->field_options['exclude_cat'] : 0;
341 308
342 309 $value = FrmProEntryMetaHelper::get_post_value( $atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts );
343 310 $atts['truncate'] = $atts['pre_truncate'];
344 311 }
345 312
346 - // phpcs:ignore Universal.Operators.StrictComparisons
347 313 if ( $value == '' ) {
348 314 return $value;
349 315 }
350 316
@@ -353,9 +319,8 @@
353 319
354 320 $value = apply_filters( 'frm_display_value_custom', $unfiltered_value, $field, $atts );
355 321 $value = apply_filters( 'frm_display_' . $field->type . '_value_custom', $value, compact( 'field', 'atts' ) );
356 322
357 - // phpcs:ignore Universal.Operators.StrictComparisons
358 323 if ( $value == $unfiltered_value ) {
359 324 $value = FrmFieldsHelper::get_unfiltered_display_value( compact( 'value', 'field', 'atts' ) );
360 325 }
361 326
@@ -369,21 +334,13 @@
369 334
370 335 return apply_filters( 'frm_display_value', $value, $field, $atts );
371 336 }
372 337
373 - /**
374 - * @param object $field
375 - * @param mixed $value
376 - * @param array $args
377 - *
378 - * @return void
379 - */
380 338 public static function set_posted_value( $field, $value, $args ) {
381 339 // If validating a field with "other" opt, set back to prev value now.
382 340 if ( ! empty( $args['other'] ) ) {
383 341 $value = $args['temp_value'];
384 342 }
385 -
386 343 if ( empty( $args['parent_field_id'] ) ) {
387 344 $_POST['item_meta'][ $field->id ] = $value;
388 345 } else {
389 346 self::set_parent_field_posted_value( $field, $value, $args );
@@ -393,18 +350,12 @@
393 350 /**
394 351 * Init arrays if necessary, else we get fatal error.
395 352 *
396 353 * @since 4.01
397 - *
398 - * @param object $field Field object.
399 - * @param mixed $value Value to set.
400 - * @param array $args Additional arguments.
401 - *
402 - * @return void
403 354 */
404 355 private static function set_parent_field_posted_value( $field, $value, $args ) {
405 - if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ] ) && is_array( $_POST['item_meta'][ $args['parent_field_id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
406 - if ( ! isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] ) || ! is_array( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
356 + if ( isset( $_POST['item_meta'][ $args['parent_field_id'] ] ) && is_array( $_POST['item_meta'][ $args['parent_field_id'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
357 + if ( ! isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] ) || ! is_array( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
407 358 $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ] = array(); // phpcs:ignore WordPress.Security.NonceVerification.Missing
408 359 }
409 360 } else {
410 361 // All of the section was probably removed.
@@ -414,27 +365,15 @@
414 365
415 366 $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; // phpcs:ignore WordPress.Security.NonceVerification.Missing
416 367 }
417 368
418 - /**
419 - * @param array|int|object|string $field
420 - * @param mixed $value
421 - * @param array $args
422 - *
423 - * @return void
424 - */
425 369 public static function get_posted_value( $field, &$value, $args ) {
426 370 if ( is_array( $field ) ) {
427 371 $field_id = $field['id'];
428 372 $field_obj = FrmFieldFactory::get_field_object( $field['id'] );
429 373 } elseif ( is_object( $field ) ) {
430 - $field_id = $field->id;
431 -
432 - if ( 'hidden' === $field->type && ! empty( $field->field_options['original_type'] ) ) {
433 - $field_obj = FrmFieldFactory::get_field_type( $field->field_options['original_type'], $field );
434 - } else {
435 - $field_obj = FrmFieldFactory::get_field_object( $field );
436 - }
374 + $field_id = $field->id;
375 + $field_obj = FrmFieldFactory::get_field_object( $field );
437 376 } elseif ( is_numeric( $field ) ) {
438 377 $field_id = $field;
439 378 $field_obj = FrmFieldFactory::get_field_object( $field );
440 379 } else {
@@ -449,21 +388,15 @@
449 388 }
450 389
451 390 /**
452 391 * @since 4.02.04
453 - * @since 6.29 This is public.
454 - *
455 - * @param int|string $field_id Field ID.
456 - * @param array $args Additional arguments.
457 - *
458 - * @return mixed
459 392 */
460 - public static function get_posted_meta( $field_id, $args ) {
393 + private static function get_posted_meta( $field_id, $args ) {
461 394 if ( empty( $args['parent_field_id'] ) ) {
462 395 // Sanitizing is done next.
463 - $value = isset( $_POST['item_meta'][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $field_id ] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
396 + $value = isset( $_POST['item_meta'][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $field_id ] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
464 397 } else {
465 - $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
398 + $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? wp_unslash( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
466 399 }
467 400 return $value;
468 401 }
469 402
@@ -471,17 +404,14 @@
471 404 * Check if field has an "Other" option and if any other values are posted
472 405 *
473 406 * @since 2.0
474 407 *
475 - * @param object $field Field object.
476 - * @param array|string $value Field value, passed by reference.
477 - * @param array $args Arguments array, passed by reference.
478 - *
479 - * @return void
408 + * @param object $field
409 + * @param array|string $value
410 + * @param array $args
480 411 */
481 412 public static function maybe_set_other_validation( $field, &$value, &$args ) {
482 413 $args['other'] = false;
483 -
484 414 if ( ! $value || ! FrmAppHelper::pro_is_installed() ) {
485 415 return;
486 416 }
487 417
@@ -495,22 +425,21 @@
495 425 // Get other value for fields in repeating section.
496 426 self::set_other_repeating_vals( $field, $value, $args );
497 427
498 428 // Check if there are any posted "Other" values.
499 - if ( ! FrmField::is_option_true( $field, 'other' ) || ! isset( $_POST['item_meta']['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
500 - return;
501 - }
429 + if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
502 430
503 - // Save original value.
504 - $args['temp_value'] = $value;
505 - $args['other'] = true;
431 + // Save original value.
432 + $args['temp_value'] = $value;
433 + $args['other'] = true;
506 434
507 - // Sanitizing is done next.
508 - $other_vals = wp_unslash( $_POST['item_meta']['other'][ $field->id ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
509 - FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
435 + // Sanitizing is done next.
436 + $other_vals = wp_unslash( $_POST['item_meta']['other'][ $field->id ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
437 + FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
510 438
511 - // Set the validation value now
512 - self::set_other_validation_val( $value, $other_vals, $field, $args );
439 + // Set the validation value now
440 + self::set_other_validation_val( $value, $other_vals, $field, $args );
441 + }
513 442 }
514 443
515 444 /**
516 445 * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
@@ -516,13 +445,11 @@
516 445 * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS
517 446 *
518 447 * @since 2.0
519 448 *
520 - * @param object $field Field object.
521 - * @param array|string $value Field value, passed by reference.
522 - * @param array $args Arguments array, passed by reference.
523 - *
524 - * @return void
449 + * @param object $field
450 + * @param array|string $value
451 + * @param array $args
525 452 */
526 453 public static function set_other_repeating_vals( $field, &$value, &$args ) {
527 454 if ( ! $args['parent_field_id'] ) {
528 455 return;
@@ -528,20 +455,19 @@
528 455 return;
529 456 }
530 457
531 458 // Check if there are any other posted "other" values for this field.
532 - if ( ! FrmField::is_option_true( $field, 'other' ) || ! isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
533 - return;
534 - }
459 + if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
460 + // Save original value
461 + $args['temp_value'] = $value;
462 + $args['other'] = true;
535 463
536 - // Save original value
537 - $args['temp_value'] = $value;
538 - $args['other'] = true;
539 - $other_vals = wp_unslash( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing, SlevomatCodingStandard.Files.LineLength.LineTooLong
540 - FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
464 + $other_vals = wp_unslash( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Missing
465 + FrmAppHelper::sanitize_value( 'sanitize_text_field', $other_vals );
541 466
542 - // Set the validation value now.
543 - self::set_other_validation_val( $value, $other_vals, $field, $args );
467 + // Set the validation value now.
468 + self::set_other_validation_val( $value, $other_vals, $field, $args );
469 + }
544 470 }
545 471
546 472 /**
547 473 * Modify value used for validation
@@ -555,13 +481,11 @@
555 481 * @param array|string $value
556 482 * @param array|string $other_vals (usually of posted values).
557 483 * @param object $field
558 484 * @param array $args
559 - *
560 - * @return void
561 485 */
562 486 public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) {
563 - // Checkboxes.
487 + // Checkboxes and multi-select dropdowns.
564 488 if ( is_array( $value ) && $field->type === 'checkbox' ) {
565 489 // Combine "Other" values with checked values. "Other" values will override checked box values.
566 490 foreach ( $other_vals as $k => $v ) {
567 491 if ( isset( $value[ $k ] ) && trim( $v ) === '' ) {
@@ -570,43 +494,39 @@
570 494 break;
571 495 }
572 496 }
573 497
574 - if ( is_array( $value ) && $value ) {
498 + if ( is_array( $value ) && ! empty( $value ) ) {
575 499 $value = array_merge( $value, $other_vals );
576 500 }
501 + } else {
502 + // Radio and dropdowns.
503 + $other_key = array_filter( array_keys( $field->options ), 'is_string' );
504 + $other_key = reset( $other_key );
577 505
578 - return;
579 - }
506 + // Multi-select dropdown.
507 + if ( is_array( $value ) ) {
508 + $o_key = array_search( $field->options[ $other_key ], $value );
580 509
581 - // Radio and dropdowns.
582 - $other_key = array_filter( array_keys( $field->options ), 'is_string' );
583 - $other_key = reset( $other_key );
510 + if ( $o_key !== false ) {
511 + // Modify the original value so other key will be preserved.
512 + $value[ $other_key ] = $value[ $o_key ];
584 513
585 - // Multi-select dropdown.
586 - if ( is_array( $value ) ) {
587 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
588 - $o_key = array_search( $field->options[ $other_key ], $value );
514 + // By default, the array keys will be numeric for multi-select dropdowns.
515 + // If going backwards and forwards between pages, the array key will match the other key.
516 + if ( $o_key !== $other_key ) {
517 + unset( $value[ $o_key ] );
518 + }
589 519
590 - if ( $o_key !== false ) {
591 - // Modify the original value so other key will be preserved.
592 - $value[ $other_key ] = $value[ $o_key ];
593 -
594 - // By default, the array keys will be numeric for multi-select dropdowns.
595 - // If going backwards and forwards between pages, the array key will match the other key.
596 - if ( $o_key !== $other_key ) {
597 - unset( $value[ $o_key ] );
520 + $args['temp_value'] = $value;
521 + $value[ $other_key ] = reset( $other_vals );
522 + if ( FrmAppHelper::is_empty_value( $value[ $other_key ] ) ) {
523 + unset( $value[ $other_key ] );
524 + }
598 525 }
599 -
600 - $args['temp_value'] = $value;
601 - $value[ $other_key ] = reset( $other_vals );
602 -
603 - if ( FrmAppHelper::is_empty_value( $value[ $other_key ] ) ) {
604 - unset( $value[ $other_key ] );
605 - }
606 - }
607 - } elseif ( $field->options[ $other_key ] == $value ) { // phpcs:ignore Universal.Operators.StrictComparisons
608 - $value = $other_vals;
526 + } elseif ( $field->options[ $other_key ] == $value ) {
527 + $value = $other_vals;
528 + }//end if
609 529 }//end if
610 530 }
611 531
612 532 /**
@@ -612,16 +532,14 @@
612 532 /**
613 533 * Add submitted values to a string for spam checking.
614 534 *
615 535 * @param array $values
616 - *
617 536 * @return string
618 537 */
619 538 public static function entry_array_to_string( $values ) {
620 539 $content = '';
621 -
622 540 foreach ( $values['item_meta'] as $val ) {
623 - if ( $content !== '' ) {
541 + if ( $content != '' ) {
624 542 $content .= "\n\n";
625 543 }
626 544
627 545 if ( is_array( $val ) ) {
@@ -668,14 +586,14 @@
668 586 'Firefox' => 'Mozilla Firefox',
669 587 );
670 588
671 589 // Next get the name of the useragent yes separately and for good reason.
672 - if ( str_contains( $u_agent, 'MSIE' ) && ! str_contains( $u_agent, 'Opera' ) ) {
590 + if ( strpos( $u_agent, 'MSIE' ) !== false && strpos( $u_agent, 'Opera' ) === false ) {
673 591 $bname = 'Internet Explorer';
674 592 $ub = 'MSIE';
675 593 } else {
676 594 foreach ( $agent_options as $agent_key => $agent_name ) {
677 - if ( str_contains( $u_agent, $agent_key ) ) {
595 + if ( strpos( $u_agent, $agent_key ) !== false ) {
678 596 $bname = $agent_name;
679 597 $ub = $agent_key;
680 598 break;
681 599 }
@@ -681,21 +599,25 @@
681 599 }
682 600 }
683 601 }
684 602
685 - // Finally get the correct version number
603 + // finally get the correct version number
686 604 $known = array( 'Version', $ub, 'other' );
687 - $pattern = '#(?<browser>' . implode( '|', $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
605 + $pattern = '#(?<browser>' . join( '|', $known ) . ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
688 606 // Get the matching numbers.
689 607 preg_match_all( $pattern, $u_agent, $matches );
690 608
691 - // See how many we have
609 + // see how many we have
692 610 $i = count( $matches['browser'] );
693 611
694 612 if ( $i > 1 ) {
695 613 // We will have two since we are not using 'other' argument yet
696 - // See if version is before or after the name.
697 - $version = strripos( $u_agent, 'Version' ) < strripos( $u_agent, $ub ) ? $matches['version'][0] : $matches['version'][1];
614 + // see if version is before or after the name.
615 + if ( strripos( $u_agent, 'Version' ) < strripos( $u_agent, $ub ) ) {
616 + $version = $matches['version'][0];
617 + } else {
618 + $version = $matches['version'][1];
619 + }
698 620 } elseif ( $i === 1 ) {
699 621 $version = $matches['version'][0];
700 622 } else {
701 623 $version = '';
@@ -700,10 +622,10 @@
700 622 } else {
701 623 $version = '';
702 624 }
703 625
704 - // Check if we have a number
705 - if ( $version === '' ) {
626 + // check if we have a number
627 + if ( $version == '' ) {
706 628 $version = '?';
707 629 }
708 630
709 631 return $bname . ' ' . $version . ' / ' . $platform;
@@ -710,19 +632,14 @@
710 632 }
711 633
712 634 /**
713 635 * @since 3.0
714 - *
715 - * @param array $atts Action dropdown attributes.
716 - *
717 - * @return void
718 636 */
719 637 public static function actions_dropdown( $atts ) {
720 - $id = $atts['id'] ?? FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
638 + $id = isset( $atts['id'] ) ? $atts['id'] : FrmAppHelper::get_param( 'id', 0, 'get', 'absint' );
721 639 $links = self::get_action_links( $id, $atts['entry'] );
722 640
723 641 foreach ( $links as $link ) {
724 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
725 642 ?>
726 643 <div class="misc-pub-section">
727 644 <a href="<?php echo esc_url( $link['url'] ); ?>"
728 645 <?php
@@ -730,13 +647,11 @@
730 647 foreach ( $link['data'] as $data => $value ) {
731 648 echo 'data-' . esc_attr( $data ) . '="' . esc_attr( $value ) . '" ';
732 649 }
733 650 }
734 -
735 651 if ( isset( $link['class'] ) ) {
736 652 echo 'class="' . esc_attr( $link['class'] ) . '" ';
737 653 }
738 -
739 654 if ( isset( $link['id'] ) ) {
740 655 echo 'id="' . esc_attr( $link['id'] ) . '" ';
741 656 }
742 657 ?>
@@ -745,19 +660,13 @@
745 660 <span class="frm_link_label"><?php echo esc_html( $link['label'] ); ?></span>
746 661 </a>
747 662 </div>
748 663 <?php
749 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
750 664 }//end foreach
751 665 }
752 666
753 667 /**
754 668 * @since 3.0
755 - *
756 - * @param int $id Entry ID.
757 - * @param array|object $entry Entry object.
758 - *
759 - * @return array
760 669 */
761 670 private static function get_action_links( $id, $entry ) {
762 671 $page = FrmAppHelper::get_param( 'frm_action' );
763 672 $actions = array();
@@ -765,9 +674,9 @@
765 674 if ( $page !== 'show' ) {
766 675 $actions['frm_view'] = array(
767 676 'url' => admin_url( 'admin.php?page=formidable-entries&frm_action=show&id=' . $id . '&form=' . $entry->form_id ),
768 677 'label' => __( 'View Entry', 'formidable' ),
769 - 'icon' => 'frmfont frm_save_icon',
678 + 'icon' => 'frm_icon_font frm_save_icon',
770 679 );
771 680 }
772 681
773 682 if ( current_user_can( 'frm_delete_entries' ) ) {
@@ -773,12 +682,11 @@
773 682 if ( current_user_can( 'frm_delete_entries' ) ) {
774 683 $actions['frm_delete'] = array(
775 684 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable-entries&frm_action=destroy&id=' . $id . '&form=' . $entry->form_id ) ),
776 685 'label' => __( 'Delete Entry', 'formidable' ),
777 - 'icon' => 'frmfont frm_delete_icon',
686 + 'icon' => 'frm_icon_font frm_delete_icon',
778 687 'data' => array(
779 - 'frmverify' => __( 'Permanently delete this entry?', 'formidable' ),
780 - 'frmverify-btn' => 'frm-button-red',
688 + 'frmverify' => __( 'Delete this form entry?', 'formidable' ),
781 689 ),
782 690 );
783 691 }
784 692
@@ -788,9 +696,9 @@
788 696 'label' => __( 'Print Entry', 'formidable' ),
789 697 'data' => array(
790 698 'frmprint' => '1',
791 699 ),
792 - 'icon' => 'frmfont frm_printer_icon',
700 + 'icon' => 'frm_icon_font frm_printer_icon',
793 701 );
794 702 }
795 703
796 704 $actions['frm_resend'] = array(
@@ -801,18 +709,18 @@
801 709 'upgrade' => __( 'Resend Emails', 'formidable' ),
802 710 'medium' => 'resend-email',
803 711 'content' => 'entry',
804 712 ),
805 - 'icon' => 'frmfont frm_email_icon',
713 + 'icon' => 'frm_icon_font frm_email_icon',
806 714 );
807 715
808 - if ( ! function_exists( 'frm_pdfs_autoloader' ) ) {
716 + if ( ! function_exists( 'frm_pdfs_autoloader' ) && FrmAppHelper::show_new_feature( 'pdfs' ) ) {
809 717 $actions['frm_download_pdf'] = array(
810 718 'url' => '#',
811 719 'label' => __( 'Download as PDF', 'formidable' ),
812 720 'class' => 'frm_noallow',
813 721 'data' => self::get_pdfs_upgrade_link_data( 'download-pdf-entry' ),
814 - 'icon' => 'frmfont frm_download_icon',
722 + 'icon' => 'frm_icon_font frm_download_icon',
815 723 );
816 724 }
817 725
818 726 $actions['frm_edit'] = array(
@@ -823,9 +731,9 @@
823 731 'upgrade' => __( 'Entry edits', 'formidable' ),
824 732 'medium' => 'edit-entries',
825 733 'content' => 'entry',
826 734 ),
827 - 'icon' => 'frmfont frm_pencil_icon',
735 + 'icon' => 'frm_icon_font frm_pencil_icon',
828 736 );
829 737
830 738 return apply_filters( 'frm_entry_actions_dropdown', $actions, compact( 'id', 'entry' ) );
831 739 }
@@ -833,9 +741,8 @@
833 741 /**
834 742 * Gets data attributes for PDFs addon upgrade link.
835 743 *
836 744 * @param string $medium The source of the upgrade link used for analytics data.
837 - *
838 745 * @return array
839 746 */
840 747 private static function get_pdfs_upgrade_link_data( $medium = 'pdfs' ) {
841 748 $data = array(
@@ -845,9 +752,8 @@
845 752 'medium' => $medium,
846 753 );
847 754
848 755 $upgrading = FrmAddonsController::install_link( 'pdfs' );
849 -
850 756 if ( isset( $upgrading['url'] ) ) {
851 757 $data['oneclick'] = json_encode( $upgrading );
852 758 } else {
853 759 $data['requires'] = FrmAddonsController::get_addon_required_plan( 28136428 );
@@ -859,9 +765,8 @@
859 765 /**
860 766 * @since 5.0.15
861 767 *
862 768 * @param int|string $entry_id
863 - *
864 769 * @return void
865 770 */
866 771 public static function maybe_render_captcha_score( $entry_id ) {
867 772 $query = array(
@@ -868,20 +773,17 @@
868 773 'item_id' => (int) $entry_id,
869 774 'field_id' => 0,
870 775 );
871 776 $metas_without_a_field = (array) FrmEntryMeta::getAll( $query, ' ORDER BY it.created_at DESC', '', true );
872 -
873 777 foreach ( $metas_without_a_field as $meta ) {
874 - if ( empty( $meta->meta_value['captcha_score'] ) ) {
875 - continue;
778 + if ( ! empty( $meta->meta_value['captcha_score'] ) ) {
779 + echo '<div class="misc-pub-section">';
780 + FrmAppHelper::icon_by_class( 'frm_icon_font frm_shield_check_icon', array( 'aria-hidden' => 'true' ) );
781 + echo ' ' . esc_html__( 'reCAPTCHA Score', 'formidable' ) . ': ';
782 + echo '<b>' . esc_html( $meta->meta_value['captcha_score'] ) . '</b>';
783 + echo '</div>';
784 + return;
876 785 }
877 -
878 - echo '<div class="misc-pub-section">';
879 - FrmAppHelper::icon_by_class( 'frmfont frm_shield_check_icon', array( 'aria-hidden' => 'true' ) );
880 - echo ' ' . esc_html__( 'reCAPTCHA Score', 'formidable' ) . ': ';
881 - echo '<b>' . esc_html( $meta->meta_value['captcha_score'] ) . '</b>';
882 - echo '</div>';
883 - return;
884 786 }
885 787 }
886 788
887 789 /**
@@ -893,13 +795,15 @@
893 795 *
894 796 * @return int
895 797 */
896 798 public static function get_entry_status( $status ) {
897 - if ( array_key_exists( $status, self::get_entry_statuses() ) ) {
799 + $statuses = self::get_entry_statuses();
800 +
801 + if ( array_key_exists( $status, $statuses ) ) {
898 802 return $status;
899 803 }
900 804
901 - if ( ! $status ) {
805 + if ( empty( $status ) ) {
902 806 // If the status is empty, let's default to 0.
903 807 return self::SUBMITTED_ENTRY_STATUS;
904 808 }
905 809
@@ -916,9 +820,11 @@
916 820 *
917 821 * @return string
918 822 */
919 823 public static function get_entry_status_label( $status ) {
920 - return self::get_entry_statuses()[ self::get_entry_status( $status ) ];
824 + $statuses = self::get_entry_statuses();
825 +
826 + return $statuses[ self::get_entry_status( $status ) ];
921 827 }
922 828
923 829 /**
924 830 * Get all entry statuses.
@@ -928,8 +834,9 @@
928 834 *
929 835 * @return array<string>
930 836 */
931 837 public static function get_entry_statuses() {
838 +
932 839 $default_entry_statuses = array(
933 840 self::SUBMITTED_ENTRY_STATUS => __( 'Submitted', 'formidable' ),
934 841 self::DRAFT_ENTRY_STATUS => __( 'Draft', 'formidable' ),
935 842 );
@@ -950,35 +857,9 @@
950 857 _doing_it_wrong( __METHOD__, esc_html__( 'Entry status must be return in array format.', 'formidable' ), '6.5' );
951 858 $extended_entry_status = array();
952 859 }
953 860
954 - return array_replace( $default_entry_statuses, $extended_entry_status );
955 - }
861 + $existing_entry_statuses = array_replace( $default_entry_statuses, $extended_entry_status );
956 862
957 - /**
958 - * @since 6.17
959 - *
960 - * @return int
961 - */
962 - public static function get_visible_unread_inbox_count() {
963 - if ( ! in_array( FrmAppHelper::get_menu_name(), array( 'Formidable', 'Forms' ), true ) ) {
964 - return 0;
965 - }
966 -
967 - $inbox = new FrmInbox();
968 - $inbox_count = count( $inbox->unread() );
969 -
970 - if ( ! $inbox_count ) {
971 - return 0;
972 - }
973 -
974 - if ( is_callable( 'FrmProSettingsController::inbox_badge' ) ) {
975 - $inbox_count = FrmProSettingsController::inbox_badge( $inbox_count );
976 -
977 - if ( ! $inbox_count ) {
978 - return 0;
979 - }
980 - }
981 -
982 - return $inbox_count;
863 + return $existing_entry_statuses;
983 864 }
984 865 }