Opened 3 years ago
Closed 3 years ago
#53231 closed defect (bug) (invalid)
wp_get_current_user() doesn't return roles and capabilities on a multisite
Reported by: | moon0326 | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Users | Keywords: | reporter-feedback |
Focuses: | multisite | Cc: |
Description
wp_get_current_user() doesn't return roles and capabilities on a multisite even when you're logged in as a super admin. This is causing https://github.com/woocommerce/woocommerce-admin/issues/7004
How to test:
- Create a new multisite
- Make sure to turn on
define( 'WP_DEBUG', true
define( 'WP_DEBUG_LOG', true )
- Add a new site. Use a different email address than the admin email.
- Use this plugin (copy from this https://gist.github.com/moon0326/34551bd7cedbd633e7d510ba9fca35d9) to print return value of wp_get_current_user().
- Open terminal and cd to :your-wordpress-dir/wp-content/ and start tailing debug.log
- Visit the new site. Notice that the WP_User object has no roles.
- Go back to the original site. Notice that the WP_User object has roles now.
Change History (4)
#3
in reply to:
↑ 2
@
3 years ago
dReplying to johnbillion:
@moon0326 Does the Super Admin user have a role on the new site that you added? If not, this is expected behaviour. A Super Admin can perform any action on any site on the network, but they won't have a role or any capabilities on the site unless they're added to that site.
Thank you for the clarification. That makes sense.
I just confirmed that it works after adding the admin to the site.
Note: See
TracTickets for help on using
tickets.
@moon0326 Does the Super Admin user have a role on the new site that you added? If not, this is expected behaviour. A Super Admin can perform any action on any site on the network, but they won't have a role or any capabilities on the site unless they're added to that site.