WordPress.org

Make WordPress Core

Opened 2 months ago

Closed 2 months 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:

  1. Create a new multisite
  2. Make sure to turn on

define( 'WP_DEBUG', true
define( 'WP_DEBUG_LOG', true )

  1. Add a new site. Use a different email address than the admin email.
  2. Use this plugin (copy from this https://gist.github.com/moon0326/34551bd7cedbd633e7d510ba9fca35d9) to print return value of wp_get_current_user().
  3. Open terminal and cd to :your-wordpress-dir/wp-content/ and start tailing debug.log
  4. Visit the new site. Notice that the WP_User object has no roles.
  5. Go back to the original site. Notice that the WP_User object has roles now.

Change History (4)

#1 @SergeyBiryukov
2 months ago

  • Component changed from General to Users
  • Focuses multisite added

#2 follow-up: @johnbillion
2 months ago

  • Keywords reporter-feedback added

@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.

#3 in reply to: ↑ 2 @moon0326
2 months 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.

Last edited 2 months ago by moon0326 (previous) (diff)

#4 @johnbillion
2 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Thanks for the update! In that case I'll close this off.

Note: See TracTickets for help on using tickets.