Skip to content

Fix invalid property notice for messages#7814

Merged
donnapep merged 3 commits intotrunkfrom
fix/invalid-property-notice
Apr 20, 2025
Merged

Fix invalid property notice for messages#7814
donnapep merged 3 commits intotrunkfrom
fix/invalid-property-notice

Conversation

@donnapep
Copy link
Copy Markdown
Member

@donnapep donnapep commented Apr 19, 2025

Resolves #6412.

Proposed Changes

In certain scenarios such as custom queries, the global $post variable may not be set or may not be an instance of WP_Post. This can occur if the_content is applied outside the main loop or if other plugins/themes manipulate the global $post variable.

To be safe, switching to using get_post instead.

Testing Instructions

N/A. I wasn't able to reproduce, but the code now does an extra check that $post is actually an instance of WP_Post before trying to access the ID property.

Pre-Merge Checklist

  • PR title and description contain sufficient detail and accurately describe the changes
  • Adheres to coding standards (PHP, JavaScript, CSS, HTML)
  • All strings are translatable (without concatenation, handles plurals)
  • Follows our naming conventions (P6rkRX-4oA-p2)
  • Hooks (p6rkRX-1uS-p2) and functions are documented
  • New UIs are responsive and use a mobile-first approach
  • Code is tested on the minimum supported PHP and WordPress versions

@donnapep donnapep added this to the 4.25.1 milestone Apr 19, 2025
@donnapep donnapep self-assigned this Apr 19, 2025
@donnapep donnapep changed the title Fix invalid property notice Fix invalid property notice for messages Apr 19, 2025
@github-actions
Copy link
Copy Markdown
Contributor

Test the previous changes of this PR with WordPress Playground.

@github-actions
Copy link
Copy Markdown
Contributor

Test the previous changes of this PR with WordPress Playground.

@donnapep donnapep merged commit 6eb5f2a into trunk Apr 20, 2025
22 checks passed
@donnapep donnapep deleted the fix/invalid-property-notice branch April 20, 2025 00:14
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.

Trying to get property 'ID' of non-object

1 participant