WordPress.org

Make WordPress Core

Opened 12 years ago

Closed 11 years ago

#10285 closed defect (bug) (fixed)

remove_role not working / code needs change

Reported by: 5ubliminal Owned by: dd32
Milestone: 3.0 Priority: normal
Severity: normal Version: 2.8
Component: Role/Capability Keywords: roles has-patch needs-testing
Focuses: Cc:

Description

Wordpress 2.8, wp-includes/capabilities.php, line 568, method remove_role should be:

$this->caps[$role]
instead of:
$this->roles[$role]

THANKS!

PS: Reported 6 months ago here http://wordpress.org/support/topic/210602 ... yet ignored.

Attachments (1)

10285.diff (548 bytes) - added by Denis-de-Bernardy 12 years ago.

Download all attachments as: .zip

Change History (12)

#1 @Denis-de-Bernardy
12 years ago

  • Component changed from General to Role/Capability
  • Milestone changed from Unassigned to 2.9
  • Owner set to Denis-de-Bernardy
  • Severity changed from blocker to normal

#2 @Denis-de-Bernardy
12 years ago

  • Owner Denis-de-Bernardy deleted
  • Status changed from new to assigned

#3 @dd32
12 years ago

  • Keywords needs-testing added

Does anyone feel like verifying this?

#4 @Denis-de-Bernardy
12 years ago

  • Keywords close added; needs-testing removed

seems invalid.

// var_dump new WP_User(1)...

  ["caps"]=>
  &array(1) {
    ["administrator"]=>
    bool(true)
  }
  ["cap_key"]=>
  string(15) "wp_capabilities"
  ["roles"]=>
  array(1) {
    [0]=>
    string(13) "administrator"
  }

#5 @Denis-de-Bernardy
12 years ago

  • Keywords has-patch added; close removed

maybe not, actually. based on the var_dump, $this->roles[$role] would always be empty. should be $this->caps[$role] indeed, or in_array($role, $this->roles).

Attaching an untest patch.

#6 @dd32
12 years ago

  • Keywords needs-testing added

not sure that patch does justice either.. specifically you only changed 1 of the references to the array on that line.

That being said, with that change, i'm getting a notice:

 Notice: Trying to get property of non-object in C:\www\wordpress\wp-includes\capabilities.php on line 537

http://core.trac.wordpress.org/browser/trunk/wp-includes/capabilities.php#L537

..Seems $role is set to (string)$roll_name, and not a roll object.. not sure why.. could be due to the test code i'm using, that being said, it needs more testing.

#7 @ryan
12 years ago

  • Milestone changed from 2.9 to 3.0

Postponing to 3.0 where we plan to work on roles.

#8 @Codebanter
12 years ago

I'm glad I searched and found this before posting the same bug. Also glad to see that it will be addressed in 3.0.

I agree with Denis in saying that the in_array solution will work fine. I created a plugin to use in my sites and uploaded it or others to use.
http://codebanter.com/wp_stuff/

#9 @dd32
11 years ago

(In [13784]) Fix WP_User::remove_role(). See #10285

#10 @dd32
11 years ago

  • Owner set to dd32
  • Status changed from assigned to accepted

Can those affected please test with the changes in that last commit there?

Here's the code i've used for testing purposes:

add_role('test', 'Test Role');
$role =& get_role('test');
$role->add_cap('test_cap_here');

$user = new WP_User('test');

$before = $user->allcaps;

$user->add_role('test');
$user->remove_role('test');

var_Dump( $before == $user->allcaps );

remove_role('test');

Should display "true" for success, "False" for failure. If it fails, the next iteration will fail too, but the 3rd will succeed.

As a side note, the user_level was not being set upon role removal, So it could lead to a higher level being set incorrectly.. User levels are deprecated and no-one should be relying on them however.

#11 @dd32
11 years ago

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

If someone finds something which is directly caused by this change, feel free to re-open.

Note: See TracTickets for help on using tickets.