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

WordPress Trac noreply at wordpress.org
Sun Oct 1 02:59:40 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 jeremyfelt):

 Replying to [comment:26 flixos90]:
 > 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).

 Ok, that make sense. After poking around a bit more, I'm on the same page.

 > > 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.

 Agreed. I did try setting a path before installing multisite and was
 reminded that you can't install in subdomain mode when that's the case, so
 if `get_id_from_blogname()` is doing it that way, then it may be useful
 for somebody and we should probably just let it be. :)

 I tweaked the tests in [attachment:40180.5.diff]:

 * Removed the assertions that the returns were `WP_Site` objects. We
 should be asserting one thing per test, and if it's not returning the
 object, then other things are going to fail.
 * Added 2 explicit tests for retrieving a site by slug on specific
 networks. I see that the other tests use different networks, but I think
 having the explicit behavior tested is good.

 The tests for `get_site_by( 'id' ...)` gave me pause. I definitely don't
 think we need to account for somebody passing `null` as the ID value when
 they can just use `get_site()`. I think that test can be removed.

 As for `id` itself, are we doing this just for parity with other
 functions? I can't imagine this being more useful than `get_site( $id )`.

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


More information about the wp-trac mailing list