You could also do this,
function mod_redirect_subscriber_delete($user_id) {
$user = get_user_by('id', $user_id);
$role = $user->roles[0];
if ($role == 'subscriber') {
add_action("deleted_user", function(){
wp_redirect( admin_url('/index.php') );
exit;
});
}
}
add_action("delete_user", "mod_redirect_subscriber_delete");
Anonymous functions (closures), available in PHP 5.3+.
Benefits:
- No need to remove the initial hook on
delete_user - No need to re-run
wp_delete_user() - You still get to hook onto
deleted_userbecause we retain the user’s role within the function, hence we place our closure in theif(conditional)statement.
Related Posts:
- How to target specific user role?
- Is it possible to incorporate username in a login redirect?
- Page template that redirects user based on role
- Redirecting Pages That No Longer Exist — But Could in the Future
- About to migrate site to new domain
- Redirect each user to specific pages based on their role
- Redirect Page ID, based on logged-in User Role
- Unable to access WP test site
- Conditional redirect on login using referring URL
- redirects for removed/deleted woocommerce products
- woocommerce shop page Redirect Help
- How do make WordPress to let alone my static home page?
- Redirecting by role from a button
- How to force a 404 on WordPress
- How do I skip wordpress’s 404 handling and redirect all 404 errors for static files to 404.html?
- Disable WordPress URL auto complete
- Disable ONLY URL auto complete, not the whole canonical URL system
- 301 redirect instead of 404 when URL is a prefix of a post or page name?
- Redirect to referring page after logging in
- Correct way to hide pseudo pages from being shown?
- How to create a php url redirection for nicer links
- WP redirects all pages from new domain to old domain
- wp_logout_url() redirects to confirmation page even with nonce?
- Creating intro page in wordpress
- How to redirect action=register link on the lostpassword page to a different link?
- You do not have sufficient permissions to access this page
- All pages showing up as homepage on WordPress website
- Redirect blogpage /blog/abcd/ to /blog/
- template_redirect causing infinite loop when get_queried_object is called
- File available but giving 404 in wordpress
- Does WP always makes 301 redirection?
- WordPress Redirecting HTTPS Requests to HTTP
- How can I redirect my website’s homepage to a random blog post?
- wp_redirect does not work
- Use virtual pages point to one specific page
- How to migrate production WordPress to Localhost
- How to redirect a page into file?
- Blog index not going to wordpress folder
- Check Page requested, and redirect
- WordPress on a local machine redirecting to xampp dashboard page [closed]
- reducing number of URL Redirects and increasing speed
- This redirect loop is eating my lunch! [closed]
- What is this code in my theme’s footer.php causing chmod permission warnings? [closed]
- How to use https on one page only?
- WooCommerce – Redirect to a product after login
- Redirect page to default subpage
- 301 redirect from old URL structur to new
- How to fix too many redirects when enabling SSL for site?
- Custom redirect user after login based on metadata
- Add Username to URL for redirect
- Log out and redirect to different URL
- How to get better performance for redirect from domain.tld/35 to domain.tld/full-permalink?
- Redirect deleted page URL ?p=xxxx
- Have WordPress post redirect to url when accesed from iPad (Safari)
- I want to resolve Redirect Chain [closed]
- How to fix URL with pageid example /?p= too many redirection error
- Conditional redirect to several pages
- Dynamic redirect
- Redirect to home if page doesn’t exists [duplicate]
- Redirect all links form a category to new links on new category
- My redirect URL doesn’t show any pages on my website [closed]
- Forced Redirect on a server migration
- Site Address and WordPress Address settings when using a load balancer
- Prevent “/login” to redirect to “/wp-login”
- Redirect certain pages if user logged in
- Login redirect shows white page in firefox
- Redirect to post_id?
- WP insert post Redirect after function has executed
- Date based redirects of posts that no longer exist
- How can I disable redirect domains?
- redirect wordpress post to new subfolder site on same domain
- Use a 301 to Redirect any 404 from at the blog post level to the blog archive
- Re-Direct ALL Users to the Home Page IF not logged in
- Random redirect to wp-admin/install.php
- How to redirect returning users who previously logged in?
- wordpress redirect error in xampp
- Swapping current old site to new WordPress site – need to check I’m doing it right
- how redirect users to custom login page when user comment must “login to reply” is clicked?
- Redirect User to Specific Page
- Allow GET request on certain page
- .htaccess redirect for old subfolder installation to new subfolder installation and https
- PHP Mistake – Whats wrong here?
- On login redirect to different homepage if user is using a mobile
- Redirecting Issue
- Redirect user to login and then to page where they came from
- htaccess and redirect to new url using regex
- Disallow “contributors” to edit their own posts once they’ve been set to “Pending Review”
- redirect attachment page to category page
- Google PageSpeed: Avoid landing page redirects?
- How to make my homepage automatically redirect to an external website?
- 404 Not Found with All Cloaking plugins
- Stopping media file redirects
- 301 redirect just for 404 to another domain
- Forcing header cache control in 404 pages
- Regex for pdf’s – Old .asp Site folder structure to new WordPress Media Folder(s)
- Redirect if a user has not written a post
- Create a custom redirect link that tracks the first visited page and after submitting form goes to first page using formidable forms plugin? [closed]
- WordPress not use site url when redirect 301
- My pagination creates a redirect
- Want to be able to redirect readers to another wordpress site but still be able to access the back end of current site