WordPress WP-CLI Scaffolding: Generating Plugins, Blocks, and Tests

WP-CLI’s scaffold command generates boilerplate for plugins, child themes, post types, taxonomies, unit tests, and — with the @wordpress/create-block scaffolder — complete Gutenberg blocks. Using scaffolding instead of copy-pasting ensures consistent file structure, correct headers, and ready-to-run PHPUnit configurations from the first commit.

Problem: Setting up a new WordPress plugin or block from scratch requires manually creating the directory structure, registering the plugin header, configuring composer.json, setting up webpack.config.js, and adding block registration boilerplate — all before writing a single line of business logic.

Solution: Use WP-CLI scaffolding commands: wp scaffold plugin my-plugin generates the full plugin structure with PHPUnit setup, and wp scaffold block my-block --plugin=my-plugin generates a Gutenberg block with block.json, JavaScript entry point, and PHP registration. Use @wordpress/create-block for more modern block scaffolding with npm init @wordpress/block.


The commands below scaffold a plugin with PHPUnit tests, a custom post type and taxonomy, a block via the official block scaffolder, and a child theme — along with the flags that control the output.


# 1. Scaffold a plugin skeleton with PHPUnit bootstrap
wp scaffold plugin my-awesome-plugin \
    --plugin_name="My Awesome Plugin" \
    --plugin_description="Does awesome things." \
    --plugin_author="Your Name" \
    --plugin_author_uri="https://example.com" \
    --plugin_uri="https://example.com/my-plugin" \
    --activate

# 2. Add PHPUnit tests to an existing plugin
wp scaffold plugin-tests my-awesome-plugin
# Creates: bin/install-wp-tests.sh, phpunit.xml.dist, tests/bootstrap.php, tests/test-sample.php

# 3. Scaffold a custom post type (adds code to the plugin)
wp scaffold post-type project \
    --label="Project" \
    --plugin=my-awesome-plugin \
    --dashicon=dashicons-portfolio \
    --textdomain=my-awesome-plugin

# 4. Scaffold a taxonomy
wp scaffold taxonomy project-type \
    --label="Project Type" \
    --post_types=project \
    --plugin=my-awesome-plugin

# 5. Scaffold a Gutenberg block (uses @wordpress/create-block internally)
cd wp-content/plugins/my-awesome-plugin
npx @wordpress/create-block@latest feature-highlight \
    --namespace my-plugin \
    --title "Feature Highlight" \
    --category widgets \
    --short-description "Highlights a feature with icon and text"

# 6. Scaffold a child theme
wp scaffold child-theme my-child-theme \
    --parent_theme=twentytwentyfive \
    --theme_name="My Child Theme" \
    --author="Your Name" \
    --activate

# 7. Run the generated tests
cd wp-content/plugins/my-awesome-plugin
bash bin/install-wp-tests.sh wordpress_test root '' localhost latest
./vendor/bin/phpunit


NOTE: The install-wp-tests.sh script downloads a full WordPress test suite and creates a test database — run it once per machine, not on every CI build; cache the /tmp/wordpress-tests-lib directory in your CI pipeline to avoid repeated downloads.