WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 3 years ago

Last modified 3 years ago

#24833 closed enhancement (fixed)

Multisite site search for subdomain install with mapped domains

Reported by: Surbma Owned by: jeremyfelt
Milestone: 4.6 Priority: normal
Severity: normal Version: 3.5.2
Component: Networks and Sites Keywords: has-patch has-unit-tests
Focuses: multisite Cc:

Description

Site search is not working in a Multisite with subdomain install, when a sub site's domain is changed and not using the main site's domain in its own domain. It means it is not a subdomain of the main site.

Mainly it affects sub sites with domain mapping.

In the file: /wp-admin/includes/class-wp-ms-sites-list-table.php there is the search query, which has the main site's domain hardcoded in the query ($current_site->domain). So it needs to be changed to search for all kind of domains.

I don't know much about this code, but I have found a fix and it is working, so I add it here.

This code needs to be put in the /wp-admin/includes/class-wp-ms-sites-list-table.php file after the 73rd line in WP 3.5.2:

$blog_s = '$wild' . $like_s . '$wild'; // fix

Attachments (1)

24833.patch (1.1 KB) - added by ocean90 4 years ago.

Download all attachments as: .zip

Change History (29)

#1 @markoheijnen
6 years ago

If the issue is only with mapped domains then it's not really an issue in WordPress because you need a plugin for that but you do have a point about having it hardcoded. Maybe a filter on the query would make sense.

I don't think your fix is a real fix but I can be wrong about the issue you are having. When you want the ability to search on mapped domains then you need to look into another table. So a like query will not fix that.

#2 @Surbma
6 years ago

WordPress Multisite has the feature to change the domain of a subsite without any plugin, so it is indeed an issue with WordPress core.

The best way to use custom domains is with domain mapping, but it is not mandatory. So the WordPress core needs to be fixed to search for other domains, than the main site's subdomains.

It is not my code, I don't know much about database query, I just know, that I put this code to the file and now the domain search function is working fine.

So this fix needs a developer, who understands how it works and change the code accordingly.

#3 @DrewAPicture
6 years ago

  • Cc xoodrew@… added

#4 follow-up: @markoheijnen
6 years ago

I looked into it and I'm mixed. I think simplifying $blog_s would be cool but that would also mean searching on the network domain name will always show everything.

I think in this situation a filter maybe makes more sense then changing $blog_s. So you change only that small part of the query.

#5 in reply to: ↑ 4 @Surbma
6 years ago

Replying to markoheijnen:

searching on the network domain name will always show everything

Not for me. ;) I use almost only custom domains in my network. So it makes sense for me to search for the network domain as it will show me all the blogs without any custom domains.

For others without any custom domains, what is the problem if it shows all subdomains, if somebody search for the network domain? Main site is always the first in the list, there is no need to search for it.

#6 @markoheijnen
6 years ago

So a filter will work for you ;) I just mentioning the possible negative impact of it. The key is that the search only shows real results and not because the main domain is in the domain name

#7 @Surbma
6 years ago

Ok, I believe you. Every solution is good for me, what works for everybody, in every case. :)

I just told you a situation, where searching for the network domain makes sense if it really shows all blogs with that domain.

So just to understand your solution, what if I search for the network domain in your case? What will it show? If it doesn't show all blogs, just the main site, how can I search for all blogs without custom domains?

#8 @jeremyfelt
6 years ago

  • Component changed from Multisite to Networks and Sites
  • Focuses multisite added

#9 @Surbma
5 years ago

I have tried it with every new version of WordPress since 3.5.2, but the search function is still not working with sub sites, that has a changed domain.

Is there any chance to have a fix for this? Is it only me, who has a Multisite with a lot of sub sites having all their own domains?

I don't know database queries, but is it really a difficult thing to get a search for a domain name?

I would pay for this solution if somebody can fix it and push this fix into WordPress core.

#10 @jeremyfelt
4 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 4.3

The current search is built with this:

$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 );

With the improvements we're working toward in #22383 and #31240, this should be updated to search all paths/domains in a subdomain configuration. See also #31148, which should become WP_Site_Query.

#12 @obenland
4 years ago

  • Milestone changed from 4.3 to Future Release

No movement, let's circle back in another release.

#13 @ocean90
4 years ago

We have the same issue on dotorg: The network for the localized sites has the domain global.wordpress.org and each "sub-site" has the domain $locale.wordpress.org. Because of the lines mentioned in comment:10 WordPress searches for $locale.wordpress.org.global.wordpress.org or $locale.global.wordpress.org which of course doesn't exist.

I tried to make a test for this behavior similar to ticket:33185:33185.tests.patch but it seems like our test suite only supports sub-directory installs. :(

@ocean90
4 years ago

This ticket was mentioned in Slack in #core-multisite by ocean90. View the logs.


4 years ago

#15 @jeremyfelt
3 years ago

  • Milestone changed from Future Release to 4.6

I have a feeling #35791 will help solve a few tickets like this, so I'm leaving a note for later.

Related: #21837, #33185.

#16 @Surbma
3 years ago

Wow! I can't believe it. I opened this ticket almost 3 years ago. Can't wait for the 4.6 version.

Thank you for all developers, who contributed in this!

#17 @DrewAPicture
3 years ago

See #36675 for where WP_MS_Sites_List_Table is being adapted to use WP_Site_Query.

#18 @ajv9540
3 years ago

  • Resolution set to wontfix
  • Status changed from new to closed

#19 @ocean90
3 years ago

  • Resolution wontfix deleted
  • Status changed from closed to reopened

#20 @chriscct7
3 years ago

  • Owner set to ocean90
  • Status changed from reopened to assigned

This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.


3 years ago

This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.


3 years ago

#23 @jeremyfelt
3 years ago

The fix for this will be part of the work on #36675 to adapt WP_MS_Sites_List_Tables to WP_Site_Query

#24 @jeremyfelt
3 years ago

  • Keywords has-patch has-unit-tests added; needs-patch removed
  • Owner changed from ocean90 to jeremyfelt

The latest patch on #36675, which implements WP_Site_Query (see #35791) resolves this ticket in the process. With that patch applied, the entire domain column is searched rather than a portion of it.

#25 @Surbma
3 years ago

Very good news @jeremyfelt. Thanks a lot for all the work done!

This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.


3 years ago

#27 @jeremyfelt
3 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 37736:

Multisite: Use WP_Site_Query to power WP_MS_Sites_List_Table.

WP_Site_Query provides for a cleaner prepare_items() method. It significantly improves the search experience in the sites list table:

  • In a subdomain configuration, domain and path are searched for a provided terms.
  • In a subdirectory configuration, path is searched for a provided term.
  • The full domain is searched in a subdomain configuration rather than the portion not matching the network's domain.
  • Terms are searched as %term% by default. Adding * in the middle of a term will search %te%rm%.

Props flixos90, Fab1en.
Fixes #33185, #24833, #21837, #36675.

#28 @DrewAPicture
3 years ago

In 37739:

Docs: Add a missing summary and @since version to the DocBlock for WP_MS_Sites_List_Table::prepare_items().

Also adds a changelog entry for 4.6.0 noting the changeover to get_sites().

Fixes #36675. See #21837, #24833 and #33185.

Note: See TracTickets for help on using tickets.