Is there a way to ban site names from being able to be created. For example we have subfolders like domain.com/site
Is there a way to ban bad words from being registered. So domain.com/bad would be blocked?
How can I do this?
Is there a way to ban site names from being able to be created. For example we have subfolders like domain.com/site
Is there a way to ban bad words from being registered. So domain.com/bad would be blocked?
How can I do this?
You can filter domain_exists
, a check that runs before a site is registered. If you return a positive integer, WordPress will not create that site. Despite its name, that filter lets you check the path too.
Sample code, not tested:
add_filter( 'domain_exists', function( $result, $domain, $path ) {
// Already taken, no need for further checks.
if ( $result ) {
return $result;
}
$blacklist = [
'domains' => [
'assets.example.com',
'wordpress.example.com',
],
'paths' => [
'wp-admin',
'wp-includes',
'wp-content',
],
];
if ( in_array( $domain, $blacklist['domains'] ) ) {
return 1;
}
$path = trim( $path, "https://wordpress.stackexchange.com/" );
if ( empty ( $path) ) {
return $result;
}
if ( in_array( $path, $blacklist['paths'] ) ) {
return 1;
}
return $result;
}, 10, 3 );