[wp-trac] [WordPress Trac] #40228: Use get_sites in get_blog_details
WordPress Trac
noreply at wordpress.org
Thu Mar 23 04:28:12 UTC 2017
#40228: Use get_sites in get_blog_details
--------------------------------+------------------------------
Reporter: spacedmonkey | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Networks and Sites | Version: 3.0
Severity: normal | Resolution:
Keywords: | Focuses: multisite
--------------------------------+------------------------------
Comment (by spacedmonkey):
Here is what a get_blog_details function would look like using get_sites.
It basically creates different args and passes it to get_sites and returns
1 site.
{{{#!php
function get_blog_details( $fields = null, $get_all = true ) {
$args = array();
if ( is_array( $fields ) ) {
if ( isset($fields['blog_id']) ) {
$args['site__in'][] = $fields['blog_id'];
}
if ( isset($fields['domain']) ){
$domains = array( $fields['domain'] );
if ( substr( $fields['domain'], 0, 4 ) == 'www.' )
{
$nowww = substr( $fields['domain'], 4 );
$domains[] = $nowww;
}
$args['domain__in'] = $domains;
}
if( isset($fields['path']) ) {
$args['path'] = $fields['path'];
}
} elseif ( is_numeric( $fields ) ){
$args['site__in'][] = $fields;
} elseif ( $fields && is_string( $fields ) ) {
$current_network = get_network();
$slug = trim( $fields, '/' );
if ( is_subdomain_install() ) {
$domain = $slug . '.' . preg_replace( '|^www\.|',
'', $current_network->domain );
$path = $current_network->path;
} else {
$domain = $current_network->domain;
$path = $current_network->path . $slug . '/';
}
$args['path'] = $path;
$args['domain'] = $domain;
} else {
$args['site__in'][] = get_current_blog_id();
}
if( empty( $args ) ){
return false;
}
$args['number'] = 1;
$sites = get_sites( $args );
if( empty( $sites ) ){
return false;
}
$details = array_shift( $sites );
$blog_id = $details->blog_id;
if ( $get_all ) {
switch_to_blog( $blog_id );
$details->blogname = get_option( 'blogname' );
$details->siteurl = get_option( 'siteurl' );
$details->post_count = get_option( 'post_count' );
$details->home = get_option( 'home' );
restore_current_blog();
/**
* Filters a blog's details.
*
* @since MU
* @deprecated 4.7.0 Use site_details
*
* @param object $details The blog details.
*/
$details = apply_filters_deprecated( 'blog_details', array(
$details ), '4.7.0', 'site_details' );
}
return $details;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/40228#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list