Skip to content

Commit 67bc91b

Browse files
swissspidyCopilot
andauthored
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent dc9a903 commit 67bc91b

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/Menu_Item_Command.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,13 @@ private function add_or_update_item( $method, $type, $args, $assoc_args ) {
659659
]
660660
);
661661

662+
// Clamp the requested position to the valid range of menu items.
663+
$max_position = count( $sorted_items );
664+
if ( $max_position > 0 && $new_position > $max_position ) {
665+
// Treat out-of-range positions as "move to end", consistent with core behavior.
666+
$new_position = $max_position;
667+
}
668+
662669
// Find the 1-indexed normalized rank of the item being moved.
663670
$old_position_normalized = 0;
664671
foreach ( $sorted_items as $idx => $sorted_item ) {

0 commit comments

Comments
 (0)