Network Admin Site Search doesn't work for domain searches
-
I saw 2 other threads addressing this bug but they were both old and closed.
When searching through your hundreds of sites on the sites>all sites page the following will work just fine:
Search by IP
Search by Blog ID
Search by Subdomain
Search by SubdirectoryThere does not appear to be any way to search by Domain.
Here’s the code from includes/class-wp-ms-sites-list-table.php
$query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' "; if ( empty($s) ) { // Nothing to do.
This bit searches for IP addresses:
} elseif ( preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $s ) || preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || preg_match( '/^[0-9]{1,3}\.[0-9]{1,3}\.?$/', $s ) || preg_match( '/^[0-9]{1,3}\.$/', $s ) ) { // IPv4 address $sql = $wpdb->prepare( "SELECT blog_id FROM {$wpdb->registration_log} WHERE {$wpdb->registration_log}.IP LIKE %s", $wpdb->esc_like( $s ) . $wild ); $reg_blog_ids = $wpdb->get_col( $sql ); if ( !$reg_blog_ids ) $reg_blog_ids = array( 0 ); $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' AND {$wpdb->blogs}.blog_id IN (" . implode( ', ', $reg_blog_ids ) . ")";
This bit searches for Blog IDs
} else { if ( is_numeric($s) && empty( $wild ) ) { $query .= $wpdb->prepare( " AND ( {$wpdb->blogs}.blog_id = %s )", $s );
This bit searches for a subdomain ie. “dev” in “dev.multi.mysite.com” when subdomain_install == true in the config.
} elseif ( is_subdomain_install() ) { $blog_s = str_replace( '.' . $current_site->domain, '', $s ); $blog_s = $wpdb->esc_like( $blog_s ) . $wild . $wpdb->esc_like( '.' . $current_site->domain ); $query .= $wpdb->prepare( " AND ( {$wpdb->blogs}.domain LIKE %s ) ", $blog_s );
This bit searches for subdirectories ie. “subdir” in “multi.mysite.com/subdir”
} else { if ( $s != trim('/', $current_site->path) ) { $blog_s = $wpdb->esc_like( $current_site->path . $s ) . $wild . $wpdb->esc_like( '/' );
and this last bit should search for anything else like “myothersite.com”
} else { $blog_s = $wpdb->esc_like( $s ); }
but it doesn’t because like the condition before it, it searches the “path” column
$query .= $wpdb->prepare( " AND ( {$wpdb->blogs}.path LIKE %s )", $blog_s ); } }
If I’m understanding the code properly then there doesn’t appear to be any way to search for “myothersite.com” if you also have “subdom.multi.mysite.com” since if is_subdomain_install() returns true, you never get to any of the other options. Though even if you do get past the subdomain condition you still won’t find “myothersite.com” since the query will try to find it in the “path” column instead of the “domain” column
In my install I’ve added the following bit right above the is_subdomain_install() condition:
elseif (strpos($s, ":") !== false) { $blog_s = $wpdb->esc_like( trim( $s, ":" ) ) . $wild; $query .= $wpdb->prepare( " AND ( {$wpdb->blogs}.domain LIKE %s )", $blog_s ); }
With this addition I can specifically look for domains by using “:” in front of my search term. The wild card * is also supported where as it doesn’t appear to be in the final “else” in the original code.
- The topic ‘Network Admin Site Search doesn't work for domain searches’ is closed to new replies.