Multisite: Replace `$wpdb->blog` queries in `ms-functions.php` with `get_sites()`
`get_sites()` is now used in: * `domain_exists()` * `wp_update_network_site_counts()` * `get_blog_id_from_url()` Props spacedmonkey, jeremyfelt. See #35791. git-svn-id: https://develop.svn.wordpress.org/trunk@37620 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
3afb9f4839
commit
21fa6e2e9b
|
@ -296,6 +296,7 @@ function get_blog_permalink( $blog_id, $post_id ) {
|
||||||
* $domain is 'blog1.example.com' and $path is '/'.
|
* $domain is 'blog1.example.com' and $path is '/'.
|
||||||
*
|
*
|
||||||
* @since MU 2.6.5
|
* @since MU 2.6.5
|
||||||
|
* @since 4.6.0 Converted to use get_sites()
|
||||||
*
|
*
|
||||||
* @global wpdb $wpdb WordPress database abstraction object.
|
* @global wpdb $wpdb WordPress database abstraction object.
|
||||||
*
|
*
|
||||||
|
@ -304,8 +305,6 @@ function get_blog_permalink( $blog_id, $post_id ) {
|
||||||
* @return int 0 if no blog found, otherwise the ID of the matching blog
|
* @return int 0 if no blog found, otherwise the ID of the matching blog
|
||||||
*/
|
*/
|
||||||
function get_blog_id_from_url( $domain, $path = '/' ) {
|
function get_blog_id_from_url( $domain, $path = '/' ) {
|
||||||
global $wpdb;
|
|
||||||
|
|
||||||
$domain = strtolower( $domain );
|
$domain = strtolower( $domain );
|
||||||
$path = strtolower( $path );
|
$path = strtolower( $path );
|
||||||
$id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' );
|
$id = wp_cache_get( md5( $domain . $path ), 'blog-id-cache' );
|
||||||
|
@ -315,7 +314,13 @@ function get_blog_id_from_url( $domain, $path = '/' ) {
|
||||||
elseif ( $id )
|
elseif ( $id )
|
||||||
return (int) $id;
|
return (int) $id;
|
||||||
|
|
||||||
$id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s and path = %s /* get_blog_id_from_url */", $domain, $path ) );
|
$args = array(
|
||||||
|
'domain' => $domain,
|
||||||
|
'path' => $path,
|
||||||
|
'fields' => 'ids',
|
||||||
|
);
|
||||||
|
$result = get_sites( $args );
|
||||||
|
$id = array_shift( $result );
|
||||||
|
|
||||||
if ( ! $id ) {
|
if ( ! $id ) {
|
||||||
wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' );
|
wp_cache_set( md5( $domain . $path ), -1, 'blog-id-cache' );
|
||||||
|
@ -1247,6 +1252,7 @@ Disable these notifications: %3$s'), $user->user_login, wp_unslash( $_SERVER['RE
|
||||||
* that each blogname is unique.
|
* that each blogname is unique.
|
||||||
*
|
*
|
||||||
* @since MU
|
* @since MU
|
||||||
|
* @since 4.6.0 Converted to use get_sites()
|
||||||
*
|
*
|
||||||
* @global wpdb $wpdb WordPress database abstraction object.
|
* @global wpdb $wpdb WordPress database abstraction object.
|
||||||
*
|
*
|
||||||
|
@ -1256,9 +1262,15 @@ Disable these notifications: %3$s'), $user->user_login, wp_unslash( $_SERVER['RE
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
function domain_exists($domain, $path, $site_id = 1) {
|
function domain_exists($domain, $path, $site_id = 1) {
|
||||||
global $wpdb;
|
|
||||||
$path = trailingslashit( $path );
|
$path = trailingslashit( $path );
|
||||||
$result = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s AND site_id = %d", $domain, $path, $site_id) );
|
$args = array(
|
||||||
|
'network_id' => $site_id,
|
||||||
|
'domain' => $domain,
|
||||||
|
'path' => $path,
|
||||||
|
'fields' => 'ids',
|
||||||
|
);
|
||||||
|
$result = get_sites( $args );
|
||||||
|
$result = array_shift( $result );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters whether a blogname is taken.
|
* Filters whether a blogname is taken.
|
||||||
|
@ -2247,13 +2259,21 @@ function wp_maybe_update_network_user_counts() {
|
||||||
* Update the network-wide site count.
|
* Update the network-wide site count.
|
||||||
*
|
*
|
||||||
* @since 3.7.0
|
* @since 3.7.0
|
||||||
|
* @since 4.6.0 Converted to use get_sites()
|
||||||
*
|
*
|
||||||
* @global wpdb $wpdb WordPress database abstraction object.
|
* @global wpdb $wpdb WordPress database abstraction object.
|
||||||
*/
|
*/
|
||||||
function wp_update_network_site_counts() {
|
function wp_update_network_site_counts() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
$count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d AND spam = '0' AND deleted = '0' and archived = '0'", $wpdb->siteid) );
|
$count = get_sites( array(
|
||||||
|
'network_id' => $wpdb->siteid,
|
||||||
|
'spam' => 0,
|
||||||
|
'deleted' => 0,
|
||||||
|
'archived' => 0,
|
||||||
|
'count' => true,
|
||||||
|
) );
|
||||||
|
|
||||||
update_site_option( 'blog_count', $count );
|
update_site_option( 'blog_count', $count );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue