Delete user from multisite when removed from subsite
I am using the multisite setup of wordpress. My subsites are managed my administrators of other organisations.
Problem:
When a user is deleted on a subsite by the administrator, its records still exist in the network user table. In turn when this user returns to the subsite where he/she was registered, he/she can still login. I guess because its records are still in the user database. So basically a deletion from a subsite has no use.
Possible solution:
When user is deleted from a subsite it is also deleted from the entire network.
I looked at the codex but I cannot get it to work. The wpmu_delete_user function should be the one to go i guess. But the trick seems to be when to fire it. I thought of adding it to remove_user_from_blog but it is just not working.
This is the code atm, hope you can help!
add_action( 'remove_user_from_blog', 'remove_user_from_network', 10,2 );
function remove_user_from_network( $user_id ) {
global $wpdb;
$user_id = (int) $user_id;
wpmu_delete_user( $user_id );
}
Leave an answer