-
-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2.x Update Timber\Post::get_info() to work with a post data array only #2674
Conversation
…r/post/import_data filter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with your considerations. But it works in the meantime 🙈
@nlemoine Thanks for the feedback 👍. I opened a new issue in #2704 where we can think about a better solution for this. I think we could do this more: Merge in pull requests if they work for the moment and create new issues where we can decide whether it needs to be fixed immediately or sometime in the future. I will merge this in now, because the tests are fine (except for the tests with PHP 8.2). |
@gchtr The introduction of these changes seems to have broken the post previewing: |
@andrewwfesenko What version of Timber v2 are you using? The latest |
@andrewwfesenko Can you create a new issue with a minimal setup so we can reproduce this? Because I can’t reproduce that bug (yet). |
Resolves:
Issue
The different usages of
Timber\Post::get_info()
are not implemented consistently. Sometimes it’s implemented with an array as the parameter an other times with aWP_Post
instance.Solution
This pull request changes the function signature of
Timber\Post::get_info()
to accept an array and return an array. The relatedWP_Post
object is converted to an array before being passed toTimber\Post::get_info()
. This way, we don’t set properties on aWP_Post
, but update the array. This array will then be used to import properties to theTimber\Post
instance.I also moved a test related to previews to the corresponding test class.
This will also fix a related issue in #2668 where PHPStan warns about setting undefined properties on a post.
Impact
If you use a custom
get_info()
method in a class that extendsTimber\Post
, you would have to update your code. This is documented in the Upgrade Guide.Usage Changes
See Impact.
Considerations
Maybe there’s a better solution than using arrays only. It will fix PHPStan issues, but it’s not really preventing us from setting undefined properties.
Testing
Yes.