Skip to content

Using the plugin boilerplate in Varying Vagrant Vagrants (VVV)

Mark Heydon edited this page Oct 17, 2018 · 1 revision

Overview

These are the steps to get the boilerplate plugin code installed in the wp-content/plugins directory of a local project in your vagrant-local folder ready to use for development. These instructions were written using version 2.2.1 of VVV and assume your vagrant-local directory is installed in '~' as per the VVV installation instructions.

Replace folder paths as needed for your particular setup, and replace 'my-plugin' with the name of the plugin you are creating.

Script

The following commands are all run within the virtual machine, so 'vagrant ssh' before running.

# 'cd' to the plugins folder where you are developing; then
# get the latest version of the boilerplate from GitHub.
cd /srv/www/wordpress-default/public_html/wp-content/plugins
git clone https://github.com/DevinVinson/WordPress-Plugin-Boilerplate.git

# re-arrange folder structure for plugin development
mv WordPress-Plugin-Boilerplate/plugin-name ./my-plugin
rm -fr WordPress-Plugin-Boilerplate
cd my-plugin

# Rename various files to the new plugin name
mv plugin-name.php my-plugin.php
rename 's/plugin-name/my-plugin/' **/*
rename 's/plugin-name/my-plugin/' **/**/*
rename 's/plugin-name/my-plugin/' **/**/**/*

# Rename various references to the new plugin name
find . -name "*.php" -exec sed -i 's/plugin-name/my-plugin/g' {} \;
find . -name "*.php" -exec sed -i 's/Plugin_Name/My_Plugin/g' {} \;
find . -name "*.php" -exec sed -i 's/plugin_name/my_plugin/g' {} \;
find . -name "*.php" -exec sed -i 's/PLUGIN_NAME/MY_PLUGIN/g' {} \;

find . -name "*.txt" -exec sed -i 's/plugin-name/my-plugin/g' {} \;
find . -name "*.txt" -exec sed -i 's/plugin_name/my_plugin/g' {} \;

What did we just do?

The above script does the following:

  • Gets the latest version of the boilerplate from the repository.
  • Re-structures the folder to standard plugin format and remove the git repository.
  • Rename all files to the new plugin name.
  • Replace all references of "Plugin Name" to the new plugin name.

Optional steps

Test plugin activiates and de-activates using WP-CLI

The following should run without any errors.

wp plugin activate my-plugin && wp plugin deactivate my-plugin

Set up git

Set up a new git repo for the plugin development.

git init
git add --all
git commit -m "Initial commit"