From 5d478fbe5e158da793d77ae77ac1b58a337e1d5e Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Tue, 28 Jun 2016 21:18: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. Built from https://develop.svn.wordpress.org/trunk@37893 git-svn-id: http://core.svn.wordpress.org/trunk@37834 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/ms-blogs.php | 43 ++++++++++++++++++++++++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/wp-includes/ms-blogs.php b/wp-includes/ms-blogs.php index 90e43d2b6f..de8667bb19 100644 --- a/wp-includes/ms-blogs.php +++ b/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. * diff --git a/wp-includes/version.php b/wp-includes/version.php index fa3498955d..b4ab4511ff 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.6-alpha-37892'; +$wp_version = '4.6-alpha-37893'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.