WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/13/2015 11:30:57 PM (6 years ago)
Author:
jeremyfelt
Message:

Multisite: Introduce the WP_Network class.

A WP_Network object initially matches a row from wp_site and is populated with additional properties used by WordPress core. The first iteration is used to retrieve an existing network based on data passed to the class.

  • A network can be retrieved by its ID through WP_Network::get_instance(), following in the steps of WP_Post and WP_Comment.
  • A network object can be created or completed by passing initial properties in as a standard object to new WP_Network().

Using these methods, we are now able to populate the global $current_site during load via this class.

Props johnjamesjacoby, jeremyfelt, drewapicture, wonderboymusic.
See #31985.

File:
1 edited

Legend:

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

    r33999 r34097  
    259259 *
    260260 * @since 3.9.0
    261  *
    262  * @global wpdb $wpdb
     261 * @since 4.4.0 Converted to leverage WP_Network
    263262 *
    264263 * @param object|int $network The network's database row or ID.
    265  * @return object|false Object containing network information if found, false if not.
     264 * @return WP_Network|false Object containing network information if found, false if not.
    266265 */
    267266function wp_get_network( $network ) {
    268     global $wpdb;
    269 
    270267    if ( ! is_object( $network ) ) {
    271         $network = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->site WHERE id = %d", $network ) );
    272         if ( ! $network ) {
    273             return false;
    274         }
     268        $network = WP_Network::get_instance( $network );
     269    } else {
     270        $network = new WP_Network( $network );
    275271    }
    276272
Note: See TracChangeset for help on using the changeset viewer.