-
Notifications
You must be signed in to change notification settings - Fork 156
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
Ensure post abstraction methods use correct site ID. #1010
Conversation
return $result; | ||
} | ||
|
||
/** |
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.
::__get()
and ::__isset()
methods are unchanged but have been relocated to group all the magic methods together.
In the revised PR #1010 (in draft), I went with a |
e26156c
to
dc19355
Compare
Description of the Change
This resolves an issue in which the post abstraction can return a mix of data on Multisite networks when the site is switched.
It introduces the
DistributorPost::__call()
magic method to ensure the current site (get_current_blog_id()
) matches the site ID used to instantiate the object.To match the PHP behavior without the magic method, a fatal error is thrown if the method name does not exist.
To discourage developers from calling the helper methods while using a switched site, a notice is thrown if the magic method needs to switch sites.
To avoid site switching when possible, an in memory cache is used to bypass the site switch the second or subsequent time a method is called. The cached data is only used if the object is called from the wrong site to reduce the risk of errors caused by the addition/removal of hooks during runtime. Basically it's a performance compromise.
Closes #1007.
Supersedes #1004.
TODO
$dt_post->source_site
doesn't result in multiple switchesHow to test the Change
Changelog Entry
Credits
Props @peterwilsoncc, @dkotter
Checklist: