Organize document uploads by automatically directing specific file types to custom folders based on their extensions.
Custom Document Folder automatically organizes your WordPress media uploads by directing specific document types to dedicated folders. Instead of having all files mixed together in date-based folders, you can configure which file extensions should be uploaded to their own organized folders.
- β¨ Modern Settings Interface - Beautiful grid-based UI with search functionality
- π Category Organization - Extensions grouped by type (Documents, Images, Video, Audio, Archives, etc.)
- π Live Search - Filter extensions and categories in real-time
- β‘ Bulk Actions - Select/deselect all visible extensions at once
- π― Collapsible Categories - Media categories (Audio, Images, Video, Other) hidden by default
- π’ Live Counter - See how many extensions are selected
- π Custom Folder Routing - Each extension gets its own folder (e.g.,
/pdf/,/docx/,/xlsx/) - π Security Focused - Input sanitization with
sanitize_text_field() - β MIME Type Validation - Only allows file types that WordPress already permits
- π Backward Compatible - Existing files remain in their original locations
- π PDF Default - Comes pre-configured with PDF support
- ποΈ Non-unique Filename Handling - Automatically removes old attachments when re-uploading
-
Quick Install
- Download
custom-document-folder.zip - Upload via Plugins > Add New > Upload Plugin
- Activate the plugin.
- Go to Settings > Document Folder to configure
- Download
-
Composer Install
composer require soderlind/custom-document-folder
-
Updates
- Plugin updates are handled automatically via GitHub. No need to manually download and install updates.
- Navigate to Settings > Document Folder
- Check the extensions you want to organize (PDF is pre-selected)
- Use the search box to quickly find specific extensions
- Click "Show More Categories" to see audio, image, and video extensions
- Click "Select All" or "Deselect All" for bulk actions
- Save your settings
- New uploads of selected types will automatically go to their designated folders
If you select pdf and docx extensions:
- PDF files upload to β
/wp-content/uploads/pdf/ - DOCX files upload to β
/wp-content/uploads/docx/ - Other files continue uploading to standard date-based folders
- WordPress: 6.7 or higher
- PHP: 8.3 or higher
- PHP Extensions: None required beyond standard WordPress requirements
They remain in their original locations. This plugin only affects new uploads after you configure and save your settings.
Yes! Select as many extensions as you need. The counter shows how many are currently selected.
No. Existing files stay where they are. Only new uploads of selected extensions are redirected to custom folders.
Yes. Each site in a multisite installation can configure its own extensions independently.
Yes! Click "Show More Categories" to reveal and select image, video, and audio extensions. However, some themes and plugins expect images in date-based folders.
custom-document-folder/
βββ custom-document-folder.php # Main plugin file
βββ tests/
β βββ TestCase.php # Base test class
β βββ SettingsTest.php # Settings tests
β βββ UploadTest.php # Upload tests
β βββ cdf-filter-test.php # WP-CLI filter test
β βββ TEST-RESULTS.md # Test documentation
βββ composer.json # Composer configuration
βββ phpunit.xml.dist # PHPUnit configuration
βββ CHANGELOG.md # Version history
βββ README.md # This file
The plugin uses these WordPress hooks:
upload_dir(priority 20) - Modifies upload directory pathwp_handle_upload_prefilter- Captures file extension earlywp_check_filetype_and_ext- Validates file typeswp_handle_upload_overrides- Handles non-unique filenamessanitize_file_name- Removes old attachments
- PHP 8.3 with strict types and namespaces
- WordPress Coding Standards compliant
- PHPUnit test coverage
- Brain Monkey for WordPress function mocking
- Namespace:
Soderlind\DocumentFolder
# Install dependencies
composer install
# Run tests
composer test
# Run with coverage
composer test:coveragewp eval-file wp-content/plugins/custom-document-folder/tests/cdf-filter-test.phpPHPUnit 9.6.29
OK (7 tests, 21 assertions)
All core functionality verified:
- β Settings sanitization
- β Invalid input handling
- β XSS protection
- β PDF upload path modification
- β Non-selected files use default path
- β Multiple extension handling
- β File type validation
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Clone repository
git clone https://github.com/soderlind/custom-document-folder.git
cd custom-document-folder
# Install dependencies
composer install
# Run tests
composer testSee CHANGELOG.md for version history.
- GitHub Issues: Report bugs or request features
- WordPress Support: Plugin support forum
This plugin is licensed under the GPL v2 or later.
Copyright (C) 2025 Per Soderlind
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Per Soderlind
- Website: soderlind.no
- GitHub: @soderlind
- Twitter: @soderlind
Built with:
Made with β€οΈ for the WordPress community