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
Prevent unneeded blog switching in multisite env. #2781
Conversation
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.
Good catch!
I only found some issues with strict types, otherwise this looks good to me.
@Levdbas I’ve marked this as 2.x future, because it’s not essential to include this in the Release Candidate for Timber 2.0 ;). |
No problem! I think I managed to fix the PR though. Prior to this PR Timber was always switching to a blog, no matter what. After my initial changes Timber was still always changing because of the strict checking and without transforming the $blog_identifier in an INT first, still resulting in always switching in these tests and thus passing the tests. After applying your suggestions, it finally passed the strict testing and resulting in not switching for the first time but resulting in testing errors. What I did to make the tests work again: Add I think this is because timber/tests/test-timber-multisite.php Line 192 in 3e45f8a
So by setting the Let me know what your thoughts. |
To get some further experience with PRs I wanted to tackle an older issue.
Related:
Issue
switch_to_blog() was used when not needed in multisite environments, resulting in unneeded globals being set.
Solution
Only use switch_to_blog() when the ID is different from the current id blog id. While at it, I changed some internal variables to reflect the new internal working and updated the docblock as well. I also added a fallback when get_blog_details() returns null instead of a site object.
Impact
Less globals set in the form of $GLOBALS['_wp_switched_stack'] and $GLOBALS['switched']
Testing
Current tests are covering it.