-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Multisite: Add WP_Site_State class for efficient site state management #8542
base: trunk
Are you sure you want to change the base?
Multisite: Add WP_Site_State class for efficient site state management #8542
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
Thank you for upgrading my 8-year-old patch to 2025, and turning it into a GitHub PR. 🙏
I left some inline comments, none blocking at all.
Has the wp_xmlrpc_server
class not been updated deliberately? I know it's not something many people use (and is even recommended against in many contexts), but still.
src/wp-includes/ms-blogs.php
Outdated
* @return WP_Site_State A snapshot of the current site state. | ||
*/ | ||
function get_site_state() { | ||
require_once ABSPATH . WPINC . '/class-wp-site-state.php'; |
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.
It doesn't make much of a difference, but this could also be done in wp-includes/ms-settings.php
, making this function pure.
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.
That's a great suggestion. Moving the require to ms-settings.php would make the get_site_state() function more efficient. I'll implement this change.
* @param WP_Site_State $state The site state object to restore to. | ||
* @return bool True on success, false on failure. | ||
*/ | ||
function restore_site_state( $state ) { |
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 wonder if we really need this function. Looking at the Locale API, there is no function to restore locales. It's always done using the relevant method on the (global) locale switcher class instance.
Personally, I think having the above factory function is fine, but doing $site_state->restore();
instead of restore_site_state( $site_state );
feels more natural, and also in line with several other classes that don't have API function wrappers around them.
Thoughts?
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 see your point about directly using the class method instead of a wrapper. I initially created the wrapper function because it follows the pattern used for switch_to_blog() and restore_current_blog()
However, I'm open to removing it if you feel the direct method call is more appropriate. The Locale API example you mentioned makes sense.
Hey @tfrommen, Thank you for reviewing the PR! I really appreciate your detailed feedback. You're right, I didn't update the XML-RPC class since I was focusing on the core multisite functionality first. I can certainly look at improving this class too if you think it would be valuable. I'll update the PR with fixes for the identified issues! |
… XML-RPC user blogs list
Trac ticket: https://core.trac.wordpress.org/ticket/37958
This PR adds a new
WP_Site_State
class and corresponding helper functions that provide methods for managing site state in WordPress Multisite.This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.