Author: admin

  • Testing WordPress plugins with wp-env

    Testing WordPress plugins on a live site can go very wrong! I have discovered a simple way to test WordPress plugins locally: wp-env. This CLI tool makes it really easy to create an instance of a docker container which runs the latest verson of WordPress.

    To add wp-env as a local developer dependency:

    npm i @wordpress/env --save-dev

    Set-up

    I recommend creating a config file for wp-env. If you have a repo where you are developing a plugin, then use something like the following in your .wp-env.json file. This example tells wp-env that you are working on two plugins, and lists the directories which contain the plugin files:

    {
        "$schema": "https://schemas.wp.org/trunk/wp-env.json",
        "plugins": [
            "./tdp-plugin-1",
            "./tdp-plugin-2"
        ]
    }

    Running wp-env

    The command to start up the WordPress containers is:

    npx wp-env start

    Once the containers are up and running, you should be able to access the WordPress site at localhost:8888. The default username and password are admin and password! The plugins should be pre-installed and ready for testing.

    The command to stop the containers is:

    npx wp-env stop

    References