Fix Undefined array key 0 warning when super admins are not zero-indexed#13074
Open
thisismyurl wants to merge 1 commit into
Open
Fix Undefined array key 0 warning when super admins are not zero-indexed#13074thisismyurl wants to merge 1 commit into
thisismyurl wants to merge 1 commit into
Conversation
…xed (google#12671) Has_Multiple_Admins::get() read $super_admins[0] to find the super admin to exclude from the local admin count. get_super_admins() can be filtered to a non-sequentially-keyed array, so index 0 may not exist, producing a PHP "Undefined array key 0" warning and leaving the super admin double-counted. Use reset() to take the first element regardless of its key. Adds a regression test that forces a non-zero-keyed super_admins array and asserts the admin count is not inflated.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Author
|
@googlebot I signed it! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey team,
On multisite,
Has_Multiple_Admins::get()reads$super_admins[0]to find the super admin to exclude from the local admin count.get_super_admins()can be filtered to return a non-sequentially-keyed array, so index 0 may not exist. That throws a PHP "Undefined array key 0" warning, and because the lookup then fails, the super admin isn't excluded and gets double-counted.Using
reset()takes the first element regardless of its key. The regression test forces a non-zero-keyedsuper_adminsarray and asserts the counted admins is 2, not 3 — without the fix the super admin is double-counted.I verified the
reset()versus[0]behaviour with a standalone check and matched the new test to your existing multisite cases inHas_Multiple_AdminsTest. I don't have a local multisite wp-env, so the test runs on CI. I also didn't add a changelog entry because I wasn't sure of your current per-PR format; happy to add one in whatever shape you use. I know the Google CLA needs signing before this can merge.Closes #12671
(full disclosure: AI helped me identify the issue and verify my work)