Skip to content

Undefined array key error when viewing pages in admin panel#219

Merged
peterwilsoncc merged 2 commits into10up:developfrom
xDehy:develop
Aug 15, 2024
Merged

Undefined array key error when viewing pages in admin panel#219
peterwilsoncc merged 2 commits into10up:developfrom
xDehy:develop

Conversation

@xDehy
Copy link
Copy Markdown
Contributor

@xDehy xDehy commented Jul 22, 2024

Description of the Change

This pull request addresses an "Undefined array key" error that occurs when a post parent ID does not exist in the $children_pages array.

Changes Made:

  • Added an isset() check before accessing the $children_pages array with the post parent ID.
  • If the key does not exist, $siblings is set to an empty array to handle the case gracefully.

Closes #218

How to test the Change

Due to me not knowing exactly how this bug happened as it wasnt originally found by me, I can only assume. This bug was originally found by someone who edited a picture on a page and then dragged that page around to be a child page of another, which resulted in the Undefined array key error on the pages panel.

Changelog Entry

Fixed - issue where an "Undefined array key" error occurs when a post parent ID does not exist in the $children_pages array.

Credits

Props @xDehy

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.
@xDehy xDehy requested review from dkotter and jeffpaul as code owners July 22, 2024 07:52
@vikrampm1 vikrampm1 added this to the 2.7.2 milestone Jul 22, 2024
@xDehy
Copy link
Copy Markdown
Contributor Author

xDehy commented Jul 23, 2024

Just cleaned it up a little, realised I added extra, unnecessary lines of code

@jeffpaul jeffpaul requested review from peterwilsoncc and removed request for dkotter and jeffpaul August 14, 2024 01:55
Copy link
Copy Markdown
Contributor

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @xDehy, this looks good to me.

I was able to reproduce the issue on an Admin > Pages list page containing only one page. This PR fixes the issue.

@peterwilsoncc
Copy link
Copy Markdown
Contributor

Due to me not knowing exactly how this bug happened as it wasnt originally found by me, I can only assume.

Does the person who found the issue have a GitHub account so we can give them credit for discovery?

@xDehy
Copy link
Copy Markdown
Contributor Author

xDehy commented Aug 15, 2024

Does the person who found the issue have a GitHub account so we can give them credit for discovery?

Nope, unfortunately not.

@peterwilsoncc peterwilsoncc merged commit 4b8dbc3 into 10up:develop Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants