Getting Started Guide - octopus-digital-strategy/wp-barebones-plugin GitHub Wiki

The following steps will get you started in less than 5 minutes.

  1. Download the files to your local plugin directory
  2. Rename the directory from bare-bones-wp-plugin to YOUR-PLUGIN-NAME
  3. Customize your Plugin Name
  4. Change the Namespace
  5. Dump autoload
  6. Add styles and scripts as needed

###Steps 1 and 2

Right now you have 2 options to get this project Cloning the repository, or Download the current release.

###Cloning

From your terminal window

cd /path/to/your/plugins/directory/

git clone https://github.com/octopus-digital-strategy/barebones-wp-plugin.git

mv ./barebones-wp-plugin ./your-plugin-name


###Download

The steps 3 to X are equal for either od these options.

###Step 3 Customize Plugin Name

Open the file init.php within your plugin folder. Locate the first comments-block and customize it accordingly


/**
 * Plugin name: YOUR PLUGIN NAME
 * Plugin URI: http://LINKTOYOURPLUGIN.COM
 * Description: QUITE TO OBVIOUS
 * Version: 0.1
 * Author: YOUR NAME
 * Author URI: http://YOURWEBSITE.COM
 */


###Step 4. Change Namespace

To accomplish this task you have to locate 2 files. composer.json on the root of your plugin and SetupPlugin.class.php on the src/ directory

Change BareBonesPlugin to YourPluginNameSpace remember that in composer.json the namespace always ends with two forward slashes ** \ \ **

Finally open the init.php file on the root of your plugin folder. Change the Namespace before \YourPluginNameSpace\SetupPlugin()

REMEBER TO USE VALID NAMESPACES

###Step 5. Composer Install and Dump Autoload

You are almost ready to get coding. The only thing you have to do is run composer install and composer dump-autoload.


cd path/to/your/plugin/root

composer install; composer dump-autoload -o

The composer install command created the vendor directory, also some of the autoload files you will be using.

The composer dump-autoload -o command generates the class map for autoloading of the SetupPlugin class used on the init file. And all other classes with the proper PSR-4 within your src/ directory

Remember to run this last command every time you add a class.

###Step 6. Scripts and Styles

SetupPlugin.class.php contains code and files where you can place your scripts and styles out of the box.

If you want to add another resource like javascript, views, templates or files, add an extra folder on the resources/ directory and use the static method getResourceURL or getResourceDirectory to get a path to the file.