Changeset 41883 for trunk/src/wp-includes/ms-blogs.php
- Timestamp:
- 10/16/2017 10:28:52 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/ms-blogs.php
r41795 r41883 94 94 * 95 95 * @since MU (3.0.0) 96 * @since 4.9.0 Use get_site_by() internally. 96 * 97 * @global wpdb $wpdb WordPress database abstraction object. 97 98 * 98 99 * @param int|string|array $fields Optional. A blog ID, a blog slug, or an array of fields to query against. … … 103 104 */ 104 105 function get_blog_details( $fields = null, $get_all = true ) { 105 if ( is_array( $fields ) ) { 106 if ( isset( $fields['blog_id'] ) ) { 107 $field = 'id'; 108 $value = (int) $fields['blog_id']; 109 } elseif ( isset( $fields['domain'] ) && isset( $fields['path'] ) ) { 110 $field = 'url'; 111 $value = $fields['domain'] . '/' . ltrim( $fields['path'], '/' ); 112 } elseif ( isset( $fields['domain'] ) && is_subdomain_install() ) { 113 $field = 'domain'; 114 $value = $fields['domain']; 106 global $wpdb; 107 108 if ( is_array($fields ) ) { 109 if ( isset($fields['blog_id']) ) { 110 $blog_id = $fields['blog_id']; 111 } elseif ( isset($fields['domain']) && isset($fields['path']) ) { 112 $key = md5( $fields['domain'] . $fields['path'] ); 113 $blog = wp_cache_get($key, 'blog-lookup'); 114 if ( false !== $blog ) 115 return $blog; 116 if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) { 117 $nowww = substr( $fields['domain'], 4 ); 118 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) ); 119 } else { 120 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) ); 121 } 122 if ( $blog ) { 123 wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details'); 124 $blog_id = $blog->blog_id; 125 } else { 126 return false; 127 } 128 } elseif ( isset($fields['domain']) && is_subdomain_install() ) { 129 $key = md5( $fields['domain'] ); 130 $blog = wp_cache_get($key, 'blog-lookup'); 131 if ( false !== $blog ) 132 return $blog; 133 if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) { 134 $nowww = substr( $fields['domain'], 4 ); 135 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) ); 136 } else { 137 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'] ) ); 138 } 139 if ( $blog ) { 140 wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details'); 141 $blog_id = $blog->blog_id; 142 } else { 143 return false; 144 } 115 145 } else { 116 146 return false; 117 147 } 118 148 } else { 119 if ( ! $fields ) { 120 $field = 'id'; 121 $value = get_current_blog_id(); 122 } elseif ( ! is_numeric( $fields ) ) { 123 $field = 'slug'; 124 $value = $fields; 149 if ( ! $fields ) 150 $blog_id = get_current_blog_id(); 151 elseif ( ! is_numeric( $fields ) ) 152 $blog_id = get_id_from_blogname( $fields ); 153 else 154 $blog_id = $fields; 155 } 156 157 $blog_id = (int) $blog_id; 158 159 $all = $get_all == true ? '' : 'short'; 160 $details = wp_cache_get( $blog_id . $all, 'blog-details' ); 161 162 if ( $details ) { 163 if ( ! is_object( $details ) ) { 164 if ( $details == -1 ) { 165 return false; 166 } else { 167 // Clear old pre-serialized objects. Cache clients do better with that. 168 wp_cache_delete( $blog_id . $all, 'blog-details' ); 169 unset($details); 170 } 125 171 } else { 126 $field = 'id'; 127 $value = (int) $fields; 128 } 129 } 130 131 $site = get_site_by( $field, $value ); 132 133 if ( ! $site ) { 134 return false; 135 } 136 172 return $details; 173 } 174 } 175 176 // Try the other cache. 137 177 if ( $get_all ) { 138 // Prepopulate magic properties for backward compatibility. 139 foreach ( array( 'blogname', 'siteurl', 'post_count', 'home' ) as $detail ) { 140 $site->$detail = $site->$detail; 141 } 142 } 143 144 return $site; 178 $details = wp_cache_get( $blog_id . 'short', 'blog-details' ); 179 } else { 180 $details = wp_cache_get( $blog_id, 'blog-details' ); 181 // If short was requested and full cache is set, we can return. 182 if ( $details ) { 183 if ( ! is_object( $details ) ) { 184 if ( $details == -1 ) { 185 return false; 186 } else { 187 // Clear old pre-serialized objects. Cache clients do better with that. 188 wp_cache_delete( $blog_id, 'blog-details' ); 189 unset($details); 190 } 191 } else { 192 return $details; 193 } 194 } 195 } 196 197 if ( empty($details) ) { 198 $details = WP_Site::get_instance( $blog_id ); 199 if ( ! $details ) { 200 // Set the full cache. 201 wp_cache_set( $blog_id, -1, 'blog-details' ); 202 return false; 203 } 204 } 205 206 if ( ! $details instanceof WP_Site ) { 207 $details = new WP_Site( $details ); 208 } 209 210 if ( ! $get_all ) { 211 wp_cache_set( $blog_id . $all, $details, 'blog-details' ); 212 return $details; 213 } 214 215 switch_to_blog( $blog_id ); 216 $details->blogname = get_option( 'blogname' ); 217 $details->siteurl = get_option( 'siteurl' ); 218 $details->post_count = get_option( 'post_count' ); 219 $details->home = get_option( 'home' ); 220 restore_current_blog(); 221 222 /** 223 * Filters a blog's details. 224 * 225 * @since MU (3.0.0) 226 * @deprecated 4.7.0 Use site_details 227 * 228 * @param object $details The blog details. 229 */ 230 $details = apply_filters_deprecated( 'blog_details', array( $details ), '4.7.0', 'site_details' ); 231 232 wp_cache_set( $blog_id . $all, $details, 'blog-details' ); 233 234 $key = md5( $details->domain . $details->path ); 235 wp_cache_set( $key, $details, 'blog-lookup' ); 236 237 return $details; 145 238 } 146 239
Note: See TracChangeset
for help on using the changeset viewer.