-
Notifications
You must be signed in to change notification settings - Fork 17
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
Fix a bug where adding superadmins would crash if none existed before #22
Conversation
@@ -194,6 +194,13 @@ public function remove( $args, $_ ) { | |||
|
|||
private static function get_admins() { | |||
// We don't use get_super_admins() because we don't want to mess with the global | |||
return get_site_option( 'site_admins', array('admin') ); |
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.
Just casting to (array)
here should do the exact same thing.
Thanks for the pull request, @Nomafin ! I think the above problem can be solved with a simple cast to |
Yeah, this is definitely simpler approach. I actually thought this as well, but decided for the if clause for better readability. But I agree that this would do as well. |
Yes, I can see why the if clause might be more readable. However, I think that the if clause also implies there is some logic being done here. This is not the case, though, we just fix the type of the return value of the WordPress function, as the WordPress return value is just borked in this case. |
@Nomafin Would you be up to adding a test for this error case as well, to make sure the WP behavior never changes and we don't introduce a regression later on? |
@Nomafin I will work on the tests for this myself in the coming days to close this PR. |
I think I ran into this exact problem, with some more verbose errors:
|
Fix a bug where adding superadmins would crash if none existed before
Backtick code references so they're properly formatted on the website
The
add
command crashes if there are no super admins present when trying to add a new one thus prevents the admin fixing the situation.Returning empty array instead of
null
from theget_admins()
function prevents the crash becausein_array()
on line 107 expects an array.