Skip to content
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

Merged
merged 9 commits into from
Feb 3, 2023

Conversation

gchtr
Copy link
Member

@gchtr gchtr commented Nov 9, 2022

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 a WP_Post instance.

Solution

This pull request changes the function signature of Timber\Post::get_info() to accept an array and return an array. The related WP_Post object is converted to an array before being passed to Timber\Post::get_info(). This way, we don’t set properties on a WP_Post, but update the array. This array will then be used to import properties to the Timber\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 extends Timber\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.

@gchtr gchtr added the Ready for Review Ready for a contrib to take a look at and review/merge label Dec 30, 2022
nlemoine
nlemoine previously approved these changes Feb 2, 2023
Copy link
Member

@nlemoine nlemoine left a 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 🙈

@gchtr
Copy link
Member Author

gchtr commented Feb 3, 2023

@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 gchtr merged commit c96b9f8 into 2.x Feb 3, 2023
@gchtr gchtr deleted the 2.x-post-import-data branch February 3, 2023 07:04
@andrewwfesenko
Copy link

@gchtr The introduction of these changes seems to have broken the post previewing:
imageimage

image

Previously it worked fine.

@gchtr
Copy link
Member Author

gchtr commented Mar 7, 2023

@andrewwfesenko What version of Timber v2 are you using? The latest 2.x branch?

@andrewwfesenko
Copy link

@gchtr Yes. Latest 2.x, 34f29b8 commit to be exact.

@gchtr
Copy link
Member Author

gchtr commented Mar 7, 2023

@andrewwfesenko Can you create a new issue with a minimal setup so we can reproduce this? Because I can’t reproduce that bug (yet).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.0 Ready for Review Ready for a contrib to take a look at and review/merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants