Skip to content

Commit fe383af

Browse files
committed
Multisite: Introduce get_subdirectory_reserved_names(), which returns a filterable list of reserved subdirectory site names.
The function encapsulates the existing `subdirectory_reserved_names` filter and reduces the maintenance burden of keeping the value of (currently) two instances of the same hook in sync. See #33615. git-svn-id: https://develop.svn.wordpress.org/trunk@34854 602fd350-edb4-49c9-b593-d223f7449a82
1 parent a409a72 commit fe383af

2 files changed

Lines changed: 31 additions & 17 deletions

File tree

src/wp-admin/network/site-new.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@
4646

4747
// If not a subdomain install, make sure the domain isn't a reserved word
4848
if ( ! is_subdomain_install() ) {
49-
/** This filter is documented in wp-includes/ms-functions.php */
50-
$subdirectory_reserved_names = apply_filters( 'subdirectory_reserved_names', array( 'page', 'comments', 'blog', 'embed', 'files', 'feed', 'wp-admin', 'wp-content', 'wp-includes', 'wp-json' ) );
51-
if ( in_array( $domain, $subdirectory_reserved_names ) )
52-
wp_die( sprintf( __('The following words are reserved for use by WordPress functions and cannot be used as blog names: <code>%s</code>' ), implode( '</code>, <code>', $subdirectory_reserved_names ) ) );
49+
$subdirectory_reserved_names = get_subdirectory_reserved_names();
50+
51+
if ( in_array( $domain, $subdirectory_reserved_names ) ) {
52+
wp_die( sprintf( __( 'The following words are reserved for use by WordPress functions and cannot be used as blog names: <code>%s</code>' ), implode( '</code>, <code>', $subdirectory_reserved_names ) ) );
53+
}
5354
}
5455

5556
$title = $blog['title'];

src/wp-includes/ms-functions.php

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -555,19 +555,7 @@ function wpmu_validate_blog_signup( $blogname, $blog_title, $user = '' ) {
555555
* spring them from jail.
556556
*/
557557
if ( ! is_subdomain_install() ) {
558-
$illegal_names = array_merge(
559-
$illegal_names,
560-
/**
561-
* Filter reserved site names on a sub-directory Multisite install.
562-
*
563-
* @since 3.0.0
564-
* @since 4.4.0 'wp-admin', 'wp-content', 'wp-includes', 'wp-json', and 'embed' were added
565-
* to the reserved names list.
566-
*
567-
* @param array $subdirectory_reserved_names Array of reserved names.
568-
*/
569-
apply_filters( 'subdirectory_reserved_names', array( 'page', 'comments', 'blog', 'files', 'feed', 'wp-admin', 'wp-content', 'wp-includes', 'wp-json', 'embed' ) )
570-
);
558+
$illegal_names = array_merge( $illegal_names, get_subdirectory_reserved_names() );
571559
}
572560

573561
if ( empty( $blogname ) )
@@ -2468,3 +2456,28 @@ function wp_get_sites( $args = array() ) {
24682456

24692457
return $site_results;
24702458
}
2459+
2460+
/**
2461+
* Retrieves a list of reserved site on a sub-directory Multisite install.
2462+
*
2463+
* @since 4.4.0
2464+
*
2465+
* @return array $names Array of reserved subdirectory names.
2466+
*/
2467+
function get_subdirectory_reserved_names() {
2468+
$names = array(
2469+
'page', 'comments', 'blog', 'files', 'feed', 'wp-admin',
2470+
'wp-content', 'wp-includes', 'wp-json', 'embed'
2471+
);
2472+
2473+
/**
2474+
* Filter reserved site names on a sub-directory Multisite install.
2475+
*
2476+
* @since 3.0.0
2477+
* @since 4.4.0 'wp-admin', 'wp-content', 'wp-includes', 'wp-json', and 'embed' were added
2478+
* to the reserved names list.
2479+
*
2480+
* @param array $subdirectory_reserved_names Array of reserved names.
2481+
*/
2482+
return apply_filters( 'subdirectory_reserved_names', $names );
2483+
}

0 commit comments

Comments
 (0)