Skip to content

Commit 3d874d1

Browse files
authored
gpnf-sortable-entries.php: Fixed an issue where duplicated entries appeared in sortable child entries.
1 parent c75fe1d commit 3d874d1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

gp-nested-forms/gpnf-sortable-entries.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,16 @@ public function add_init_script_args( $args, $field, $form ) {
112112
// Sort $args['entries'] which contains Gravity Forms entries arrays. They contain an 'id' key.
113113
// $cookie_entries contains the entry IDs in the order they should be displayed.
114114
$sorted_entries = array();
115+
$valid_entry_ids = array();
115116

116117
foreach ( $cookie_entries as $entry_id ) {
118+
$entry_id_str = (string) $entry_id;
119+
117120
foreach ( $args['entries'] as $entry ) {
118-
if ( $entry['id'] == $entry_id ) {
121+
// Use strict comparison and prevent duplicates
122+
if ( (string) $entry['id'] === $entry_id_str && ! in_array( $entry_id_str, $valid_entry_ids, true ) ) {
119123
$sorted_entries[] = $entry;
124+
$valid_entry_ids[] = $entry_id_str;
120125
break;
121126
}
122127
}

0 commit comments

Comments
 (0)