Axure 8 Tutorial: Quick and Easy Show and Hide Content with Link Text Change
How to add and remove WordPress theme unit test data with WP-CLI Aliases on Vagrant
This post was inspired by:
Warning: These instructions include importing, exporting and resetting (deleting) your WordPress database. If you have any important data, you should make a backup first before trying this. Proceed at your own risk. I am not responsible for any loss of data.
Let’s say you’re working on a WordPress site/theme in your development environment and you’ve set up some plugins and then you want to import the theme unit test data and work on your theme. When you’re done working on your theme, you want to remove all the theme unit test data and keep all your plugin settings and any other pages you made before you imported the test data. You can do this easily with WP-CLI. In this example I will show you how to do it using WP-CLI aliases.
This assumes you’re somewhat comfortable with the command line and you’re using Vagrant and you know how to ssh into your Vagrant server and navigate around the folders and find the folder that has your WordPress site.
Here’s the basic concept. First you will export your database as a backup that you will use later to restore (“removing” the theme unit test data). Then, you will download the theme unit test data xml file onto your remote Vagrant server. After that, you can use WP-CLI to install and activate the WordPress Importer plugin and activate it. Once that’s installed you can import the xml file. After you’ve done that, you will see all the test data posts and pages in your WordPress site. When you’re finished developing your theme, you can remove all the theme unit test data by importing your backup and your plugin settings etc. will be preserved.
Although I’m doing this with WP-CLI aliases, you can do it without, but I think aliases make it a lot easier. Make sure you have WP-CLI install on your host system and your remote Vagrant server.
Here’s the info on how to set up aliases:
http://wp-cli.org/commands/cli/alias/
It may take a little experimentation to get it working.
Now you’re ready to begin.
Step 1
Make a backup of your database. You will use this later to restore and remove all the them unit test data.
(I’ve named my development alias “development”)
wp @development db export mydatabase.sql
(You can name your sql filename anything you want.)
Step 2
Use cURL (curl) to download the theme-unit-test-data.xml file from WordPress onto your Vagrant server into a specifc folder.
ssh vagrant@yourdomainname.test 'cd ../../path/to/wordpress && { curl -O https://wpcom-themes.svn.automattic.com/demo/theme-unit-test-data.xml ; cd -; }'
Step 3
Install and activate the WordPress Import plugin.
wp @development plugin install wordpress-importer --activate
Step 4
Import theme-unit-test-data.xml.
wp @development import ./theme-unit-test-data.xml --authors=create
Now you should be able to go to your WordPress development site and see all the test posts and pages.
Step 5
After you’re finished developing your theme, you can remove all the theme unit test dat by resetting the database and importing the database backup from step 1.
wp @development db reset --yes wp @development db import mydatabase.sql