Skip to content

Commit 13b4dc3

Browse files
CopilotJJJ
andcommitted
Check for existing site path before appending to prevent duplication
Instead of blindly appending /sites/{blog_id}, check if wpmu_create_blog() already set it in upload_path to avoid duplication like /uploads/sites/136/sites/136/ Co-authored-by: JJJ <88951+JJJ@users.noreply.github.com>
1 parent 78da09e commit 13b4dc3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

wp-multi-network/includes/functions.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ function add_network( $args = array() ) {
600600
update_network_option( $new_network_id, $key, $value );
601601
}
602602

603-
// Fix upload path and URLs for WordPress > 3.7.
603+
// Fix upload path and URLs in WP < 3.7.
604604
$use_files_rewriting = defined( 'SITE_ID_CURRENT_SITE' ) && get_network( SITE_ID_CURRENT_SITE )
605605
? get_network_option( SITE_ID_CURRENT_SITE, 'ms_files_rewriting' )
606606
: get_site_option( 'ms_files_rewriting' );
@@ -622,6 +622,16 @@ function add_network( $args = array() ) {
622622
}
623623
$upload_dir .= '/uploads';
624624

625+
// Check if wpmu_create_blog() already set the site-specific path.
626+
$existing_upload_path = get_blog_option( $new_blog_id, 'upload_path' );
627+
$site_path_suffix = defined( 'MULTISITE' ) ? '/sites/' . $new_blog_id : '/' . $new_blog_id;
628+
629+
// Only add the site-specific path if it's not already present.
630+
if ( empty( $existing_upload_path ) || false === strpos( $existing_upload_path, $site_path_suffix ) ) {
631+
$upload_dir .= $site_path_suffix;
632+
$upload_url .= $site_path_suffix;
633+
}
634+
625635
update_blog_option( $new_blog_id, 'upload_path', $upload_dir );
626636
update_blog_option( $new_blog_id, 'upload_url_path', $upload_url );
627637
}

0 commit comments

Comments
 (0)