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.
For starters, let's download a bunch of things:
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.
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.
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.
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:
ifconfig
(the inet
address)ln -s /opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/ plugins
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.
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:
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/