定制 boxuk/wp-muplugin-loader 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

boxuk/wp-muplugin-loader

最新稳定版本:2.2.0

Composer 安装命令:

composer require boxuk/wp-muplugin-loader

包简介

A drop-in MU Plugin loader for WordPress

README 文档

README

This project is now abandoned. We've moved to use Roots Bedrock Autoloader in our project skeleton.

Attribution

  • This package was forked from WP Must-Use Plugin Loader due to it seemingly falling into abandonment. We are happy to contribute our work back to the source should the maintainer pick up the project again.

Overview

Managing plugins using the Composer Installers library works remarkably well. However, its handling of MU plugins leaves something to be desired.

WordPress MU (must use) Plugins are files that are placed in the wp-content/mu-plugins/ folder. These files are loaded automatically. The problem is when a plugin is actually inside a folder. WordPress will only load .php files and doesn't drop into any directories. When the Composer Installers plugin runs, it always puts the repo into a nice contained folder. This means the Composer Installers MU plugins never actually run!

There are manual ways around this that work fine, but I want to get away from any manual steps when running the install. No extra files, just run composer install or composer update and have it work. That is what the WP Must-Use Plugin Loader does.

Usage Instructions

In your project's composer.json file, require this package.

"require": {
	"composer/installers": "~1.2.0",
	"johnpbloch/wordpress": "*",
	"boxuk/wp-muplugin-loader": "~1.0",
}

Make sure in the extras of your composer.json you have your mu-plugins path defined.

"extra": {
	"installer-paths": {
		"app/wp-content/themes/{$name}": [
			"type:wordpress-theme"
		],
		"app/wp-content/plugins/{$name}": [
			"type:wordpress-plugin"
		],
		"app/wp-content/mu-plugins/{$name}": [
			"type:wordpress-muplugin"
		]
	},
	"wordpress-install-dir": "app/wp"
}

And that's it.

When Composer dumps it's autoload file, a file called mu-require.php will be placed into your mu-plugins folder. When WordPress loads this file as an MU plugin, it will find all of the plugins in folders in your MU plugins directory and include those as well.

Changing the name of the generated file

If you need to have control over what the name of the generated file is, you can set it with the following within the extra section of your composer.json:

"extra": {
	...
	"mu-require-file": "custom-mu-require-filename.php"
}

Similarly, if you wish to turn off generation of this file altogether you can do so by setting this to false:

"extra": {
	...
	"mu-require-file": false
}

Forcing MU Plugins

Usually when you are using MU plugins, you have some 'normal' WordPress plugins that you want to always be active. They are not always MU-Plugins, though, so it makes no sense to put the "type": "wordpress-muplugin" in the composer.json file. WP Must-Use Plugin Loader allows you to override the type from wordpress-plugin to wordpress-muplugin as needed.

To do this, define a "force-mu" key in "extra" of your composer.json file. This key should hold an array of slugs for plugins to force into Must-Use status.

This is compatible with WPackagist. When adding plugins from WPackagist use the plugin's normal slug, not the wp-packagist version.

"require": {
	"johnpbloch/wordpress": "*",
	"boxuk/wp-muplugin-loader": "~1.0",
	"wpackagist-plugin/rest-api": "*"
},
"extra": {
	"force-mu": [
		"rest-api"
	],
	"installer-paths": {
		"app/wp-content/themes/{$name}": [
			"type:wordpress-theme"
		],
		"app/wp-content/plugins/{$name}": [
			"type:wordpress-plugin"
		],
		"app/wp-content/mu-plugins/{$name}": [
			"type:wordpress-muplugin"
		]
	},
	"wordpress-install-dir": "app/wp"
}

When the rest-api plugin is installed, instead of going in the normal plugins folder, it will be pushed over to the mu-plugins folder and loaded automatically with other Must-Use Plugins.

Forcing Unix Directory Separators

If you work on Windows but use a Linux VM to run your development server, you may need to force unix directory separators to make sure the server can find the mu loader script. If so, there's another configuration in the extra block you can set:

"extra": {
	"force-unix-separator": true
}

Modifying the src directory of the mu plugins

You may wish to change the src directory you want the mu plugins to be loaded from. For example, on WordPress VIP projects you may wish to load mu plugins from client-mu-plugins using this loader. To do this you can set a constant to tell the mu plugin loader where your mu plugins are kept:

define('MU_PLUGIN_LOADER_SRC_DIR', WPCOM_VIP_CLIENT_MU_PLUGIN_DIR . '/');

Filtering the mu plugins loaded

You may wish to filer the mu plugins loaded by the mu plugin loader. WordPress does not provide any hook that is early enough to ensure that this filter is registered before the plugins are loaded, so filtering of this list should be applied immediately before the mu-loader is initialised. You can modify the mu-require.php file like the below, or create a new file that's alphabetically before mu-require.php file in your mu-plugins directory.

add_filter(
    'lkwdwrd_mupluginloader_get_muplugins',
    function ( array $plugins ):  array {
        unset( $plugins['example/plugin.php'] );
        return $plugins;
    }
);

// Load the mu loader
require_once 'vendor/boxuk/wp-muplugin-loader/src/mu-loader.php';

boxuk/wp-muplugin-loader 适用场景与选型建议

boxuk/wp-muplugin-loader 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 410.23k 次下载、GitHub Stars 达 21, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「wordpress」 「loader」 「muplugin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 boxuk/wp-muplugin-loader 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 boxuk/wp-muplugin-loader 我们能提供哪些服务?
定制开发 / 二次开发

基于 boxuk/wp-muplugin-loader 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 410.23k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 21
  • 点击次数: 19
  • 依赖项目数: 8
  • 推荐数: 0

GitHub 信息

  • Stars: 21
  • Watchers: 4
  • Forks: 27
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04