Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions inc/class-domain-mapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ public function register_mapped_filters(): void {
add_filter('site_url', [$this, 'mangle_url'], -10, 4);
add_filter('home_url', [$this, 'mangle_url'], -10, 4);
add_filter('option_siteurl', [$this, 'mangle_url'], 20);
add_filter('option_home', [$this, 'mangle_url'], 20);

add_filter('theme_file_uri', [$this, 'mangle_url']);
add_filter('stylesheet_directory_uri', [$this, 'mangle_url']);
Expand Down
37 changes: 37 additions & 0 deletions inc/compat/class-general-compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ public function init(): void {
*/
add_filter('wp_initialize_site_args', [$this, 'fix_new_site_url_scheme'], 10, 3);

/**
* Flush rewrite rules after site duplication.
*
* Cloned sites inherit the template's rewrite_rules option verbatim.
* If CPT permalink slugs were changed after the template was created,
* the cloned site will 404 on those CPT URLs until rules are regenerated.
*
* @since 2.0.24
*/
add_action('wu_duplicate_site', [$this, 'flush_rewrite_rules_on_new_site'], 20);

/**
* Rank Math (Free and Pro)
*
Expand Down Expand Up @@ -501,6 +512,32 @@ public function fix_new_site_url_scheme(array $args, \WP_Site $site, \WP_Network
return $args;
}

/**
* Flush rewrite rules after site duplication.
*
* Cloned sites inherit the template's rewrite_rules option verbatim.
* If CPT permalink slugs were changed after the template was created,
* the cloned site will 404 on those CPT URLs until rules are regenerated.
*
* @since 2.0.24
* @param int|object $new_site The new site ID or data object.
* @return void
*/
public function flush_rewrite_rules_on_new_site($new_site): void {

$blog_id = is_object($new_site) && isset($new_site->blog_id)
? (int) $new_site->blog_id
: (int) $new_site;

if ($blog_id < 2) {
return;
}

switch_to_blog($blog_id);
flush_rewrite_rules(true);
restore_current_blog();
}

/**
* Removes RankMath and RankMath Pro Installer::wpmu_new_blog action
* This registered action causes error on database during site creation
Expand Down
Loading