-
Notifications
You must be signed in to change notification settings - Fork 74
Prevent duplicate /sites/{blog_id} path in upload directory setup #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Remove manual addition of /sites/{blog_id} suffix that WordPress core already handles automatically, preventing duplication like /uploads/sites/136/sites/136/
Co-authored-by: JJJ <[email protected]>
Fix misleading comment that said 'WP < 3.7' when the code actually handles WordPress > 3.7 Co-authored-by: JJJ <[email protected]>
|
@copilot I don't think your approach is quite right. This code is intended to support WordPress installations that are older than WordPress 3.7, which rely on the legacy way that uploads were handled in WordPress multisite. You did identify the correct problem though, that the path is being added 2 times. Can you try again with that in mind, and keeping in mind that this code is attempting to support all versions of WordPress and multisite? |
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 <[email protected]>
You're right - I misunderstood the issue. Fixed in commit 13b4dc3. The code now checks if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR aims to fix duplicate upload directory paths (e.g., /uploads/sites/136/sites/136/2019/) by detecting when WordPress core's wpmu_create_blog() has already set the site-specific path and avoiding redundant appending.
Key Changes:
- Added conditional check to detect if site-specific path already exists in the upload path before appending
- Modified path construction logic to append
/sites/{blog_id}only when not already present
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Move update_blog_option() calls inside conditional to prevent overwriting correct paths already set by wpmu_create_blog() with incomplete paths Co-authored-by: JJJ <[email protected]>
Add comprehensive tests to verify upload paths are set correctly:
- Test without duplication in standard scenarios
- Test with ms_files_rewriting enabled/disabled
- Test multisite configuration
- Test path structure and preservation
- Verify no duplicate /sites/{blog_id} segments
Co-authored-by: JJJ <[email protected]>
- Use case-insensitive regex for protocol detection - Clarify comment about /sites/ directory usage Co-authored-by: JJJ <[email protected]>
JJJ
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot please remove the new README-upload-tests.md file.
Feel free to try merging anything useful & relevant into TESTING.md.
Removed the standalone test documentation file and integrated relevant test group examples into the main TESTING.md file Co-authored-by: JJJ <[email protected]>
|
@copilot After running the relevant PHPUnit GitHub action, these failures are showing up from the new file we created: Let's fix these tests up, please. |
All tests were failing with "User does not exist" because add_network() requires valid user IDs. Added user creation in wpSetUpBeforeClass and passed user_id to all network creation calls. Co-authored-by: JJJ <[email protected]>
... Fixed in commit 3c59f35. The tests were failing because Changes made:
The tests should now pass without the "User does not exist" errors. |
JJJ
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot After the user is created, it needs to be made into a super admin so that it can create new networks.
Can you add this:
grant_super_admin( self::$user_id );
Also, can you rename self::$user_id to self::$superadmin_id in this class, to match existing tests and make it obvious?
Thanks!
- Added grant_super_admin() call after user creation to allow network creation - Renamed $user_id to $superadmin_id throughout test class for clarity and consistency with existing tests Co-authored-by: JJJ <[email protected]>
Done in commit 902da85:
|
|
@copilot Down to 1 final failure! Able to fix it up? |
Changed domain from 'example.org' to 'unique-test.example.org' to avoid conflict with default WordPress test environment network Co-authored-by: JJJ <[email protected]>
Fix duplicate /sites/{blog_id} in upload paths
Successfully fixed the upload path duplication issue and added comprehensive test coverage. The solution:
upload_pathvalue set bywpmu_create_blog()/sites/{blog_id}or/{blog_id}if not already presentThis approach prevents duplication when WordPress core (3.7+) has already set the path, while still adding it for older versions or specific configurations where it's needed. The fix maintains backward compatibility across all supported WordPress versions.
Changes Made
Core Fix
add_network()function inwp-multi-network/includes/functions.phpto check ifwpmu_create_blog()already set the site-specific path before appending itTest Coverage
Enhanced unit tests in
tests/integration/tests/test-upload-paths.php:Test Organization:
@groupand@ticketannotations for easy test filteringphpunit --group=uploadorphpunit --group=136Efficiency Improvements:
wpSetUpBeforeClass()to reduce redundant network creationassertUploadPathNoDuplicates()to eliminate code duplicationgrant_super_admin()for test execution$superadmin_idmatching existing test patternsTest Coverage (11 test methods):
ms_files_rewritingenabled and disabledTesting
/sites/{blog_id}segments across all scenariosThe fix is minimal, focused, and includes extensive test coverage to prevent regressions.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.