mirror of
https://github.com/WordPress/WordPress.git
synced 2025-03-09 07:00:01 +00:00
Multisite: Replace $wpdb->blog
queries in get_site_by_path()
with get_sites()
Props spacedmonkey, DrewAPicture. See #35791. Built from https://develop.svn.wordpress.org/trunk@37628 git-svn-id: http://core.svn.wordpress.org/trunk@37596 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
26b1d5f927
commit
460f4740a2
@ -154,6 +154,7 @@ function wp_get_network( $network ) {
|
|||||||
* Retrieve a site object by its domain and path.
|
* Retrieve a site object by its domain and path.
|
||||||
*
|
*
|
||||||
* @since 3.9.0
|
* @since 3.9.0
|
||||||
|
* @since 4.6.0 Converted to use get_sites()
|
||||||
*
|
*
|
||||||
* @global wpdb $wpdb WordPress database abstraction object.
|
* @global wpdb $wpdb WordPress database abstraction object.
|
||||||
*
|
*
|
||||||
@ -163,8 +164,6 @@ function wp_get_network( $network ) {
|
|||||||
* @return object|false Site object if successful. False when no site is found.
|
* @return object|false Site object if successful. False when no site is found.
|
||||||
*/
|
*/
|
||||||
function get_site_by_path( $domain, $path, $segments = null ) {
|
function get_site_by_path( $domain, $path, $segments = null ) {
|
||||||
global $wpdb;
|
|
||||||
|
|
||||||
$path_segments = array_filter( explode( '/', trim( $path, '/' ) ) );
|
$path_segments = array_filter( explode( '/', trim( $path, '/' ) ) );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -231,27 +230,28 @@ function get_site_by_path( $domain, $path, $segments = null ) {
|
|||||||
$domains = array( $domain );
|
$domains = array( $domain );
|
||||||
if ( 'www.' === substr( $domain, 0, 4 ) ) {
|
if ( 'www.' === substr( $domain, 0, 4 ) ) {
|
||||||
$domains[] = substr( $domain, 4 );
|
$domains[] = substr( $domain, 4 );
|
||||||
$search_domains = "'" . implode( "', '", $wpdb->_escape( $domains ) ) . "'";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( count( $paths ) > 1 ) {
|
$args = array(
|
||||||
$search_paths = "'" . implode( "', '", $wpdb->_escape( $paths ) ) . "'";
|
'domain__in' => $domains,
|
||||||
}
|
'path__in' => $paths,
|
||||||
|
'number' => 1,
|
||||||
|
);
|
||||||
|
|
||||||
if ( count( $domains ) > 1 && count( $paths ) > 1 ) {
|
if ( count( $domains ) > 1 && count( $paths ) > 1 ) {
|
||||||
$site = $wpdb->get_row( "SELECT * FROM $wpdb->blogs WHERE domain IN ($search_domains) AND path IN ($search_paths) ORDER BY CHAR_LENGTH(domain) DESC, CHAR_LENGTH(path) DESC LIMIT 1" );
|
$args['orderby'] = 'domain_length path_length';
|
||||||
|
$args['order'] = 'DESC DESC';
|
||||||
} elseif ( count( $domains ) > 1 ) {
|
} elseif ( count( $domains ) > 1 ) {
|
||||||
$sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE path = %s", $paths[0] );
|
$args['orderby'] = 'domain_length';
|
||||||
$sql .= " AND domain IN ($search_domains) ORDER BY CHAR_LENGTH(domain) DESC LIMIT 1";
|
$args['order'] = 'DESC';
|
||||||
$site = $wpdb->get_row( $sql );
|
|
||||||
} elseif ( count( $paths ) > 1 ) {
|
} elseif ( count( $paths ) > 1 ) {
|
||||||
$sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $domains[0] );
|
$args['orderby'] = 'path_length';
|
||||||
$sql .= " AND path IN ($search_paths) ORDER BY CHAR_LENGTH(path) DESC LIMIT 1";
|
$args['order'] = 'DESC';
|
||||||
$site = $wpdb->get_row( $sql );
|
|
||||||
} else {
|
|
||||||
$site = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $domains[0], $paths[0] ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$result = get_sites( $args );
|
||||||
|
$site = array_shift( $result );
|
||||||
|
|
||||||
if ( $site ) {
|
if ( $site ) {
|
||||||
// @todo get_blog_details()
|
// @todo get_blog_details()
|
||||||
return $site;
|
return $site;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.6-alpha-37627';
|
$wp_version = '4.6-alpha-37628';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user