Changeset 42343 for trunk/src/wp-includes/ms-blogs.php
- Timestamp:
- 11/30/2017 11:09:33 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/ms-blogs.php
r41918 r42343 59 59 function get_blogaddress_by_name( $blogname ) { 60 60 if ( is_subdomain_install() ) { 61 if ( $blogname == 'main' ) 61 if ( $blogname == 'main' ) { 62 62 $blogname = 'www'; 63 } 63 64 $url = rtrim( network_home_url(), '/' ); 64 if ( !empty( $blogname ) ) 65 $url = preg_replace( '|^([^\.]+://)|', "\${1}" . $blogname . '.', $url ); 65 if ( ! empty( $blogname ) ) { 66 $url = preg_replace( '|^([^\.]+://)|', '${1}' . $blogname . '.', $url ); 67 } 66 68 } else { 67 69 $url = network_home_url( $blogname ); … … 81 83 function get_id_from_blogname( $slug ) { 82 84 $current_network = get_network(); 83 $slug = trim( $slug, '/' );85 $slug = trim( $slug, '/' ); 84 86 85 87 if ( is_subdomain_install() ) { 86 88 $domain = $slug . '.' . preg_replace( '|^www\.|', '', $current_network->domain ); 87 $path = $current_network->path;89 $path = $current_network->path; 88 90 } else { 89 91 $domain = $current_network->domain; 90 $path = $current_network->path . $slug . '/'; 91 } 92 93 $site_ids = get_sites( array( 94 'number' => 1, 95 'fields' => 'ids', 96 'domain' => $domain, 97 'path' => $path, 98 ) ); 92 $path = $current_network->path . $slug . '/'; 93 } 94 95 $site_ids = get_sites( 96 array( 97 'number' => 1, 98 'fields' => 'ids', 99 'domain' => $domain, 100 'path' => $path, 101 ) 102 ); 99 103 100 104 if ( empty( $site_ids ) ) { … … 121 125 global $wpdb; 122 126 123 if ( is_array( $fields ) ) {124 if ( isset( $fields['blog_id']) ) {127 if ( is_array( $fields ) ) { 128 if ( isset( $fields['blog_id'] ) ) { 125 129 $blog_id = $fields['blog_id']; 126 } elseif ( isset( $fields['domain']) && isset($fields['path']) ) {127 $key = md5( $fields['domain'] . $fields['path'] );128 $blog = wp_cache_get( $key, 'blog-lookup');129 if ( false !== $blog ) 130 } elseif ( isset( $fields['domain'] ) && isset( $fields['path'] ) ) { 131 $key = md5( $fields['domain'] . $fields['path'] ); 132 $blog = wp_cache_get( $key, 'blog-lookup' ); 133 if ( false !== $blog ) { 130 134 return $blog; 135 } 131 136 if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) { 132 137 $nowww = substr( $fields['domain'], 4 ); 133 $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'] ) );138 $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'] ) ); 134 139 } else { 135 140 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) ); 136 141 } 137 142 if ( $blog ) { 138 wp_cache_set( $blog->blog_id . 'short', $blog, 'blog-details');143 wp_cache_set( $blog->blog_id . 'short', $blog, 'blog-details' ); 139 144 $blog_id = $blog->blog_id; 140 145 } else { 141 146 return false; 142 147 } 143 } elseif ( isset( $fields['domain']) && is_subdomain_install() ) {144 $key = md5( $fields['domain'] );145 $blog = wp_cache_get( $key, 'blog-lookup');146 if ( false !== $blog ) 148 } elseif ( isset( $fields['domain'] ) && is_subdomain_install() ) { 149 $key = md5( $fields['domain'] ); 150 $blog = wp_cache_get( $key, 'blog-lookup' ); 151 if ( false !== $blog ) { 147 152 return $blog; 153 } 148 154 if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) { 149 155 $nowww = substr( $fields['domain'], 4 ); 150 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) );156 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) ); 151 157 } else { 152 158 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'] ) ); 153 159 } 154 160 if ( $blog ) { 155 wp_cache_set( $blog->blog_id . 'short', $blog, 'blog-details');161 wp_cache_set( $blog->blog_id . 'short', $blog, 'blog-details' ); 156 162 $blog_id = $blog->blog_id; 157 163 } else { … … 162 168 } 163 169 } else { 164 if ( ! $fields ) 170 if ( ! $fields ) { 165 171 $blog_id = get_current_blog_id(); 166 elseif ( ! is_numeric( $fields ) )172 } elseif ( ! is_numeric( $fields ) ) { 167 173 $blog_id = get_id_from_blogname( $fields ); 168 else174 } else { 169 175 $blog_id = $fields; 176 } 170 177 } 171 178 172 179 $blog_id = (int) $blog_id; 173 180 174 $all = $get_all == true ? '' : 'short';181 $all = $get_all == true ? '' : 'short'; 175 182 $details = wp_cache_get( $blog_id . $all, 'blog-details' ); 176 183 … … 182 189 // Clear old pre-serialized objects. Cache clients do better with that. 183 190 wp_cache_delete( $blog_id . $all, 'blog-details' ); 184 unset( $details);191 unset( $details ); 185 192 } 186 193 } else { … … 202 209 // Clear old pre-serialized objects. Cache clients do better with that. 203 210 wp_cache_delete( $blog_id, 'blog-details' ); 204 unset( $details);211 unset( $details ); 205 212 } 206 213 } else { … … 210 217 } 211 218 212 if ( empty( $details) ) {219 if ( empty( $details ) ) { 213 220 $details = WP_Site::get_instance( $blog_id ); 214 221 if ( ! $details ) { … … 283 290 global $wpdb; 284 291 285 if ( empty( $details) )292 if ( empty( $details ) ) { 286 293 return false; 287 288 if ( is_object($details) ) 289 $details = get_object_vars($details); 294 } 295 296 if ( is_object( $details ) ) { 297 $details = get_object_vars( $details ); 298 } 290 299 291 300 $current_details = get_site( $blog_id ); 292 if ( empty( $current_details) )301 if ( empty( $current_details ) ) { 293 302 return false; 294 295 $current_details = get_object_vars($current_details); 296 297 $details = array_merge($current_details, $details); 298 $details['last_updated'] = current_time('mysql', true); 303 } 304 305 $current_details = get_object_vars( $current_details ); 306 307 $details = array_merge( $current_details, $details ); 308 $details['last_updated'] = current_time( 'mysql', true ); 299 309 300 310 $update_details = array(); 301 $fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id');311 $fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ); 302 312 foreach ( array_intersect( array_keys( $details ), $fields ) as $field ) { 303 313 if ( 'path' === $field ) { … … 308 318 } 309 319 310 $result = $wpdb->update( $wpdb->blogs, $update_details, array( 'blog_id' => $blog_id) );311 312 if ( false === $result ) 320 $result = $wpdb->update( $wpdb->blogs, $update_details, array( 'blog_id' => $blog_id ) ); 321 322 if ( false === $result ) { 313 323 return false; 324 } 314 325 315 326 // If spam status changed, issue actions. … … 437 448 438 449 $blog_id = $blog; 439 $blog = get_site( $blog_id );450 $blog = get_site( $blog_id ); 440 451 if ( ! $blog ) { 441 452 if ( ! is_numeric( $blog_id ) ) { … … 444 455 445 456 // Make sure a WP_Site object exists even when the site has been deleted. 446 $blog = new WP_Site( (object) array( 447 'blog_id' => $blog_id, 448 'domain' => null, 449 'path' => null, 450 ) ); 451 } 452 453 $blog_id = $blog->blog_id; 457 $blog = new WP_Site( 458 (object) array( 459 'blog_id' => $blog_id, 460 'domain' => null, 461 'path' => null, 462 ) 463 ); 464 } 465 466 $blog_id = $blog->blog_id; 454 467 $domain_path_key = md5( $blog->domain . $blog->path ); 455 468 … … 457 470 wp_cache_delete( $blog_id, 'site-details' ); 458 471 wp_cache_delete( $blog_id, 'blog-details' ); 459 wp_cache_delete( $blog_id . 'short' 472 wp_cache_delete( $blog_id . 'short', 'blog-details' ); 460 473 wp_cache_delete( $domain_path_key, 'blog-lookup' ); 461 474 wp_cache_delete( $domain_path_key, 'blog-id-cache' ); … … 560 573 $non_cached_ids = _get_non_cached_ids( $ids, 'sites' ); 561 574 if ( ! empty( $non_cached_ids ) ) { 562 $fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) );575 $fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join( ',', array_map( 'intval', $non_cached_ids ) ) ) ); 563 576 564 577 update_site_cache( $fresh_sites ); … … 666 679 $id = (int) $id; 667 680 668 if ( empty( $id ) ) 681 if ( empty( $id ) ) { 669 682 $id = get_current_blog_id(); 670 671 if ( get_current_blog_id() == $id ) 683 } 684 685 if ( get_current_blog_id() == $id ) { 672 686 return get_option( $option, $default ); 687 } 673 688 674 689 switch_to_blog( $id ); … … 711 726 $id = (int) $id; 712 727 713 if ( empty( $id ) ) 728 if ( empty( $id ) ) { 714 729 $id = get_current_blog_id(); 715 716 if ( get_current_blog_id() == $id ) 730 } 731 732 if ( get_current_blog_id() == $id ) { 717 733 return add_option( $option, $value ); 734 } 718 735 719 736 switch_to_blog( $id ); … … 736 753 $id = (int) $id; 737 754 738 if ( empty( $id ) ) 755 if ( empty( $id ) ) { 739 756 $id = get_current_blog_id(); 740 741 if ( get_current_blog_id() == $id ) 757 } 758 759 if ( get_current_blog_id() == $id ) { 742 760 return delete_option( $option ); 761 } 743 762 744 763 switch_to_blog( $id ); … … 763 782 $id = (int) $id; 764 783 765 if ( null !== $deprecated )784 if ( null !== $deprecated ) { 766 785 _deprecated_argument( __FUNCTION__, '3.1.0' ); 767 768 if ( get_current_blog_id() == $id ) 786 } 787 788 if ( get_current_blog_id() == $id ) { 769 789 return update_option( $option, $value ); 790 } 770 791 771 792 switch_to_blog( $id ); … … 830 851 $wpdb->set_blog_id( $new_blog ); 831 852 $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix(); 832 $prev_blog_id = $blog_id;833 $GLOBALS['blog_id'] = $new_blog;853 $prev_blog_id = $blog_id; 854 $GLOBALS['blog_id'] = $new_blog; 834 855 835 856 if ( function_exists( 'wp_cache_switch_to_blog' ) ) { … … 884 905 } 885 906 886 $blog = array_pop( $GLOBALS['_wp_switched_stack'] );907 $blog = array_pop( $GLOBALS['_wp_switched_stack'] ); 887 908 $blog_id = get_current_blog_id(); 888 909 … … 896 917 897 918 $wpdb->set_blog_id( $blog ); 898 $prev_blog_id = $blog_id;899 $GLOBALS['blog_id'] = $blog;919 $prev_blog_id = $blog_id; 920 $GLOBALS['blog_id'] = $blog; 900 921 $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix(); 901 922 … … 975 996 */ 976 997 function is_archived( $id ) { 977 return get_blog_status( $id, 'archived');998 return get_blog_status( $id, 'archived' ); 978 999 } 979 1000 … … 988 1009 */ 989 1010 function update_archived( $id, $archived ) { 990 update_blog_status( $id, 'archived', $archived);1011 update_blog_status( $id, 'archived', $archived ); 991 1012 return $archived; 992 1013 } … … 1008 1029 global $wpdb; 1009 1030 1010 if ( null !== $deprecated )1031 if ( null !== $deprecated ) { 1011 1032 _deprecated_argument( __FUNCTION__, '3.1.0' ); 1012 1013 if ( ! in_array( $pref, array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id') ) ) 1033 } 1034 1035 if ( ! in_array( $pref, array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ) ) ) { 1014 1036 return $value; 1015 1016 $result = $wpdb->update( $wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id) ); 1017 1018 if ( false === $result ) 1037 } 1038 1039 $result = $wpdb->update( 1040 $wpdb->blogs, array( 1041 $pref => $value, 1042 'last_updated' => current_time( 'mysql', true ), 1043 ), array( 'blog_id' => $blog_id ) 1044 ); 1045 1046 if ( false === $result ) { 1019 1047 return false; 1048 } 1020 1049 1021 1050 clean_blog_cache( $blog_id ); … … 1061 1090 * @param int $blog_id Blog ID. 1062 1091 * @param string $value The value of blog status. 1063 1092 */ 1064 1093 do_action( 'update_blog_public', $blog_id, $value ); // Moved here from update_blog_public(). 1065 1094 } … … 1083 1112 1084 1113 $details = get_site( $id ); 1085 if ( $details ) 1114 if ( $details ) { 1086 1115 return $details->$pref; 1087 1088 return $wpdb->get_var( $wpdb->prepare("SELECT %s FROM {$wpdb->blogs} WHERE blog_id = %d", $pref, $id) ); 1116 } 1117 1118 return $wpdb->get_var( $wpdb->prepare( "SELECT %s FROM {$wpdb->blogs} WHERE blog_id = %d", $pref, $id ) ); 1089 1119 } 1090 1120 … … 1104 1134 global $wpdb; 1105 1135 1106 if ( ! empty( $deprecated ) ) 1136 if ( ! empty( $deprecated ) ) { 1107 1137 _deprecated_argument( __FUNCTION__, 'MU' ); // never used 1138 } 1108 1139 1109 1140 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", get_current_network_id(), $start, $quantity ), ARRAY_A ); … … 1233 1264 1234 1265 $non_cached_ids = _get_non_cached_ids( $network_ids, 'networks' ); 1235 if ( ! empty( $non_cached_ids ) ) {1236 $fresh_networks = $wpdb->get_results( sprintf( "SELECT $wpdb->site.* FROM $wpdb->site WHERE id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) );1266 if ( ! empty( $non_cached_ids ) ) { 1267 $fresh_networks = $wpdb->get_results( sprintf( "SELECT $wpdb->site.* FROM $wpdb->site WHERE id IN (%s)", join( ',', array_map( 'intval', $non_cached_ids ) ) ) ); 1237 1268 1238 1269 update_network_cache( $fresh_networks );
Note: See TracChangeset
for help on using the changeset viewer.