Make WordPress Core


Ignore:
Timestamp:
09/24/2018 03:08:32 PM (6 years ago)
Author:
flixos90
Message:

Multisite: Introduce a site initialization and uninitialization API.

This changeset makes the new CRUD API for sites introduced in [43548] usable for real-world sites. A new function wp_initialize_site(), which takes care of creating a site's database tables and populating them with initial values, is hooked into the site insertion process that is initiated when calling wp_insert_site(). Similarly, a new function wp_uninitialize_site(), which takes care of dropping a site's database tables, is hooked into the site deletion process that is initiated when calling wp_delete_site().

A new function wp_is_site_initialized() completes the API, allowing to check whether a site is initialized. Since this function always makes a database request in its default behavior, it should be called with caution. Plugins that would like to use site initialization in special ways can leverage a pre_wp_is_site_initialized filter to alter that default behavior.

The separate handling of the site's row in the wp_blogs database table and the actual site setup allows for more flexibility in controlling whether or how a site's data is set up. For example, a unit test that only checks data from the site's database table row can unhook the site initialization process to improve performance. At the same time, developers consuming the new sites API only need to know about the CRUD functions, since the initialization and uninitialization processes happen internally.

With this changeset, the foundation for a sites REST API endpoint is fully available. The previously recommended functions wpmu_create_blog() and wpmu_delete_blog() now call the new respective function internally. Further follow-up work to this includes replacing calls to wpmu_create_blog() with wp_insert_site(), update_blog_details() with wp_update_site() and wpmu_delete_blog() with wp_delete_blog() throughout the codebase.

As a side-effect of this work, the wpmu_new_blog, delete_blog, and deleted_blog actions and the install_blog() function have been deprecated.

Fixes #41333. See #40364.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ms-default-filters.php

    r43548 r43654  
    3838// Blogs
    3939add_filter( 'wpmu_validate_blog_signup', 'signup_nonce_check' );
    40 add_action( 'wpmu_new_blog', 'wpmu_log_new_registrations', 10, 2 );
    41 add_action( 'wpmu_new_blog', 'newblog_notify_siteadmin', 10, 2 );
    4240add_action( 'wpmu_activate_blog', 'wpmu_welcome_notification', 10, 5 );
    4341add_action( 'after_signup_site', 'wpmu_signup_blog_notification', 10, 7 );
     
    5048add_action( 'wp_update_site', 'wp_maybe_transition_site_statuses_on_update', 10, 2 );
    5149add_action( 'wp_update_site', 'wp_maybe_clean_new_site_cache_on_update', 10, 2 );
     50add_action( 'wp_initialize_site', 'wp_initialize_site', 10, 2 );
     51add_action( 'wp_initialize_site', 'wpmu_log_new_registrations', 100, 2 );
     52add_action( 'wp_initialize_site', 'newblog_notify_siteadmin', 100, 1 );
     53add_action( 'wp_uninitialize_site', 'wp_uninitialize_site', 10, 1 );
    5254add_action( 'update_blog_public', 'wp_update_blog_public_option_on_site_update', 1, 2 );
    5355
Note: See TracChangeset for help on using the changeset viewer.