Tag: theme-development

  • Easily import DB using wp-cli

    Easily import DB using wp-cli

    I have been using Vagrant VVV for development on local for a long while now; havinng moved from XAMPP and PHPmyadmin for as long as I’ve been doing this stuff, moving to Vagrant presented me with a very real fear that I wouldn’t be able to easily setup local installs of live sites. With XAMPP I had always did a find & repace using the Search and Replace DB script, after importing the DB to the the local/development servers.

    It wasn’t perfect but served my needs for any db under 50MB. Sadly as I have been tasked with older installs and larger DBs that restriction has become problematic. Fortunately Vagrant once again steps in to save my butt.

    This is mostly a command line process but I promise it’s pretty basic, much faster than my previous mostly manual solution, and isn’t restricted to the PHPmyadmin file size limits. These steps while specific to Vagrant make use of the WP-CLI which is not specific to Vagrant. You could probably do this with XAMPP/MAMP and can definietly do this on your server if you set it up proper.

    WARNING

    If you are cloning a live site make sure you update your local wp-config.php file accordingly. Just copy the settings that Vagrant setup for you with the wp install.

    DB IMPORT IN VAGRANT

    This assumes you installed vagrant at the default location of vagrant-local

    1. Rename db
      Make sure that the db you will be importing is the same name as the db you will be importing into. So if your local site has a database name of EXAMPLE.sql you need to make sure that the db you will be imported also has the name of EXAMPLE.sql
    2. Move db
      Make a copy of the db you will be importing and move it to the root directory of the site you will be importing into./vagrant-local/www/EXAMPLE/
    3. ssh into vagrant
      cd vagrant-localvagrant ssh
    4. cd to site
      cd /srv/www/EXAMPLE
       
    5. Import db
      wp db import DATABASE.sql
    6. Search and Replace (optional)If you need to do a search and replace run the following command. It handles serialized data appropriately so you don’t bugger up your site.wp search-replace ‘http://example.com’ ‘http://example.dev’
    7. Celebrate 🎉
      Extra: Commands that start with wp make use of the WP-CLI which comes set up with vagrant. See http://wp-cli.org for more info and available commands.

      Vagrant does support PHPmyadmin at vvv.dev but the upload limit is actually lower than MAMP. This limit can be changed in your PHP.ini file but I really don’t think it’s worth doing with how much easier the command line method is.

      What tools do you use for your development environments? Do you have any favourites?

  • Installing Theme Unit Test Data with wp-cli

    Installing Theme Unit Test Data with wp-cli

    When building custom themes client sites it is important to test as many edge case as possible. Theme Unit Test Data is the way to go here and a minimum requirement for any professionally built WordPress theme (in my opinion anyway) If building a theme for the wordpress.org theme repository this will almost certainly be tested. For those using WP-CLI there is a quick and easy way to install and then remove this test data. Naturally, you will need to install and setup WP-CLI before proceeding.

    First you will want to backup your current database

    wp db export mydatabase.sql

    Then reset your WordPress installation. This step is not obligatory as you can import the test data on top of your own data. The --y flag stands for “yes” in response to the question “Are you sure you want to reset your database?” So make sure you have the old data backed up in case.

    wp db reset --yes

    Next you will want to import

     curl -O https://wpcom-themes.svn.automattic.com/demo/theme-unit-test-data.xml
    wp plugin install wordpress-importer --activate
    wp import ./theme-unit-test-data.xml --authors=create
    rm theme-unit-test-data.xml

    Here is where you will test you theme. Ideally you should go through and systematically check each of the links which have all sorts of edge cases. Correct any abnormalities and problems with layout. When you are finished you can change back to your old data.

    wp db reset --y
    wp db import mydatabase.sql

     

    Please note that you will have to provide the --url flag for some of those wp commands when using multisite. I am happy to answer any questions in the comments.