Skip to content

Custom Document Folder

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
  • Composer Install

    Terminal window
    composer require soderlind/custom-document-folder
  • Updates

  1. Navigate to Settings > Document Folder
  2. Check the extensions you want to organize (PDF is pre-selected)
  3. Use the search box to quickly find specific extensions
  4. Click “Show More Categories” to see audio, image, and video extensions
  5. Click “Select All” or “Deselect All” for bulk actions
  6. Save your settings
  7. 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

What happens to files uploaded before activating the plugin?

Section titled “What happens to files uploaded before activating the plugin?”

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.

Will this break my existing media library?

Section titled “Will this break my existing media library?”

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 path
  • wp_handle_upload_prefilter - Captures file extension early
  • wp_check_filetype_and_ext - Validates file types
  • wp_handle_upload_overrides - Handles non-unique filenames
  • sanitize_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
Terminal window
# Install dependencies
composer install
# Run tests
composer test
# Run with coverage
composer test:coverage
Terminal window
wp eval-file wp-content/plugins/custom-document-folder/tests/cdf-filter-test.php
PHPUnit 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:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request
Terminal window
# Clone repository
git clone https://github.com/soderlind/custom-document-folder.git
cd custom-document-folder
# Install dependencies
composer install
# Run tests
composer test

See CHANGELOG.md for version history.

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

Built with:


Made with ❤️ for the WordPress community