Skip to content

fix: prevent undefined array key warning in DistributorPost::get_extra_data#1372

Open
oleksandrhurskyi wants to merge 2 commits into10up:developfrom
oleksandrhurskyi:fix/update-extra-data
Open

fix: prevent undefined array key warning in DistributorPost::get_extra_data#1372
oleksandrhurskyi wants to merge 2 commits into10up:developfrom
oleksandrhurskyi:fix/update-extra-data

Conversation

@oleksandrhurskyi
Copy link
Copy Markdown

@oleksandrhurskyi oleksandrhurskyi commented Apr 21, 2026

Description of the Change

Prevent undefined array key warning in DistributorPost::get_extra_data()

Call populate_source_site() explicitly at the start of get_extra_data() before accessing source_site array keys. Direct array access bypasses the __get magic method when source_site is already a declared but empty property, causing an undefined array key warning on source site save.

Added null coalescing fallbacks as a secondary guard.

Fixes #1371

How to test the Change

  1. Connect a site to an external connection
  2. Enable logging of PHP warnings to an external file in wp-config, on both the source and target site
  3. Create, publish and distribute a post
  4. Update the post
  5. Ensure the target site does not throw the warning PHP Warning: Undefined array key "name" in /vagrant/content/plugins/distributor/includes/classes/DistributorPost.php on line 688

Changelog Entry

Fixed - Prevent undefined array key warning in DistributorPost::get_extra_data()

Credits

Props @oleksandrhurskyi, @peterwilsoncc

Checklist:

    fix: prevent undefined array key warning in DistributorPost::get_extra_data

    Call populate_source_site() explicitly before accessing source_site array
    keys, as __get() magic method is not triggered when the property already
    exists. Add null coalescing fallbacks for name and home_url keys to handle
    external connections where these values may be absent.
@oleksandrhurskyi oleksandrhurskyi requested a review from a team as a code owner April 21, 2026 16:23
@oleksandrhurskyi oleksandrhurskyi requested review from peterwilsoncc and removed request for a team April 21, 2026 16:23
Copy link
Copy Markdown
Collaborator

@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.

I've added a comment inline.

I've gone through and edited the pull request description to follow the template and clear the warning by the bot.

Are you able to review our Code of Conduct and if you agree check the box in the PR description that you do so?

I can get this merged once that's done.

Comment thread includes/classes/DistributorPost.php
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.

ErrorException: Undefined array key "home_url" in DistributorPost::get_extra_data()

2 participants