| 1 |
# WP Dependency Installer |
| 2 |
* Contributors: [](https://github.com/afragenAndy Fragen](https://github.com/afragen](https://github.com/afragen), [](https://github.com/mgibbs189Matt Gibbs](https://github.com/mgibbs189](https://github.com/mgibbs189), [](https://github.com/RarutoRaruto](https://github.com/Raruto](https://github.com/Raruto), [](https://github.com/afragen/wp-dependency-installer/graphs/contributorscontributors](https://github.com/afragen/wp-dependency-installer/graphs/contributors](https://github.com/afragen/wp-dependency-installer/graphs/contributors) |
| 3 |
* Tags: plugin, dependency, install |
| 4 |
* Requires at least: 5.1 |
| 5 |
* Requires PHP: 5.6 |
| 6 |
* Stable tag: master |
| 7 |
* Donate link: <https://thefragens.com/wp-dependency-installer-donate> |
| 8 |
* License: MIT |
| 9 |
|
| 10 |
This is a drop in class for developers to optionally or automatically install plugin dependencies for their own plugins or themes. It can install a plugin from wp.org, GitHub, Bitbucket, GitLab, Gitea, or a direct URL. |
| 11 |
|
| 12 |
[](https://github.com/afragen/wp-dependency-installer/wikiComprehensive information regarding WP Dependency Installer is available on the wiki.](https://github.com/afragen/wp-dependency-installer/wiki](https://github.com/afragen/wp-dependency-installer/wiki) |
| 13 |
|
| 14 |
See also: [](https://github.com/afragen/wp-dependency-installer-examplesexample plugin](https://github.com/afragen/wp-dependency-installer-examples](https://github.com/afragen/wp-dependency-installer-examples). |
| 15 |
|
| 16 |
## Description |
| 17 |
|
| 18 |
You can use **composer** to install this package within your WordPress plugin / theme. |
| 19 |
|
| 20 |
**Please ensure you are using the latest version of this framework in your `composer.json`** |
| 21 |
|
| 22 |
1. Within your plugin or theme root folder, run the following command: |
| 23 |
|
| 24 |
```shell |
| 25 |
composer require afragen/wp-dependency-installer |
| 26 |
``` |
| 27 |
|
| 28 |
2. Then create a sample [](https://github.com/afragen/wp-dependency-installer/wiki/Configuration#json-config-file-format**`wp-dependencies.json`**](https://github.com/afragen/wp-dependency-installer/wiki/Configuration#json-config-file-format](https://github.com/afragen/wp-dependency-installer/wiki/Configuration#json-config-file-format) file |
| 29 |
|
| 30 |
```js |
| 31 |
[ |
| 32 |
{ |
| 33 |
"name": "Git Updater", |
| 34 |
"host": "github", |
| 35 |
"slug": "git-updater/git-updater.php", |
| 36 |
"uri": "afragen/git-updater", |
| 37 |
"branch": "develop", |
| 38 |
"required": true, |
| 39 |
"token": null |
| 40 |
}, |
| 41 |
{ |
| 42 |
"name": "Query Monitor", |
| 43 |
"host": "wordpress", |
| 44 |
"slug": "query-monitor/query-monitor.php", |
| 45 |
"uri": "https://wordpress.org/plugins/query-monitor/", |
| 46 |
"optional": true |
| 47 |
}, |
| 48 |
{ |
| 49 |
"name": "Local Development", |
| 50 |
"host": "wordpress", |
| 51 |
"slug": "local-development/local-development.php", |
| 52 |
"uri": "https://wordpress.org/plugins/local-development/", |
| 53 |
"required": true |
| 54 |
} |
| 55 |
] |
| 56 |
``` |
| 57 |
|
| 58 |
You will then need to update `wp-dependencies.json` to suit your requirements. |
| 59 |
|
| 60 |
3. Finally add the following lines to your plugin or theme's `functions.php` file: |
| 61 |
|
| 62 |
```php |
| 63 |
require_once __DIR__ . '/vendor/autoload.php'; |
| 64 |
add_action( 'plugins_loaded', function() { |
| 65 |
WP_Dependency_Installer::instance( __DIR__ )->run(); |
| 66 |
}); |
| 67 |
``` |
| 68 |
|
| 69 |
`WP_Dependency_Installer` should be loaded via an action hook like `plugins_loaded` or `init` to function properly as it requires `wp-includes/pluggable.php` to be loaded for `wp_create_nonce()`. |
| 70 |
|
| 71 |
4. (optional) Take a look at some of built in [](https://github.com/afragen/wp-dependency-installer/wiki/Actions-and-HooksHooks](https://github.com/afragen/wp-dependency-installer/wiki/Actions-and-Hooks](https://github.com/afragen/wp-dependency-installer/wiki/Actions-and-Hooks) and [](https://github.com/afragen/wp-dependency-installer/wiki/Helper-FunctionsFunctions](https://github.com/afragen/wp-dependency-installer/wiki/Helper-Functions](https://github.com/afragen/wp-dependency-installer/wiki/Helper-Functions) to further customize your plugin look and behaviour: |
| 72 |
|
| 73 |
That's it, happy blogging! |
| 74 |
|
| 75 |
## Development |
| 76 |
|
| 77 |
PRs are welcome against the `develop` branch. |
| 78 |
|