From 7de7b36b9fd8e85b7b47be00c12c153a9802f86e Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Tue, 28 Jun 2016 21:17:30 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@37893 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/ms-blogs.php | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/wp-includes/ms-blogs.php b/src/wp-includes/ms-blogs.php index 90e43d2b6f..de8667bb19 100644 --- a/src/wp-includes/ms-blogs.php +++ b/src/wp-includes/ms-blogs.php @@ -1071,6 +1071,49 @@ function get_last_updated( $deprecated = '', $start = 0, $quantity = 40 ) { return $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00' ORDER BY last_updated DESC limit %d, %d", $wpdb->siteid, $start, $quantity ) , ARRAY_A ); } +/** + * Retrieves network data given a network ID or network object. + * + * Network data will be cached and returned after being passed through a filter. + * If the provided network is empty, the current network global will be used. + * + * @since 4.6.0 + * + * @global WP_Network $current_site + * + * @param WP_Network|int|null $network Network to retrieve. + * @return WP_Network|null The network object or null if not found. + */ +function get_network( &$network = null ) { + global $current_site; + if ( empty( $network ) && isset( $current_site ) ) { + $network = $current_site; + } + + if ( $network instanceof WP_Network ) { + $_network = $network; + } elseif ( is_object( $network ) ) { + $_network = new WP_Network( $network ); + } else { + $_network = WP_Network::get_instance( $network ); + } + + if ( ! $_network ) { + return null; + } + + /** + * Fires after a network is retrieved. + * + * @since 4.6.0 + * + * @param WP_Network $_network Network data. + */ + $_network = apply_filters( 'get_network', $_network ); + + return $_network; +} + /** * Handler for updating the blog date when a post is published or an already published post is changed. *