GithubHelp home page GithubHelp logo

wp-muplugin-loader's Introduction

WP Must-Use Plugin Loader

Build Status

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": "*",
	"lkwdwrd/wp-muplugin-loader": "~1.0.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.

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": "*",
	"lkwdwrd/wp-muplugin-loader": "~1.0.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
}

wp-muplugin-loader's People

Contributors

lkwdwrd avatar johnpbloch avatar benvoynick avatar keironlowe avatar nlemoine avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.