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
This commit is contained in:
Jeremy Felt 2016-06-28 21:17:30 +00:00
parent 41b39bae16
commit 7de7b36b9f
1 changed files with 43 additions and 0 deletions

View File

@ -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 ); 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. * Handler for updating the blog date when a post is published or an already published post is changed.
* *