An Opinionated Guide to WordPress Plugin Development

Dimitris Glezos
June 24, 2015
5 min read

After creating our own WordPress multilingual plugin, we wanted to share some information about how we developed it. This guide runs you through the basics to set up a PHP development environment for plugin development. Many steps in this guide are intended for Mac OSX systems running WordPress on a virtual Ubuntu server. If you are attempting to follow this on a different platform, the steps might be different.

What you will need

For starters, let’s download a bunch of things:

Getting WordPress running on your local Virtual Machine

The first task is to get WordPress up and running locally from the image. Following the steps from Bitnami, you should be able to easily import the image.
One key item to note at this point…make sure you are connected to a network with internet access. The VM will setup itself with ‘Bridged’ networking initially, so it needs an external DNS. I’ll address working offline later.

Also reference the following FAQ from Bitnami.

The cloud setup will be slightly different, so be sure you are on the ‘Virtual Appliance’ FAQ.

WordPress dev

If you chose VirtualBox

After you have installed and launched VirtualBox, go to File > Import Appliance, and navigate to the folder of your extracted VM image and import it.

In the next window, allocate at least 2048 MB of RAM.

Next up: starting the VM!

If you get the WRITE SAME failed. Manually zeroing error, just wait. It will eventually boot to the OS.

Note: If the default login credentials don’t work, try bitnami for the username and password. Also, if prompted to change the password, change it to whatever you like.

Set up a repository and Git Client

If you don’t have any existing plugin code, create a new project on GitHub. Then generate your plugin boilerplate here: http://wppb.me/.

The boilerplate generator will create 2 directories: 1 for your assets which will be displayed on the WordPress plugin page , and another for your plugin. I recommend creating two separate projects for these directories. Right now, we are only focused on the plugin code.

Getting the IDE setup, and sFTP access

At this point, go ahead and install NetBeans; you’ll also need to set up Firefox with the FireFTP plugin.
We are SO close to being able to do something productive!

Just a few more quick setup tasks:

  • Shell into the VM as ‘bitnami’ user (you can use console or set up SSH).
    • Enable SSH in the VM
    • The VM’s IP address can be found using ifconfig (the inet address)
  • Make a symbolic link to the WordPress plugin directory as it’s somewhat hidden in Bitnami’s special paths.
    ln -s /opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/ plugins
  • Now, set up your sFTP connection. I recommend just using the IP address displayed on the VM console screen, and the ‘bitnami’ user. (Note: You can create separate users for security purposes…but it’s easy to lose track if you have many vms)
  • While still inside the FireFTP console, navigate on the left pane to your boilerplate plugin (WPPB.me) and copy the plugin directory over to the VM.
  • Finally! You can now log in to WordPress and activate your plugin! The default WordPress login info is ‘user’ / ‘bitnami’

Advanced topics

Getting unit tests setup

You’ll need to set up PHPUnit and WP-CLI on the VM.

To install PHPunit:

wget https://phar.phpunit.de/phpunit.phar
chmod +x phpunit.phar
sudo mv phpunit.phar /usr/local/bin/phpunit

For additional info: https://github.com/sebastianbergmann/phpunit#installation.

To install WP-CLI (similiar to PHPUnit):

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

For additional info: http://wp-cli.org/.

If you have existing tests…simply go to your plugin directory and run the WP-CLI initialization script:

sudo ./bin/install-wp-tests.sh wordpress_test <mysql root user> <mysql root user password> localhost

Now, if everything is good and the starts aligned for you…simply run:

phpunit

If you are working on a project that needs tests setup, there’s a few more steps which I’m not going to cover here. Instead, please refer to WP-CLI docs here.

Working offline

When you are not connected to a network, this setup doesn’t work since the WordPress Virtual Machine can’t get an IP address to support a local connection. In this case, you will need to setup ‘host-only networking’. For Virtual Box, this is fairly straightforward…although you do need to take some extra configuration steps.

Unfortunately, the VirtualBox documentation isn’t completely clear. I’ll break it down quickly here:

  • Create the host-only loopback device. The management console will default to ‘vboxnet0’ which is fine. Be sure to turn DHCP server on. This will prevent you from having to change networking on the guest.
  • Now you will be able to flip from bridged to host-only in your Virtual Machine’s settings panel.
  • Be sure to reboot the VM so that the virtual hardware settings are updated and you will get a new IP address on the virtual machine’s console.

If you found this guide useful, please check out our WordPress plugin that helps you to quickly translate your website or blog: https://wordpress.org/plugins/transifex-live-integration/

TRANSIFEX
Start your localization journey
Bring your brand to the world and create global experiences with the power of AI
FREE TRIAL
Dimitris Glezos
FacebookgithubGoogle+Fill 88Twitter