Opened 11 months ago

Closed 8 months ago

Last modified 8 months ago

#21142 closed enhancement (fixed)

Add a filter to domain_exists() function

Reported by: jamescollins Owned by: ryan
Priority: normal Milestone: 3.5
Component: Multisite Version:
Severity: normal Keywords: has-patch commit
Cc:

Description

In Multisite, the domain_exists() function is used by WordPress to "check whether the specified blogname is already taken", however it doesn't provide any filter so that plugins can override the result.

Our Use Case:

On our multisite installs, we allow users to change their subdomain name (or domain name).

We keep a list of their previously used subdomains/domains, and if there is a HTTP request for one of their old domains, we automatically perform a 301 redirect to the new domain name.

However, we also want to make sure that other users cannot use any subdomain/domain name that has been used by another user.

Currently we have no way to override the return value of the domain_exists() function, which means we can't easily prevent other people from signing up for sites that use a domain/subdomain name

Suggestion:

Add a simple filter to the end of the domain_exists() function. See attached patch.

Attachments (2)

21142_domain_exists.diff (684 bytes) - added by jamescollins 11 months ago.
21142_2.diff (669 bytes) - added by jamescollins 8 months ago.
Refreshed patch, uses intermediate $result variable to better readability

Download all attachments as: .zip

Change History (13)

Please ignore the sunrise.php attachment in this ticket - it was meant for #21143 instead.

Apologies for the mess here with the sunrise attachments.

The original 21142_domain_exists.diff patch is still valid, and adding it shouldn't cause any backwards compatibility issues.

  • Keywords reporter-feedback added

There's a 'wpmu_validate_blog_signup' filter. Can't you use that?

I think the 'wpmu_validate_blog_signup ' filter would be ok for when people create blogs via wp-signup.php, but that filter doesn't fire when a super admin creates a site via the network admin dashboard screen.

The description of the domain_exists() function is:

Check whether a blogname is already taken
Used during the new site registration process to ensure that each blogname is unique.

So I think the domain_exists() function is a much more semantically correct place to check if the specified domain name has been used.

Thanks

  • Keywords reporter-feedback removed
  • Milestone changed from Awaiting Review to 3.5

Right, except most of the checks in wpmu_validate_blog_signup() would be useful to run even when a super-admin is creating a blog.

Moved to the 3.5 milestone for consideration, either way.

I just checked, and wpmu_validate_blog_signup() isn't used at all when creating a site via wp-admin/network/site-new.php.

At present it seems that we assume that super admins know what they are doing when creating sites, which is why we perform very few checks when they create a new site.

We would need to come to a consensus as to which checks in wpmu_validate_blog_signup() should apply when creating sites via the network admin screen. At this stage I would think most of those checks shouldn't apply when a super admin is creating a site.

Worth a discussion though.

Although that discussion is possibly separate to the simple 'domain_exists' filter in my patch.

comment:8 follow-up: ↓ 9   nacin8 months ago

  • Keywords needs-refresh commit added

Is there really no other decent filter in the stack to stop a site from being created from site-new.php? It looks like all we do is wp_die() anyway. Also, if wpmu_create_blog() fails, we still create the user. Seems like the whole set of error checking should probably improve.

I'm okay with a filter here, either way. Would be nice if it could set $result, then pass $result to the filter. Otherwise, the line gets long and it's not easy to see what kind of context is passed to the filter.

Refreshed patch, uses intermediate $result variable to better readability

comment:9 in reply to: ↑ 8   jamescollins8 months ago

  • Keywords needs-refresh removed

Replying to nacin:

I'm okay with a filter here, either way. Would be nice if it could set $result, then pass $result to the filter. Otherwise, the line gets long and it's not easy to see what kind of context is passed to the filter.

21142_2.diff implements this - thanks for the suggestion nacin!

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [22065]:

Add domain_exists filter. Props jamescollins. fixes #21142

Note: See TracTickets for help on using tickets.