This repository was archived by the owner on Nov 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Options: Adding WordPress plugin dependencies
Dan Smith edited this page Sep 6, 2019
·
15 revisions
DTRT WordPress Plugin Boilerplate supports user-configurable plugin dependencies.
- 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)
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"
}
],
Adding the plugin as a Composer dev dependency makes it available in a semi or fully automated unit testing environment.
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.
This tells Composer to look for package in locations other than Packagist.
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' );