[wp-trac] [WordPress Trac] #40180: Introduce `get_site_by()` function for multisite

WordPress Trac noreply at wordpress.org
Sat Sep 30 03:02:43 UTC 2017


#40180: Introduce `get_site_by()` function for multisite
-------------------------------------------------+-------------------------
 Reporter:  flixos90                             |       Owner:  flixos90
     Type:  enhancement                          |      Status:  assigned
 Priority:  normal                               |   Milestone:  4.9
Component:  Networks and Sites                   |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch dev-feedback has-unit-     |     Focuses:  multisite
  tests ms-roadmap needs-dev-note                |
-------------------------------------------------+-------------------------

Comment (by flixos90):

 Replying to [comment:25 jeremyfelt]:
 > I'm a little unsure of the `domain` and `path` arguments as implemented.
 We don't have the same `is_subdomain_install()` restrictions in
 `get_sites()`. I would argue that if somebody is looking for protection
 like that, they should adjust based on their awareness of the environment
 rather than maybe go away thinking that a site doesn't exist. I may be
 biased because in the current form, I would not be able to use
 `get_site_by( 'domain' ... )` in my configuration.

 I think these restrictions make sense, as I see `get_site_by()` as a
 function that should generally only run a query which will produce a
 single result (even if it didn't have the `limit` argument). I don't think
 it should be a "here is some input, give me a random site for which this
 data applies" function. Using a full `url` will always fulfill this
 requirement (unless someone has similar www and non-www URL sites, which
 is edge-case though), using a `slug` will too on regular multisite setups.
 `domain` and `path` are basically more specific variants of `slug`, to be
 used when it's already clear that the setup is subdomain/subdirectory
 (`get_blog_details()` supports this only for subdomain installs for some
 reason, but it does support the general idea).
 I may be a bit conservative here, but what I'm essentially saying that
 `slug`, `domain` and `path` only exist to account for the typical
 multisite (where no sub-site has an actually distinct non-subdomain domain
 name etc.). With anything custom, `get_site_by()` should mostly be used
 with `url` (and `id` which always works of course).

 > For the `slug` argument, I'm not sure we can assume that `path` will
 always be `$network->path` when `is_subdomain_install()`. I would go the
 other way and assume that we could leave `path` off entirely.

 I took this bit of code from `get_id_from_blogname()` which works that
 way. I think it should stay that way since that is how a regular multisite
 network works. You either only use subdomains or subdirectories.
 Everything else is, I'd say, custom and the `slug` way alone cannot
 account for this.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40180#comment:26>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list