# How to build a WordPress plugin using Lumen ## Do this: 1. Use [WP-CLI](http://wp-cli.org) to download a clean copy of WordPress: `wp download` 1. Run WordPress locally using [Laravel Valet](https://laravel.com/docs/5.3/valet) 1. Setup WordPress—use WP-CLI or the Web UI, doesn't matter 1. Install and activate the WP REST project: `wp plugin install rest-api && wp plugin activate rest-api` 1. Install Lumen globally: https://lumen.laravel.com/docs/5.3/installation 1. Create a new Lumen project in the **wp-content/plugins** folder: `lumen new {$pluginName}` 1. Copy in **config/app.php** and **config/database.php** (attached to this Gist) 1. Remove the contents of **app/Http/routes.php**—we'll be using the WP REST API for routing 1. Modify **bootstrap/app.php**: uncomment both `$app->withFacades();` and `$app->withEloquent();`, and add `$app->configure('app');` 1. Optionally, add my custom `Handler` implementation: copy `Handler.php` to **{$pluginName}/app/Exceptions**; this implementation turns Exceptions into JSON responses instead of marking them up with HTML 1. Copy **plugin.php** (attached to this Gist) to your plugin's path, e.g., **{$pluginName}/plugin.php**; this is your plugin's main file, where you'll build out your routes 1. Make sure to remove the `/vendor` entry from **.gitignore** so that if/when you distribute your WordPress plugin, it will ship with all the necessary dependencies ## Now you can do this: 1. Use Laravel's [Service Container](https://laravel.com/docs/5.3/container) to add complex functionality to your plugins: Event Broadcasting, Notifications, Caching, Queing, and Mail 1. Use Laravel's [Eloquent](https://laravel.com/docs/5.3/eloquent) ORM and [Migrations](https://laravel.com/docs/5.3/migrations) to rapidly build your plugin's model code 1. Run Laravel's artisan CLI tool through WP-CLI: `wp {$pluginName} {$artisanCmd} ...` 1. Build awesome things