Self-contained Bedrock autoloader for must-use plugins. This package is automatically synchronized daily from roots/bedrock and roots/bedrock-autoloader.
The original roots/bedrock-autoloader requires the library to be loaded before the mu-plugin wrapper executes. This creates a chicken-and-egg problem in standard WordPress environments where mu-plugins load before regular plugins.
This package solves that by:
- Combining the Autoloader class and wrapper into a single self-contained file
- Auto-syncing daily from upstream sources
- Installing directly in
mu-pluginsroot (not a subdirectory) - Working out-of-the-box with WordPress
mu-pluginsdirectory - Requiring no external dependencies at runtime
Install the package:
composer require wp-spaghetti/bedrock-autoloader-muAdd this to your project root composer.json:
{
"require": {
"wp-spaghetti/bedrock-autoloader-mu": "^1.0"
},
"scripts": {
"post-install-cmd": [
"@copy-bedrock-autoloader-mu"
],
"post-update-cmd": [
"@copy-bedrock-autoloader-mu"
],
"copy-bedrock-autoloader-mu": [
"WpSpaghetti\\BedrockAutoloader\\CopyHelper::copy"
]
},
"extra": {
"installer-paths": {
"wp-content/mu-plugins/{$name}/": [
"type:wordpress-muplugin"
]
}
}
}The helper class will automatically copy bedrock-autoloader.php to mu-plugins/ root on install and update.
Install the package to manage versions via Composer, then download the file directly:
Add this to your project root composer.json:
{
"require": {
"wp-spaghetti/bedrock-autoloader-mu": "^1.0"
},
"scripts": {
"post-install-cmd": [
"@copy-bedrock-autoloader-mu"
],
"post-update-cmd": [
"@copy-bedrock-autoloader-mu"
],
"copy-bedrock-autoloader-mu": [
"curl -sS https://raw.githubusercontent.com/wp-spaghetti/bedrock-autoloader-mu/main/dist/bedrock-autoloader.php -o wp-content/mu-plugins/bedrock-autoloader.php"
]
},
"extra": {
"installer-paths": {
"wp-content/mu-plugins/{$name}/": [
"type:wordpress-muplugin"
]
}
}
}Note: Adjust the path
wp-content/mu-plugins/bedrock-autoloader.phpaccording to your project structure.
Once installed, the autoloader will automatically load all subdirectories in wp-content/mu-plugins/ as plugins.
Example structure after installation:
wp-content/
└── mu-plugins/
├── bedrock-autoloader.php (← main autoloader file, copied from dist/)
├── bedrock-autoloader-mu/
│ ├── dist/
│ │ └── bedrock-autoloader.php (← source template)
│ ├── src/
│ │ └── CopyHelper.php (← helper class)
│ └── composer.json
└── your-mu-plugin/
└── your-mu-plugin.php (← auto-loaded)
- Composer installs the package in
mu-plugins/bedrock-autoloader-mu/ - Your post-install script copies
dist/bedrock-autoloader.phptomu-plugins/root - WordPress loads
mu-plugins/bedrock-autoloader.phpdirectly - The autoloader loads all other mu-plugin subdirectories
This repository automatically syncs the following files every day at 2 AM UTC:
- Autoloader.php - The autoloader class
- bedrock-autoloader.php - The wrapper file
The combined file is generated and saved in the dist/ directory to prevent it from being autoloaded by itself.
When changes are detected, a new version tag is automatically created with format v1.0.YYYYMMDD.
Make sure:
- You've added the scripts to your project root
composer.json(not the package's composer.json) - Your
installer-pathscorrectly points to your mu-plugins directory - The helper class can write to the mu-plugins directory (check permissions)
If your project has a custom structure, adjust the paths in your scripts. The helper class copies the file relative to the vendor directory, so you may need to use a custom shell script instead:
"copy-bedrock-autoloader-mu": [
"cp -f custom/path/to/vendor/wp-spaghetti/bedrock-autoloader-mu/dist/bedrock-autoloader.php custom/path/to/mu-plugins/"
]For your contributions please use:
See CONTRIBUTING for detailed guidelines.
Based on the original work by Roots:
MIT License - See LICENSE file for details.
Original code © Roots
Self-contained package © Frugan
