Skip to content

Commit 2101d99

Browse files
committed
Add polyfill for get_sudirectory_reserved_names
1 parent 6b87b49 commit 2101d99

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/Site_Command.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,7 @@ public function create( $args, $assoc_args ) {
424424

425425
// If not a subdomain install, make sure the domain isn't a reserved word
426426
if ( ! is_subdomain_install() ) {
427-
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Calling WordPress native hook.
428-
$subdirectory_reserved_names = apply_filters( 'subdirectory_reserved_names', [ 'page', 'comments', 'blog', 'files', 'feed' ] );
427+
$subdirectory_reserved_names = $this->get_subdirectory_reserved_names();
429428
if ( in_array( $base, $subdirectory_reserved_names, true ) ) {
430429
WP_CLI::error( 'The following words are reserved and cannot be used as blog names: ' . implode( ', ', $subdirectory_reserved_names ) );
431430
}
@@ -552,7 +551,7 @@ public function generate( $args, $assoc_args ) {
552551
$is_subdomain_install = is_subdomain_install();
553552
// If not a subdomain install, make sure the domain isn't a reserved word
554553
if ( ! $is_subdomain_install ) {
555-
$subdirectory_reserved_names = get_subdirectory_reserved_names();
554+
$subdirectory_reserved_names = $this->get_subdirectory_reserved_names();
556555
if ( in_array( $base, $subdirectory_reserved_names, true ) ) {
557556
WP_CLI::error( 'The following words are reserved and cannot be used as blog names: ' . implode( ', ', $subdirectory_reserved_names ) );
558557
}
@@ -646,6 +645,35 @@ public function generate( $args, $assoc_args ) {
646645
}
647646
}
648647

648+
/**
649+
* Retrieves a list of reserved site on a sub-directory Multisite installation.
650+
*
651+
* Works on older WordPress versions where get_subdirectory_reserved_names() does not exist.
652+
*
653+
* @return string[] Array of reserved names.
654+
*/
655+
private function get_subdirectory_reserved_names() {
656+
if ( function_exists( 'get_subdirectory_reserved_names' ) ) {
657+
return get_subdirectory_reserved_names();
658+
}
659+
660+
$names = array(
661+
'page',
662+
'comments',
663+
'blog',
664+
'files',
665+
'feed',
666+
'wp-admin',
667+
'wp-content',
668+
'wp-includes',
669+
'wp-json',
670+
'embed',
671+
);
672+
673+
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Calling WordPress native hook.
674+
return apply_filters( 'subdirectory_reserved_names', $names );
675+
}
676+
649677
/**
650678
* Gets network data for a given id.
651679
*

0 commit comments

Comments
 (0)