Skip to content

Fix Undefined array key 0 warning when super admins are not zero-indexed#13074

Open
thisismyurl wants to merge 1 commit into
google:developfrom
thisismyurl:fix/12671-super-admins-non-sequential-keys
Open

Fix Undefined array key 0 warning when super admins are not zero-indexed#13074
thisismyurl wants to merge 1 commit into
google:developfrom
thisismyurl:fix/12671-super-admins-non-sequential-keys

Conversation

@thisismyurl

Copy link
Copy Markdown

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-keyed super_admins array 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 in Has_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)

…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.
@google-cla

google-cla Bot commented Jul 7, 2026

Copy link
Copy Markdown

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.

@thisismyurl

Copy link
Copy Markdown
Author

@googlebot I signed it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Address multisite PHP Warning: Undefined array key 0 in Has_Multiple_Admins.php line 93

1 participant