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_user
because 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 redirect non-logged in users to a specific page?
- When I change slug, will WordPress create redirect from the old URL?
- Why am I getting a 301 on a existing post?
- Keeps on redirecting on my development copy
- Password change when the user login first time
- Custom login form redirect to external site
- Clarification on auth_redirect()
- Prevent from deleting any user role but subscriber
- Redirecting old permalink to new one
- WP auto redirects after url change?
- Setting a redirect cookie in wordpress
- Redirect users after first login
- $_SESSION variables lost during OAuth callback
- 404 redirection and Google’s index [closed]
- Redirect user after logout
- WWW to non WWW redirect effects on load speed
- 302 redirect to signup with nginx reverse proxy
- How to redirect user to specific page based on the input password
- Hide Login information in Account settings in Buddy Boss
- Redirect HTTP to HTTPS
- Change gravity forms confirmation redirect query string to include entry id [closed]
- How to redirect visitor to a custom URL using PHP code in functions.php
- Deny access to a path (give 403 or 404 response)
- Redirect home to another page with htaccess
- How do I redirect /search/ to ?s=
- 301 Redirect Loop
- Infinite loop behind SSL proxy on non-standard port
- Redirect from home page to post list page?
- .htaccess rule to redirect old URLs to new structure [closed]
- .htaccess Redirect
- Redirect when accessing /login when logged in
- Built-In Postname Redirection vs Hard Redirects in relation to SEO and performance
- Local Environment Stripping Port Number…help tracking down the redirect?
- User is logged in after Stripe payment, then redirected, but is then logged out again
- How To Fix A Redirect Chain
- Redirect “http://old.net/category/postname” to “https://new.com/postname”?
- Image URLs not redirecting properly
- After logout browser’s back button into twenty sixteen theme profile
- 301 Redirect Old URL to New WordPress Page
- Login Redirect – Multiple Scenarios
- URL masking of subdomain to main domain using .htaccess
- Redirecting from wp-content?
- WP page 404 error only on mobile
- How to stop displaying the Id without losing the functionality
- Redirect user on first visit based on geographical location
- Create a permalink to a pdf?
- My site doesn’t redirect from HTTP to HTTPS
- Bedrock WordPress
- How to prevent redirect 301
- Redirect one domain to another
- Only execute function if SSL is set up properly
- How to redirect wp_login_form to new page after user loged in?
- Redirect User to login page
- How do I Redirect Tags from Old Joomla Site to New WordPress Site?
- How to redirect user after login to the page called by his first name?
- Redirect after get_delete_post_link
- Whenever I try to publish a post in wordpress, I always get redirected to the installation page…why?
- Login redirect to previous page
- Redirect when not logged and parametr in link
- Relink Drupal Permalinks “…node/XXXX” to wordpress Permalinks (e.g./audio/)
- Hide a Post everywhere except on redirect
- Keep the old referrer after failed login
- Redirect Image URL to it’s parent post
- Redirect user if they are logged in
- Redirect to custom post if custom archive page has just one result?
- URL redirect regular expressions redirecting all after first viriable
- 301 Redirect Link to Media
- Redirect not work
- There is 1 redirect
- How to create mass 301 redirects with PHP in Nginx server without using a WP plugin
- HOW do you Redirect buddypress login to EDIT tab not PROFILE tab on profile page? [closed]
- WordPress redirects to backend when i’am not logged in
- Redirect HTTP request to HTTPS request
- Woocommerce login to specific page or referrer
- 301 Redirects when change URL in WordPress database
- How can I redirect to another page with screen already at the bottom of the page?
- How is this URL being redirected?
- Tag archive page not working
- How to move a https website back to dev and access the admin?
- Why is WordPress redirecting to homepage after GET form submit?
- Redirect after user changes password
- Custom Form Redirects to Post after Submit
- Plugin redirects URL structure using 301 redirect. Time to disable the plugin?
- URL is redirecting (301) when query string is passed through URL
- Plugin html-on-pages: URL not redirecting
- Redirect a WP to another with all URL
- How to disable plugin capability : “create new category”