OK, it wasn’t easy to catch, but… There is one major problem in your code…
First check you make is:
if ( is_user_logged_in() == 1 ) {
And is_user_logged_in()
is based on global $current_user
variable. But… As you can read in login_redirect
hook docs:
The $current_user global may not be available at the time this filter
is run. So you should use the $user global or the $user parameter
passed to this filter.
So this condition won’t be satisfied – so your code won’t change anything.
You should use $user
variable that is passed as param, so this should do the trick:
public function login_redirect( $redirect_to, $request, $user ) {
if ( is_a ( $user , 'WP_User' ) && $user->exists() ) {
if ( $user->has_cap( 'manage_woocommerce' ) ) {
$redirect_to = get_admin_url() . 'admin.php?page=my-page';
}
}
return $redirect_to;
}
add_filter( 'login_redirect', array( $this, 'login_redirect' ), 10, 3 );
Related Posts:
- wordpress custom login successful redirect hook
- Janrain/Simple Modal under Redirected Domain
- WordPress Admin login redirect to homepage
- How do I to override login redirect on specific pages?
- Redirection plugin – how to let the editor access the ‘redirection’ menu?
- SSL redirect loop using WordPress HTTPS Plugin
- Redirection Plugin: Redirect all URLs with a regular expression
- How to get user-meta from Social Login registered users?
- Which hook should be used to validate custom form fields on the login form?
- How can I make content disappear when a user logs in?
- flush_rewrite_rules not working on plugin deactivation, invalid URLs not showing 404
- Can Not Redirect from Plugin-Registered Admin Page
- Tracking last login and last visit
- login to wordpress with Get variables instead of Post
- Detecting $_GET parameters from any page + Cookie
- How to send “Location” header on plugin form submit event?
- Prevent Brute Force Attack
- Custom url structure for custom template
- Login with email (WP Modal Login)
- Check if the front end user is log in or not
- How to create a word press user with hashedpassword
- How to redirect Old Post URL to new Post and keep Old post Comments?
- What’s the _wp_desired_post_slug value for?
- Redirect all blog links from WordPress.com site to new domain
- WordPress login with Phone Number [closed]
- wp_authenticate but not logged in
- how can I link to a PlugIn admin-sub-menu page after processing a formular
- How do i login when i cant access wp-login.php?
- Changed permalink structure. Need help with redirecting old posts
- Landing Page Redirect Chain | http->https->https www
- Single central login for front end users from any site
- how to create site exit messages with destination url displayed
- Plugin: Google Analytics for Dashboard error – Timestamp is too far from current time
- How to save generated JWT token to cookies on login?
- Redirecting a buddyboss profile tab to a different tab if not subscribed to a specific membership
- How to fix the woocommerce – adaranth.com redirection issue [closed]
- Redirecting thousands of posts that currently have no category in their permalink when changing permalink structure to include category
- Login cookies set as wrong domain
- Login Customizer doesn’t change the background of the register form
- Removing Automatic Redirects Without Plugin
- WordPress 4.3 broke meta redirect (with url params plugin)
- Login problem after installing my written plugin [closed]
- Get ‘Headers already sent’ error for the plugin I am creating when I try to login
- Mask and Track Outbound Links
- Possibility to login without password
- how do i change my website facebook login button to another text immediately user login? [closed]
- WordPress unable to write files in the server
- Custom PHP Page Using WordPress login
- Making the ‘add to cart’ button redirect to PayPal
- How to force load a page in plugin?
- If I use an alternative login (e.g. CAS or other SSO) plugin, is my site protected from the recent brute force login attempts?
- Preserve Search engine index while shifting to new Domain
- Linking form to user meta fields
- WordPress Multisite Profile Picture Sync Error with Nextend Social Login Plugin
- Plugin or ways to limit number of users logging in the website,
- force logged in user to stay in the dashboard
- login form should redirect to register page for in 1st login next time it should redirected to home page
- www redirects to another directory in wordpress
- Hidden permalink different from displayed permalink
- redirect to homepage once action is completed
- Share login credential with QR code
- Redirect to a page while maintaining search query parameters without causing an infinite loop
- Which membership plugin for a simple sign in? Personal areas for customers
- Discern a specific plugin’s action hooks
- Can’t add new plugin or themes on a wordpress multisite network from the primary site as administrator. Error: ERR_TOO_MANY_REDIRECTS
- Login/password protected “client page”
- How to send new visitor to a splash page for only one time in wordpress?
- Why is my site still showing insecure icon even if I have SSL certificate?
- https rewrite not working for All in one security Brute force > rename login url
- On button click, redirect users to registration page instead of another page
- When the user entered an unauthorized url redirect to login page
- How to show private pages based on a user’s role?
- redirect to a custom page
- .htaccess file doesn’t work, with hundred tries
- using wordpress login details for other website / application / forum?
- Infinite 301 redirects after definitions in “Redirections” plugin?
- wp_signon returns user, in popup window, but the user is not logged in
- wp_login_form() ignoring login_form action hook
- AJAX login without a plugin does not work. when add a action to function.php
- Redirect default login page to a custom page [duplicate]
- How to redirect from plugin page
- wp-admin will not redirect to wp-login.php
- Template redirect inside of plugin not redirecting
- Adding google authenticator and use only email address of user
- Can’t redirect to previous page after using GET
- First argument is expected to be a valid callback for cp_admin_init and _canonical_charset
- how to protect wordpress website
- Need to change contact email depending where user is from
- WordPress ReAuth =1 Loop with wpCAS
- Advice on setting up private site
- Checking url from plugin [duplicate]
- Change All Login/Signup Links in Plugin
- plugin for different writers [closed]
- How to resolve these findings from security audit
- ERROR: Cookies are blocked due to unexpected output – no access to FTP
- How to Find WordPress site has backdoor login Codes
- How to create a custom wordpress plugin for a specific functionality?
- WordPress Homepage Login
- I cannot login after installing the wp-login timeout setting plugin
- Page with redirect