If you have some kind of error or warning in the users import results, it won’t delete any user (as a precaution measure).
Hello Javier, nice it’s working perfectly, thank you very much for the quick response !!!
Is there a way to protect users with another role, if I create a new role called “do_not_delete” and I add this role as Other Role, can I protect those users?
Thank you for your help
Sorry I do not understand really well your question.
I’m using the “Delete users not in CSV file” option during imports.
In my use case, I need to protect certain users from deletion, even if they are not present in the CSV file.
Is there a built-in method (or a filter) to exclude specific users, besides admins (for example, users with a specific role or a custom meta flag), from being deleted when this option is enabled?
I hope my question is clearer?
Thank you for your support!
Currently, there is no way to do this, but if it’s enough for you, I can prepare a hook here:
$args = array(
‘fields’ => array( ‘ID’ ),
‘role__not_in’ => $exclude_roles,
‘exclude’ => array( get_current_user_id() ), // current user never cannot be deleted
);
Would that work for you? In the exclude, you could add user_ids to exclude.
Yes, that would be perfect. Please go ahead and add the hook as you suggested — being able to use role__not_in and exclude to protect users from deletion would fully cover my needs.
This is very much appreciated, thank you for your support!
Hook added:
$args = array(
'fields' => array( 'ID' ),
'role__not_in' => $exclude_roles,
'exclude' => apply_filters( 'acui_exclude_users_to_delete', array( get_current_user_id() ) ), // current user never cannot be deleted
);
It will be available in minutes.