From 3ff13c9a2a451d759537349fe42956ff98444c26 Mon Sep 17 00:00:00 2001 From: Achraf Chouk Date: Sun, 2 Jan 2022 15:33:49 +0100 Subject: [PATCH] Fix the multisite option by adding the WORDPRESSDIR constant. --- CHANGELOG.md | 3 ++ web/statics/mu-plugins/autoload.php | 58 +++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 555d599..73ca331 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v0.0.28 (January 2, 2022) +Fix the `siteurl` multisite option by adding the WORDPRESSDIR constant. + ## v0.0.27 (March 6, 2021) Auto detect https use from site url. Add options to fully customize WordPress installation, as multisite or single site. diff --git a/web/statics/mu-plugins/autoload.php b/web/statics/mu-plugins/autoload.php index 94049b5..e5c357b 100644 --- a/web/statics/mu-plugins/autoload.php +++ b/web/statics/mu-plugins/autoload.php @@ -108,22 +108,6 @@ return WP_THEME_URL; }); -/** - * Update network admin URL. - */ -add_filter('network_site_url', function ($url, $path, $scheme) { - // Check network admin path - if ('wp-admin/network/' !== $path || 'admin' !== $scheme) { - return $url; - } - - // Fix path by adding the WORDPRESSDIR constant - $current_network = get_network(); - $url = set_url_scheme('https://'.$current_network->domain.'/'.WORDPRESSDIR.$current_network->path, $scheme); - - return $url.ltrim($path, '/'); -}, 10, 3); - /** * Update automatically the `own.php` configuration file. */ @@ -189,3 +173,45 @@ // Puts contents into target configuration file file_put_contents($target, $contents); }); + +/** + * Update network admin URL. + */ +add_filter('network_site_url', function ($url, $path, $scheme) { + // Check network admin path + if ('wp-admin/network/' !== $path || 'admin' !== $scheme) { + return $url; + } + + // Fix path by adding the WORDPRESSDIR constant + $current_network = get_network(); + $url = set_url_scheme('https://'.$current_network->domain.'/'.WORDPRESSDIR.$current_network->path, $scheme); + + return $url.ltrim($path, '/'); +}, 10, 3); + +/** + * Filters reserved site names on a sub-directory Multisite installation. + */ +add_filter('subdirectory_reserved_names', function ($names) { + return array_merge($names, [WORDPRESSDIR]); +}); + +/** + * Fires once a site has been created. + * Useful to update the `siteurl` option. + */ +add_action('wpmu_new_blog', function ($blog_id, $user_id, $domain, $path, $site_id, $meta) { + // Switch the newly created blog + switch_to_blog($blog_id); + + // Get `siteurl` network option and add WORDPRESSDIR constant + $siteurl = get_option('siteurl'); + $siteurl = rtrim($siteurl, '/').'/'.WORDPRESSDIR; + + // Update option + update_option('siteurl', $siteurl); + + // Restore to the current blog + restore_current_blog(); +}, 10, 6);