#32450 closed task (blessed) (fixed)
WP_Site class
Reported by: | jeremyfelt | Owned by: | jeremyfelt |
---|---|---|---|
Milestone: | 4.5 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Networks and Sites | Keywords: | has-patch |
Focuses: | multisite | Cc: |
Description
Historically, the global $current_blog
has been a stdClass
and has not had any methods attached to it. We should better define this as an instance of a WP_Site
object.
This ticket should:
- Introduce the
WP_Site
class and have base properties and methods for interacting with a site object. - Apply the new class where it can be used within core.
- Provide tests for any methods introduced.
See #31985 for the WP_Network
class equivalent of this ticket.
Attachments (4)
Change History (43)
This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.
9 years ago
This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.
9 years ago
This ticket was mentioned in Slack in #core by jeremyfelt. View the logs.
9 years ago
This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.
9 years ago
#6
follow-up:
↓ 7
@
9 years ago
- Owner set to jeremyfelt
- Status changed from new to assigned
@jeremyfelt, do you think this will still make 4.3 with two weeks left until beta?
#7
in reply to:
↑ 6
@
9 years ago
Replying to obenland:
@jeremyfelt, do you think this will still make 4.3 with two weeks left until beta?
@obenland - likely not, though I'm going to keep the 4.3 milestone attached to it for a bit longer just in case. :) Slack log from yesterday.
This ticket was mentioned in Slack in #core by wonderboymusic. View the logs.
9 years ago
#10
@
9 years ago
@jeremyfelt, I'd like to suggest the following additions:
- adding support to pass WP_Site to switch_to_blog
- adding a method "switch_to" to the WP_Site that would pass itself/id to the switch_to_blog
this would allow for things like
switch_to_blog( get_site_by_path( 'mysitepath' ) );
or
$my_site = get_site_by_path( 'mysitepath' ); $my_site->switch_to();
both of which would end up performing the same code in the end, but allows for promoting the WP_Site to a primary object.
This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.
9 years ago
This ticket was mentioned in Slack in #core by jeremyfelt. View the logs.
9 years ago
This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.
9 years ago
#14
@
9 years ago
- Milestone changed from Future Release to 4.4
- Type changed from enhancement to task (blessed)
32450.01.patch is a good start. I don't think it's far from an initial commit that models the database in the same way that WP_Network
, WP_Comment
, and WP_Post
all do.
We should aim to introduce that first, and apply it to areas of core as possible. It may be a little tougher than WP_Network
only because multisite does actually handle multiple sites by default. :)
This ticket was mentioned in Slack in #core by jeremyfelt. View the logs.
9 years ago
This ticket was mentioned in Slack in #core by drew. View the logs.
9 years ago
This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.
9 years ago
This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.
9 years ago
#19
@
9 years ago
- Milestone changed from 4.4 to Future Release
This hasn't gotten the attention it deserves after the initial patch. We should try to make some progress on this before the 4.5 cycle.
#20
follow-up:
↓ 22
@
9 years ago
- Milestone changed from Future Release to 4.5
32450.diff is my latest version of this that I forgot to upload a while ago. :)
Moving this to 4.5
This ticket was mentioned in Slack in #core-multisite by drew. View the logs.
9 years ago
#22
in reply to:
↑ 20
@
9 years ago
Replying to jeremyfelt:
32450.diff is my latest version of this that I forgot to upload a while ago. :)
Moving this to 4.5
This seems doable today IMO. And the diff between our two patches is the start of WP_Site_Query
.
Do we want to consolidate the individual status properties immediately afterwards? It would be nice to avoid having all of those separate object variables if we plan to collapse them in a future release.
#23
follow-up:
↓ 27
@
9 years ago
The blog-details
& blog-lookup
cache keys contain the same data, which is essentially the details of a blog look-up (imagine that.) I'm not confident how to best combine these into 1 canonical place, since sites are queried both by site ID and by domain & path, but I think it'd be nice to have a single bucket for sites rather than 2.
As I type this, I wonder if blog-lookup
is meant to piggy-back domain aliasing. Maybe worth giving it a peek, too.
#24
@
9 years ago
There is also the is_blog_installed
cache key that we might be able to tack onto this. A site should know if it's installed correctly, especially if that's a thing whole WordPress installations need to be cognizant of.
This ticket was mentioned in Slack in #core by jeremyfelt. View the logs.
9 years ago
This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.
9 years ago
#27
in reply to:
↑ 23
@
9 years ago
- Keywords has-patch added; needs-patch dev-feedback removed
- Status changed from assigned to accepted
Another refresh in 32450.2.diff.
In the previous patch, I was hoping we could populate the blogname
, home
, siteurl
, and post_count
properties as part of the WP_Site
object. This relies on get_option()
which in turn relies on wp-includes/formatting.php
—which is not included during the bootstrap process—and on setting the $wpdb
table prefixes. Chicken meet egg. :)
That's been backed out to focus only on mirroring the database structure for the time being. This seems to provide a pretty clear path.
The latest patch also adds sites
to our global groups and ensures the site's sites
cache is cleared in clean_blog_cache()
. (See #29247, #35251)
Replying to johnjamesjacoby:
Do we want to consolidate the individual status properties immediately afterwards? It would be nice to avoid having all of those separate object variables if we plan to collapse them in a future release.
Definitely open to this. Am I imagining it correctly as $wp_site->status
with $wp_site->spam
still accessible (via _get()
)? Are there any downsides to consolidating those?
Replying to johnjamesjacoby:
The
blog-details
&blog-lookup
cache keys contain the same data, which is essentially the details of a blog look-up (imagine that.) I'm not confident how to best combine these into 1 canonical place, since sites are queried both by site ID and by domain & path, but I think it'd be nice to have a single bucket for sites rather than 2.
It would be nice to pre-populate these on object creation if possible. We might be able to rework get_blog_details()
a bit, especially as WP_Site_Query
starts to be more obvious.
Replying to johnjamesjacoby:
There is also the
is_blog_installed
cache key that we might be able to tack onto this. A site should know if it's installed correctly, especially if that's a thing whole WordPress installations need to be cognizant of.
This one looks a little harder since it deals with the options tables. Worth exploring in another ticket once we have WP_Site
in?
@toscho and I also had a discussion yesterday in Slack around public/private properties. After poking around some more, I'm still inclined to leave them as public
.
The $current_blog
object has been around and stompable for years. We've also provided a blog_details
filter since pre-merge that allows a site's object to be directly filtered. It's tempting to protect the properties, but I'd rather error on the side of back-compat here.
I can see adding getters/setters to help ensure the quality of the data.
This ticket was mentioned in Slack in #core by drew. View the logs.
9 years ago
#33
@
9 years ago
Probably not - I'm going to take one more closer look tomorrow to make sure, but then I'll close it up.
#36
@
9 years ago
- Resolution set to fixed
- Status changed from accepted to closed
Closing this out, thanks everyone! We can open new tickets for bugs if they come up.
#38
in reply to:
↑ 37
@
9 years ago
Replying to spacedmonkey:
Should
wp_get_sites
return a array ofWP_Site
objects?
Definitely. And we'll need to do some instance juggling (like WP_Post does) to make this happen on a broader scale.
32450.01.patch does the following:
WP_Site
class usingWP_Post
for inspirationget_site_by_path()
into a staticget()
methodget_instance()
method similar toWP_Post::get_instance()
, but I don't see a practical use case for it yetThis patch isn't very great, but is... something. We should iterate towards replacing
get_site_by_path()
usages withnew WP_Site( $args )
usages instead.