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