mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-01 21:21:24 +01: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.
|
||||
*
|
||||
* @since 3.9.0
|
||||
* @since 4.6.0 Converted to use get_sites()
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
function get_site_by_path( $domain, $path, $segments = null ) {
|
||||
global $wpdb;
|
||||
|
||||
$path_segments = array_filter( explode( '/', trim( $path, '/' ) ) );
|
||||
|
||||
/**
|
||||
@ -231,27 +230,28 @@ function get_site_by_path( $domain, $path, $segments = null ) {
|
||||
$domains = array( $domain );
|
||||
if ( 'www.' === substr( $domain, 0, 4 ) ) {
|
||||
$domains[] = substr( $domain, 4 );
|
||||
$search_domains = "'" . implode( "', '", $wpdb->_escape( $domains ) ) . "'";
|
||||
}
|
||||
|
||||
if ( count( $paths ) > 1 ) {
|
||||
$search_paths = "'" . implode( "', '", $wpdb->_escape( $paths ) ) . "'";
|
||||
}
|
||||
$args = array(
|
||||
'domain__in' => $domains,
|
||||
'path__in' => $paths,
|
||||
'number' => 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 ) {
|
||||
$sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE path = %s", $paths[0] );
|
||||
$sql .= " AND domain IN ($search_domains) ORDER BY CHAR_LENGTH(domain) DESC LIMIT 1";
|
||||
$site = $wpdb->get_row( $sql );
|
||||
$args['orderby'] = 'domain_length';
|
||||
$args['order'] = 'DESC';
|
||||
} elseif ( count( $paths ) > 1 ) {
|
||||
$sql = $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $domains[0] );
|
||||
$sql .= " AND path IN ($search_paths) ORDER BY CHAR_LENGTH(path) DESC LIMIT 1";
|
||||
$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] ) );
|
||||
$args['orderby'] = 'path_length';
|
||||
$args['order'] = 'DESC';
|
||||
}
|
||||
|
||||
$result = get_sites( $args );
|
||||
$site = array_shift( $result );
|
||||
|
||||
if ( $site ) {
|
||||
// @todo get_blog_details()
|
||||
return $site;
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @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.
|
||||
|
Loading…
Reference in New Issue
Block a user