[wp-trac] [WordPress Trac] #40228: Use get_sites in get_blog_details

WordPress Trac noreply at wordpress.org
Thu Mar 23 23:25:29 UTC 2017


#40228: Use get_sites in get_blog_details
-------------------------------------------------+-------------------------
 Reporter:  spacedmonkey                         |       Owner:  flixos90
     Type:  enhancement                          |      Status:  assigned
 Priority:  normal                               |   Milestone:  4.8
Component:  Networks and Sites                   |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests dev-        |     Focuses:  multisite
  feedback                                       |
-------------------------------------------------+-------------------------
Changes (by flixos90):

 * keywords:   => has-patch has-unit-tests dev-feedback
 * version:  3.0 =>
 * milestone:  Awaiting Review => 4.8


Comment:

 [attachment:40228.diff] shows a possible implementation of
 `get_blog_details()` using `get_site_by()` (see #40180). Since the patch
 relies on that function, it is required that you apply the patch on #40180
 as well in order to test.

 All regular `get_blog_details()` tests pass after the change, however I
 had to adjust / partly remove some tests related to the `blog-details` and
 `blog-lookup` caches, since these now don't exist any longer. There are
 two tests related to the `site-details` cache, however that is due to a
 bug in setting that cache, for which I'll open a ticket shortly.

 The code in `get_blog_details()` has obviously been drastically reduced,
 and by using `get_site_by()` the patch fulfills the original requirement
 of using the more efficient `get_sites()` / `get_site()` functions.
 Admittedly there is one ''really weird'' line in the new code
 (`$site->detail = $site->detail;`), but it actually does what it is
 supposed to do (PHP magic method weirdness) - however this code is one of
 the reasons that I think we should recommend using `get_site_by()` over
 `get_blog_details()` going forward (see more below).

 I think this approach makes more sense than refactoring
 `get_blog_details()` itself. `get_site_by()` is more explicit in its usage
 and does not explicitly set the "site details" on the object (which is a
 bad practice since they're now lazy-loaded, but we have to keep it in
 `get_blog_details()` for BC. We could use `get_site_by()` in other core
 functions, like `get_id_from_blogname()` for example. These are some of
 the reasons why I think `get_site_by()` is viable to have in core although
 it serves a rather similar use-case like `get_blog_details()`. Let's not
 deprecate `get_blog_details()`, but let's provide a better alternative for
 new development going forward.

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


More information about the wp-trac mailing list