Make WordPress Core

Changeset 37893


Ignore:
Timestamp:
06/28/2016 09:17:30 PM (8 years ago)
Author:
jeremyfelt
Message:

Multisite: Introduce get_network().

Given a network ID or network object, get_network() retrieves network data in the same vein as get_site() or get_post(). This will allow for clean retrieval of networks from a primed cache when WP_Network_Query is implemented.

Props flixos90.
See #32504.

File:
1 edited

Legend:

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

    r37874 r37893  
    10731073
    10741074/**
     1075 * Retrieves network data given a network ID or network object.
     1076 *
     1077 * Network data will be cached and returned after being passed through a filter.
     1078 * If the provided network is empty, the current network global will be used.
     1079 *
     1080 * @since 4.6.0
     1081 *
     1082 * @global WP_Network $current_site
     1083 *
     1084 * @param WP_Network|int|null $network Network to retrieve.
     1085 * @return WP_Network|null The network object or null if not found.
     1086 */
     1087function get_network( &$network = null ) {
     1088    global $current_site;
     1089    if ( empty( $network ) && isset( $current_site ) ) {
     1090        $network = $current_site;
     1091    }
     1092
     1093    if ( $network instanceof WP_Network ) {
     1094        $_network = $network;
     1095    } elseif ( is_object( $network ) ) {
     1096        $_network = new WP_Network( $network );
     1097    } else {
     1098        $_network = WP_Network::get_instance( $network );
     1099    }
     1100
     1101    if ( ! $_network ) {
     1102        return null;
     1103    }
     1104
     1105    /**
     1106     * Fires after a network is retrieved.
     1107     *
     1108     * @since 4.6.0
     1109     *
     1110     * @param WP_Network $_network Network data.
     1111     */
     1112    $_network = apply_filters( 'get_network', $_network );
     1113
     1114    return $_network;
     1115}
     1116
     1117/**
    10751118 * Handler for updating the blog date when a post is published or an already published post is changed.
    10761119 *
Note: See TracChangeset for help on using the changeset viewer.