Options: Adding WordPress plugin dependencies - dotherightthing/wpdtrt-plugin-boilerplate GitHub Wiki
Summary
DTRT WordPress Plugin Boilerplate supports user-configurable plugin dependencies.
Status
- Stable @ 1.5.6
- Needs further documentation and testing re adding 3rd party styles and scripts.
- PHPUnit has a conflict when loading plugins with autoloaders (as MU plugins)
Usage
Composer
Example from ./composer.json
:
"require-dev": {
...
"dotherightthing/wpdtrt-contentsections": "^0.1.7",
"wpackagist-plugin/ambrosite-nextprevious-post-link-plus": "2.4.*"
},
"extra": {
"require-wp": [
{
"name": "DTRT Content Sections",
"host": "github",
"repository": "dotherightthing/wpdtrt-contentsections",
"file": "wpdtrt-contentsections.php",
"description": "The gallery viewer is initialised as these are scrolled into view"
},
{
"name": "Ambrosite Next/Previous Post Link Plus",
"host": "wpackagist",
"repository": "wpackagist-plugin/ambrosite-nextprevious-post-link-plus",
"file": "ambrosite-post-link-plus.php",
"description": "Provides the base for the bicycle navigation"
}
]
},
"repositories":[
{
"type": "vcs",
"url": "https://github.com/dotherightthing/wpdtrt-contentsections"
},
{
"type": "composer",
"url": "https://wpackagist.org"
}
],
require-dev
Adding the plugin as a Composer dev dependency makes it available in a semi or fully automated unit testing environment.
require-wp
Adding the plugin as a WordPress dependency registers it with TGMPA (TGM Plugin Activation). This enables a notification and install/update flow in WP Admin.
This information is also used to load files for unit testing.
The additional description describes why the dependency is necessary.
repositories
This tells Composer to look for package in locations other than Packagist.
WP Unit
Example from ./tests/bootstrap.php
:
/**
* Manually load the plugin being tested, and any dependencies.
*/
function _manually_load_plugin() {
require dirname( dirname( __FILE__ ) ) . '/wpdtrt-foobar.php'; // Access static methods of plugin class.
$composer_json = dirname( dirname( __FILE__ ) ) . '/composer.json';
$composer_dependencies = WPDTRT_Foobar_Plugin::get_wp_composer_dependencies( $composer_json );
$composer_dependencies_to_require = WPDTRT_Foobar_Plugin::get_wp_composer_dependencies_wpunit( $composer_dependencies );
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );