[wp-trac] [WordPress Trac] #40064: Deprecate `get_blog_details()`

WordPress Trac noreply at wordpress.org
Thu Mar 9 03:09:52 UTC 2017


#40064: Deprecate `get_blog_details()`
--------------------------------+------------------------
 Reporter:  flixos90            |       Owner:
     Type:  enhancement         |      Status:  new
 Priority:  normal              |   Milestone:  4.8
Component:  Networks and Sites  |     Version:
 Severity:  normal              |  Resolution:
 Keywords:                      |     Focuses:  multisite
--------------------------------+------------------------

Comment (by spacedmonkey):

 Here is what a get_blog_details function would look like using get_sites.

 {{{#!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'];
                 }

         } else {
                 if ( ! $fields ){
                         $args['site__in'][] = get_current_blog_id();
                 } elseif ( ! is_numeric( $fields ) ){
                         $args['site__in'][] = get_id_from_blogname(
 $fields );
                 } else {
                         $args['site__in'][] = $fields;
                 }
         }

         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;
 }
 }}}

 This makes for much clearer code.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40064#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list