-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trac/43421 #7351
base: trunk
Are you sure you want to change the base?
Trac/43421 #7351
Changes from 1 commit
e67221b
016fe1a
3a4adec
925c285
2566498
83a3538
7d5d1f7
ccf5d0d
e764924
c284c8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,6 +160,13 @@ public function add_role( $role, $display_name, $capabilities = array() ) { | |
return; | ||
} | ||
|
||
foreach( $capabilities as $key => $value ) { | ||
if(!is_bool($value)) { | ||
$capabilities[$value] = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if That could theoretically overwrite an intentionally blocked capability with an unintentionally allowed one. |
||
unset($capabilities[$key]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsetting the numeric array key does make sense to me in this scenario. 👍 |
||
} | ||
} | ||
|
||
$this->roles[ $role ] = array( | ||
'name' => $display_name, | ||
'capabilities' => $capabilities, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this reuses
$value
as a key on lines 165 & 166, it would make the code more resilient to do:is_int( $key ) && is_string( $value )
But, I think if we are considering doing argument validation, it may warrant a dedicated method – one where we can more intentionally conclude (and document) what mutations will take place to what kind of submitted keys & values.
(The obvious benefit of a dedicated method would be reuse elsewhere that an array of caps is passed in as an argument, ensuring the same results, and ability to write unit tests for it.)
Alternatively,
wp_is_numeric_array()
could be used before the newforeach
, but that function checks that all array keys are numeric, which means we’d lose support for mixed key types (which was an example in the core ticket).