wp-spaghetti/bedrock-autoloader-mu
最新稳定版本:v1.0.20260107
Composer 安装命令:
composer require wp-spaghetti/bedrock-autoloader-mu
包简介
Self-contained Bedrock MU-Plugin Autoloader, auto-synced daily from roots/bedrock and roots/bedrock-autoloader
README 文档
README
Bedrock MU-Plugin Autoloader
Self-contained Bedrock autoloader for must-use plugins. This package is automatically synchronized daily from roots/bedrock and roots/bedrock-autoloader.
Why this package?
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
Installation
Method 1: Via Composer with Auto-Copy Helper (Recommended)
Install the package:
composer require wp-spaghetti/bedrock-autoloader-mu
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": [
"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.
Method 2: Via Composer with Direct Download
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.
Usage
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)
How It Works
- 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
Auto-Sync
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.
Troubleshooting
File not copied to mu-plugins root
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)
Different project structure
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/" ]
Contributing
For your contributions please use:
See CONTRIBUTING for detailed guidelines.
Sponsor
Credits
Based on the original work by Roots:
License
MIT License - See LICENSE file for details.
Original code © Roots
Self-contained package © Frugan
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-06