Make WordPress Core


Ignore:
Timestamp:
08/01/2018 01:05:44 PM (7 years ago)
Author:
flixos90
Message:

Multisite: Complete the new CRUD API for managing sites.

New functions wp_insert_site( $data ), wp_update_site( $id, $data ) and wp_delete_site( $id ) are introduced to manage site rows in the wp_blogs table, forming the new CRUD API together with the existing get_site() / get_sites(). The new API provides various benefits over the previously existing API, fixing several cache invalidation issues and being hook-driven so that normalization and validation of the passed data can be fully customized.

New hooks introduced as part of this are the actions wp_insert_site, wp_update_site, wp_delete_site, wp_validate_site_data and the filter wp_normalize_site_data.

At this point, wp_insert_site() does not handle setting up the site's database tables, and wp_delete_site() does not handle dropping the site's database tables, so the two can not yet be used directly as full replacements of wpmu_create_blog() and wpmu_delete_blog(). Managing the site's database tables will be added via hooks as part of the follow-up ticket #41333.

The existing functions wpmu_create_blog(), update_blog_details(), and wpmu_delete_blog() make use of the respective new counterpart and will be obsolete once #41333 has been completed.

Props flixos90, jeremyfelt, spacedmonkey.
Fixes #40364.

File:
1 edited

Legend:

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

    r41714 r43548  
    547547    return isset( $current_user->$local_key );
    548548}
     549
     550/**
     551 * Store basic site info in the blogs table.
     552 *
     553 * This function creates a row in the wp_blogs table and returns
     554 * the new blog's ID. It is the first step in creating a new blog.
     555 *
     556 * @since MU (3.0.0)
     557 * @deprecated 5.0.0 Use `wp_insert_site()`
     558 * @see wp_insert_site()
     559 *
     560 * @param string $domain  The domain of the new site.
     561 * @param string $path    The path of the new site.
     562 * @param int    $site_id Unless you're running a multi-network install, be sure to set this value to 1.
     563 * @return int|false The ID of the new row
     564 */
     565function insert_blog($domain, $path, $site_id) {
     566    _deprecated_function( __FUNCTION__, '5.0.0', 'wp_insert_site()' );
     567
     568    $data = array(
     569        'domain'  => $domain,
     570        'path'    => $path,
     571        'site_id' => $site_id,
     572    );
     573
     574    $site_id = wp_insert_site( $data );
     575    if ( is_wp_error( $site_id ) ) {
     576        return false;
     577    }
     578
     579    clean_blog_cache( $site_id );
     580
     581    return $site_id;
     582}
Note: See TracChangeset for help on using the changeset viewer.