Skip to content

Fixing bug where WP_User->roles array does not start with a 0 index#815

Closed
desrosj wants to merge 1 commit intoxwp:developfrom
desrosj:develop
Closed

Fixing bug where WP_User->roles array does not start with a 0 index#815
desrosj wants to merge 1 commit intoxwp:developfrom
desrosj:develop

Conversation

@desrosj
Copy link
Copy Markdown
Contributor

@desrosj desrosj commented Jan 22, 2016

See #814 for context.

…user responsible for the item does not have a WP_User->roles array that starts with a 0 index.
@tylerhcarter
Copy link
Copy Markdown
Contributor

@desrosj Attempting to reproduce the issue. Do you know under what circumstances you were not getting a 0 index array?

@desrosj
Copy link
Copy Markdown
Contributor Author

desrosj commented Feb 24, 2016

I believe I have it narrowed down to the user having a capability added to their account prior to their current role. The key in the roles property in WP_User appears to correspond with it's placement in the caps property. The site that I noticed this error on was assigning capabilities to users that were not in a role in order to allow access to content in a drip manner.

To reproduce:

  1. Create new user.
  2. With code, or a plugin that allows you to add custom capabilities, add a capability that is not a role to the user (in our scenario it was $user->add_cap( 'custom_cap' ).
  3. Change the user's role (can be with code or in the admin).

You should then notice the error then. If you print out or log the WP_User object, you will notice the order of items in $user->caps and the keys in $user->roles.

@tylerhcarter
Copy link
Copy Markdown
Contributor

Reproduced the bug and verified the code fix. Refreshing the commit in pr/815

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants