Skip to content

Commit

Permalink
Add polyfill for get_sudirectory_reserved_names
Browse files Browse the repository at this point in the history
  • Loading branch information
i-am-chitti committed Apr 26, 2024
1 parent 6b87b49 commit 2101d99
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/Site_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,7 @@ public function create( $args, $assoc_args ) {

// If not a subdomain install, make sure the domain isn't a reserved word
if ( ! is_subdomain_install() ) {
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Calling WordPress native hook.
$subdirectory_reserved_names = apply_filters( 'subdirectory_reserved_names', [ 'page', 'comments', 'blog', 'files', 'feed' ] );
$subdirectory_reserved_names = $this->get_subdirectory_reserved_names();
if ( in_array( $base, $subdirectory_reserved_names, true ) ) {
WP_CLI::error( 'The following words are reserved and cannot be used as blog names: ' . implode( ', ', $subdirectory_reserved_names ) );
}
Expand Down Expand Up @@ -552,7 +551,7 @@ public function generate( $args, $assoc_args ) {
$is_subdomain_install = is_subdomain_install();
// If not a subdomain install, make sure the domain isn't a reserved word
if ( ! $is_subdomain_install ) {
$subdirectory_reserved_names = get_subdirectory_reserved_names();
$subdirectory_reserved_names = $this->get_subdirectory_reserved_names();
if ( in_array( $base, $subdirectory_reserved_names, true ) ) {
WP_CLI::error( 'The following words are reserved and cannot be used as blog names: ' . implode( ', ', $subdirectory_reserved_names ) );
}
Expand Down Expand Up @@ -646,6 +645,35 @@ public function generate( $args, $assoc_args ) {
}
}

/**
* Retrieves a list of reserved site on a sub-directory Multisite installation.
*
* Works on older WordPress versions where get_subdirectory_reserved_names() does not exist.
*
* @return string[] Array of reserved names.
*/
private function get_subdirectory_reserved_names() {
if ( function_exists( 'get_subdirectory_reserved_names' ) ) {
return get_subdirectory_reserved_names();
}

$names = array(
'page',
'comments',
'blog',
'files',
'feed',
'wp-admin',
'wp-content',
'wp-includes',
'wp-json',
'embed',
);

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Calling WordPress native hook.
return apply_filters( 'subdirectory_reserved_names', $names );
}

/**
* Gets network data for a given id.
*
Expand Down

0 comments on commit 2101d99

Please sign in to comment.