[wp-trac] [WordPress Trac] #40364: Improve site creation in multisite

WordPress Trac noreply at wordpress.org
Tue May 2 19:46:34 UTC 2017


#40364: Improve site creation in multisite
-------------------------------------------------+-------------------------
 Reporter:  jeremyfelt                           |       Owner:
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
Component:  Networks and Sites                   |  Review
 Severity:  normal                               |     Version:
 Keywords:  dev-feedback needs-unit-tests has-   |  Resolution:
  patch needs-testing                            |     Focuses:  multisite
-------------------------------------------------+-------------------------
Changes (by flixos90):

 * keywords:  needs-patch dev-feedback needs-unit-tests => dev-feedback
     needs-unit-tests has-patch needs-testing


Comment:

 [attachment:40364.diff] introduces new functions `wp_insert_site()`,
 `wp_update_site()` and `wp_delete_site()` (in `ms-blogs.php`). As briefly
 discussed in today's office-hours, the functions follow a more modern
 approach parameter-wise, as all of them accept a `WP_Site` object and
 return a `WP_Site` object as well (or `WP_Error` on failure):

 * `wp_insert_site( $site )` accepts a `WP_Site` which must not have the
 `$id` property set. After having inserted the new site, it sets the `$id`
 property and returns the modified object (or `WP_Error` on failure).
 * `wp_update_site( $site )` accepts a `WP_Site` which must have the `$id`
 property set. After having updated the site, it returns the object (or
 `WP_Error` on failure).
 * `wp_delete_site( $site )` accepts a `WP_Site` which must have the `$id`
 property set. After having deleted the site, it sets the `$id` property to
 0 and returns the modified object (or `WP_Error` on failure).

 Passing objects around has several advantages:
 * The properties are already defined, so we don't need as much of complex
 default logic that we'd have otherwise.
 * It's straightforward. Instantiate a new site object, set properties and
 pass it to `wp_insert_site()`.
 * You can work with the same object instance, less unnecessary object
 instantiations from redundant `get_site()` calls.
 * Passing objects around also opens up possibilities for more flexible
 filters as the objects contain much more information than just an ID. A
 good example is that we can now immediately pass the object to
 `clean_blog_cache()` without some weird logic such as the one in
 `refresh_blog_details()`.

 In addition to the above three functions, a new function is introduced for
 running the status transition hooks (previously located in
 `update_blog_details()`). This functionality is now part of
 `wp_update_site()`, but it should be outsourced to limit complexity of
 that function.

 Furthermore the patch uses the three new functions: `insert_blog()` now
 wraps `wp_insert_site()`, `update_blog_details()` now wraps
 `wp_update_site()` and `wpmu_delete_blog()` calls `wp_delete_site()`
 internally.

 This patch of course needs thorough review and testing (I haven't tested
 it at all tbh, will do that soon). Things to consider in particular:

 * Is the approach clear enough / flexible / stable enough?
 * Since objects are passed by reference, the input objects are directly
 modified. Is that acceptable, or should we clone them in all of the three
 functions to require the caller to use the returned object?
 * There are some `//TODO` annotations in the patch with further things to
 think about.

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


More information about the wp-trac mailing list