(a)delete_user
钩子:这里有一个想法:
将此添加到代码中以删除用户:
remove_action("delete_user", "mod_redirect_subscriber_delete");
wp_delete_user($user_id);
我们移除动作回调以防止它再次调用自己。
因此,您的代码变成:
function mod_redirect_subscriber_delete($user_id) {
$user = get_user_by(\'id\', $user_id);
$role = $user->roles[0];
if ($role == \'subscriber\') {
// start extra:
remove_action("delete_user", "mod_redirect_subscriber_delete");
wp_delete_user($user_id);
// end extra
wp_redirect( admin_url(\'/index.php\') );
exit;
}
}
add_action("delete_user", "mod_redirect_subscriber_delete");
b)deleted_user
挂钩:
deleted_user
钩子在用户被删除后被激活,但在用户被删除前不会被激活
delete_user
案例
这意味着您无法检查用户的角色,因为它已被删除。
您可以这样使用它,但对于所有用户:
function mod_redirect_subscriber_deleted($user_id) {
wp_redirect( admin_url(\'/index.php\') );
exit();
}
add_action("deleted_user", "mod_redirect_subscriber_deleted");