## # Installing Plugins
#### Why configure plugins in Composer instead of giving users control? On a managed WordPress project:
* Users should not be able to update, delete, or add plugins which haven't been tested locally or on a testing server. * A plugin may work on its own, but in conjunction with other dependencies, there may be conflicts leading to errors and the famous 'blank screen'. Developers should first test for conflicts. * Anything that breaks on the site, even if it's because of the client, will need to be found and fixed by the developer.
Therefore, configuring plugins through Composer prevents potential issues. All a user can can do, is activate or deactivate plugins. We can thus make decisions about which plugins should be used.
#### WPackagist We can add WordPress plugins that feature on the WordPress website https://en-gb.wordpress.org/plugins using Composer. But we have to do it through the a different repository called [WPackagist](https://wpackagist.org/). It features features both plugins and themes. The instructions on WPackagist are simple, but I'll feature them here:

### # First, tell Composer to look for packages in WPackagist ``` > composer.json ``` ```json { "repositories":[ { "type":"composer", "url":"https://wpackagist.org" } ] } ```
#### Repository type > Normally Composer will look within the default [Packagist](https://packagist.org/) repository. However, Composer allows us to define [custom repositories](https://getcomposer.org/doc/05-repositories.md), even using Git projects or zip files.

### # Set the custom install path for the plugin's directory ``` > composer.json ``` ```json { "extra": { "installer-paths": { "public/wp-content/plugins/{$name}": ["type:wordpress-plugin"] } } } ```
#### The extra block > This contains custom **installer-paths** configurations. A plugin with a Composer package type of **wordpress-plugin** would be identified by Composer, and installed into the directory defined with its **project name** using the `{$name}` identifier.

### # Configure a plugin and its version In WPackagist, you can search for packages. Clicking on the version number gives you the exact line you need to add to the require block of the Composer file. ![enter image description here](https://snag.gy/Jbfv47.jpg)

#### Example: installing the Yoast plugin Here's an example with the WordPress SEO (aka Yoast) plugin. ``` > composer.json ``` ``` "require": { "johnpbloch/wordpress": "~4", "wpackagist-plugin/wordpress-seo": "7.*" } ``` > By changing the version to `7.*`, it will install the latest within version 7 for that plugin, rather than the specific version.

Run a composer update ``` $ composer update ```

Our folder structure should now look like this: ```yml root |-- composer.json |-- composer.lock |-- public |-- wordpress |-- wp-content |-- plugins |-- wordpress-seo # The installed plugin |-- themes |-- uploads |-- vendor ```