WordPress.org

Make WordPress Core

Opened 3 months ago

Last modified 3 weeks ago

#40364 new enhancement

Improve site creation in multisite

Reported by: jeremyfelt Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Networks and Sites Keywords: dev-feedback needs-unit-tests has-patch needs-testing
Focuses: multisite Cc:

Description

wpmu_create_blog() is responsible for a lot. It uses insert_blog(), install_blog(), wp_install_defaults() and many other things to accomplish the task of creating a site.

We should go through this process and determine what kind of improvements can be made as part of wpmu_create_blog() or in a new wp_create_site()/wp_insert_site() function that is more in tune with the objectives of site creation through the REST API. See #40365.

Attachments (1)

40364.diff (12.3 KB) - added by flixos90 8 weeks ago.

Download all attachments as: .zip

Change History (11)

This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.


3 months ago

This ticket was mentioned in Slack in #core-multisite by flixos90. View the logs.


3 months ago

This ticket was mentioned in Slack in #core-multisite by flixos90. View the logs.


8 weeks ago

This ticket was mentioned in Slack in #core-multisite by flixos90. View the logs.


8 weeks ago

This ticket was mentioned in Slack in #core-multisite by flixos90. View the logs.


8 weeks ago

@flixos90
8 weeks ago

#6 @flixos90
8 weeks ago

  • Keywords has-patch needs-testing added; needs-patch removed

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.

This ticket was mentioned in Slack in #core-restapi by flixos90. View the logs.


8 weeks ago

This ticket was mentioned in Slack in #core-multisite by flixos90. View the logs.


4 weeks ago

This ticket was mentioned in Slack in #core-multisite by flixos90. View the logs.


4 weeks ago

This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.


3 weeks ago

Note: See TracTickets for help on using tickets.