Skip to content

Commit baac6f0

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 3788b95 commit baac6f0

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/User_Command.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,31 @@ public function get( $args, $assoc_args ) {
282282
* $ wp user delete $(wp user list --role=contributor --field=ID | head -n 100)
283283
*/
284284
public function delete( $args, $assoc_args ) {
285-
$args = self::expand_id_ranges( $args, [ $this, 'get_user_ids_in_range' ] );
285+
// Only expand arguments that look like numeric ID ranges, and only if no user
286+
// exists with that exact login or email. This avoids misinterpreting a valid
287+
// user_login like "12-24" as an ID range.
288+
$expanded_args = [];
289+
290+
foreach ( $args as $arg ) {
291+
if ( is_string( $arg ) && preg_match( '/^\d+-\d+$/', $arg ) ) {
292+
$user_by_login = get_user_by( 'login', $arg );
293+
$user_by_email = get_user_by( 'email', $arg );
294+
295+
if ( $user_by_login || $user_by_email ) {
296+
// Treat as login/email, do not expand as an ID range.
297+
$expanded_args[] = $arg;
298+
} else {
299+
$range_expanded = self::expand_id_ranges( [ $arg ], [ $this, 'get_user_ids_in_range' ] );
300+
foreach ( $range_expanded as $expanded_arg ) {
301+
$expanded_args[] = $expanded_arg;
302+
}
303+
}
304+
} else {
305+
$expanded_args[] = $arg;
306+
}
307+
}
308+
309+
$args = $expanded_args;
286310
$network = Utils\get_flag_value( $assoc_args, 'network' ) && is_multisite();
287311

288312
/**

0 commit comments

Comments
 (0)