First:
This forum is used by volunteers to help other wordpress users. I am not a “staffmember” of anything but volunteer here and answer your as well as other questions in my spare time – free of charge. You can read more about it here: https://www.ads-software.com/support/guidelines/
If you are looking for professional support, you can find it here: https://jobs.wordpress.net
And now to your request:
The page describing wp user doesn’t quite contain what you need, of course. Your requirement is very individual, so there is nothing ready-made for it. But thanks to the many possibilities that many thousands of volunteers put into the development of wordpress, what you want is still doable. You need to manually add a function here that can be executed via WP CLI.
What you need for this is documented (also by volunteers) in the WordPress manual. E.g. here is a function with which you can add your own command to the CLI:
https://make.www.ads-software.com/cli/handbook/references/internal-api/wp-cli-add-command/
Relevant for the determination of the users is a WP_User_Query, whose options are described here: https://developer.www.ads-software.com/reference/classes/wp_user_query/
Here is a small example I just wrote, but I couldn’t test it because I don’t have a database with thousands of users:
function custom_cli() {
WP_CLI::add_command('custom_cli', 'custom_user_delete');
}
add_action( 'cli_init', 'custom_cli' );
function custom_user_delete() {
$users = get_users([
'role' => 'editor', // select only users with the editor-role
'date_query' => array( // select only users which has been registered during the last 12 months
array( 'after' => '12 months ago', 'inclusive' => true )
)
]);
foreach( $users as $user ) {
wp_delete_user($user->ID);
}
}
You would have to add that to your theme’s functions.php, your custom plugin or via code snippet plugin. After that you should call the console with
wp custom_cli
to call the deletion process. But be careful: You have to adjust the commented part with the condition.
And always remember to make a backup.