Make WordPress Core

Opened 6 years ago

Closed 5 years ago

#43851 closed defect (bug) (worksforme)

Network admin allows updating one site to have the same domain and path as another site.

Reported by: giacocorsiglia's profile giacocorsiglia Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Networks and Sites Keywords:
Focuses: administration, multisite Cc:


The network admin page for updating sites in multisite (site-info.php) allows setting the domain and path on one site to match the domain and path on another site. This creates a conflict: if multiple sites have the same domain or path (depending on subdomain install vs. subdirectory install), only one of them can actually be accessed.

I would propose the following addition on line 82 of site-info.php:

// /wp-admin/network/site-info.php:82

if ( $blog_data['domain'] !== $existing_details->domain || $blog_data['path'] !== $existing_details->path ) {
    // A change to the domain or path was requested.
    if ( get_sites( [
        'domain' => $blog_data['domain'],
        'path' => $blog_data['path'],
        'site__not_in' => [ $id ], // Don't include the site we are changing.
        'number' => 1, // It's enough to know if one or more exist.
    ] ) ) {
        wp_die( __( 'Another site with that domain and path already exists.' ) );

I don't think this is the case, but if it only needs to be unique by network, this can be added to the query:

'network_id' => $existing_details->site_id,

If there is some reason to not make this change, then I would appreciate the addition of a filter either on line 82 of site-info.php or in the update_blog_details() function that would allow the above check to be added by me or other developers. In fact, would be useful in either case!

Thank you!

Change History (1)

#1 @jeremyfelt
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed
  • Version 4.9.5 deleted

Hi @giacocorsiglia, thanks for the ticket.

This should be possible in the upcoming WordPress 5.1 release. The new wp_update_site() and wp_insert_site() functions call wp_prepare_site_data() which in turn fires a wp_validate_site_data action that allows developers to return an error before the site is added or changed. The history on that can be seen in #40364.

I'm going to go ahead and close this as "worksforme" (even though it will still be a few weeks), but please feel free to reopen if this doesn't address the issue.

Note: See TracTickets for help on using tickets.