Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#34495 closed defect (bug) (fixed)

Negative number for "No role"?

Reported by: pavelevap's profile pavelevap Owned by: johnbillion's profile johnbillion
Milestone: 4.4 Priority: normal
Severity: normal Version: 4.4
Component: Users Keywords: needs-patch
Focuses: Cc:

Description

Is it possible? See attached screenshot.

Attachments (1)

No_role_negative_number.png (869 bytes) - added by pavelevap 11 years ago.

Download all attachments as: .zip

Change History (13)

#1 @johnbillion
11 years ago

  • Keywords reporter-feedback added

Can you provide some more info please? A question does not make a good bug report.

It looks like you may have some malformed users in your users table.

#2 @pavelevap
11 years ago

Sorry, I had to go and did not have time to find additional details. There are 11 users, one of them (admin) has 2 roles (Administrator and Keymaster), all others only one (standard WP roles). Keymaster role is probably from bbPress, but this plugin is not active now. There is no user without role. Any ideas what should I check tomorrow?

#3 @netweb
11 years ago

I just tried various combinations of activating and deactivating bbPress to try and recreate a user without a role and could not.

#4 @pavelevap
11 years ago

So, I tried to debug it a little bit and problem is here: https://core.trac.wordpress.org/browser/trunk/src/wp-includes/user-functions.php#L779

$role_counts['none'] = ( $total_users - array_sum( $role_counts ) );

This logic does not work for me.

$role_counts:

array(5) { ["administrator"]=> int(1) ["editor"]=> int(1) ["author"]=> int(2) ["subscriber"]=> int(7) ["bbp_keymaster"]=> int(1) }

array_sum( $role_counts ): int(12)

$total_users: int(11)

Result is -1

bbPress plugin is deactivated, but was active before and Administrator is also Keymaster.

#5 @johnbillion
11 years ago

  • Keywords needs-testing added; reporter-feedback removed
  • Milestone changed from Awaiting Review to 4.4
  • Owner set to johnbillion
  • Status changed from new to reviewing

#6 @johnbillion
11 years ago

  • Keywords needs-patch added; needs-testing removed

This is reproducible if you've a user on your site with a role that no longer exists (for example by using the Members plugin to add a role, assigning a user that role, then deactivating the Members plugin) and then subsequently activate a plugin such as bbPress which also adds a custom user role. I've not dug into the root cause yet.

Last edited 11 years ago by johnbillion (previous) (diff)

#7 @johnbillion
11 years ago

cc @greenshady just FYI

Last edited 11 years ago by johnbillion (previous) (diff)

#8 @greenshady
11 years ago

I believe this is the changeset where this issue was introduced: [34965]

This ticket was mentioned in Slack in #core by wonderboymusic. View the logs.


11 years ago

#10 @SergeyBiryukov
11 years ago

  • Component changed from General to Users

#11 @johnbillion
11 years ago

In 35707:

Ensure the count for users with no role remains accurate when users with multiple roles are present.

See #34495

#12 @johnbillion
11 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

Turns out this was due to miscalculation of user counts when users with multiple roles are present. Fixed in [35707].

Note: See TracTickets for help on using tickets.