Scaffold WordPress plugins using WP-CLI commands (wp scaffold plugin, wp scaffold plugin-tests). Use this skill when creating new WordPress plugins or adding test infrastructure to existing plugins.
This skill provides guidance for scaffolding WordPress plugins using WP-CLI's scaffold commands. It supports both creating new plugins from scratch and adding test infrastructure to existing plugins.
Note: This skill works seamlessly with the wp-env skill (if available). When wp-env setup or management is needed, activate the wp-env skill for comprehensive environment handling.
WP-CLI provides two primary scaffolding commands for plugin development:
Generates starter code for a new plugin, including:
readme.txt for WordPress.orgpackage.json with Grunt tasks for i18n and readme conversion.editorconfig, .gitignore, .distignore)Adds PHPUnit test infrastructure to an existing plugin, including:
phpunit.xml.dist configurationbin/install-wp-tests.sh for WordPress test suite setuptests/bootstrap.php to activate the plugin during teststests/test-sample.php with example test cases.phpcs.xml.dist for PHP_CodeSniffer rulesVerify WP-CLI is installed and accessible:
wp --version
If WP-CLI is not installed, see references/wp-cli-installation.md for comprehensive installation instructions across all platforms.
IMPORTANT: Before running any scaffold commands, detect which WordPress environment is available:
Check for existing WordPress installation (preferred):
wp core version 2>/dev/null
wp scaffold plugin directlyCheck for wp-env configuration:
# Look for wp-env config files
[ -f .wp-env.json ] || [ -f .wp-env.override.json ]
wp-env run cli wp scaffold pluginCheck for wp-env availability (fallback):
wp-env --version 2>/dev/null
No environment available (error):
--path flagBased on detection, use the appropriate command prefix throughout this skill:
wp scaffold pluginwp-env run cli wp scaffold pluginAll examples below show the base command. Prepend wp-env run cli when using wp-env.
When creating a new WordPress plugin, follow this interactive workflow:
Collect the following information from the user, offering smart defaults:
Plugin slug (required) - Internal name, lowercase with hyphens
Plugin name - Display name for the plugin header
Plugin description - What the plugin does
Plugin author - Author name
git config user.name if availablePlugin author URI - Author website URL
git config user.url if available, otherwise skipPlugin URI - Plugin project URL
Ask the user about these options:
Include tests? - Whether to generate PHPUnit test files
--skip-tests flag to omitCI provider - Which continuous integration service to use
circle (default), github, gitlab, bitbucket--ci=<provider> flagTarget directory - Where to create the plugin
--dir=<path> to specify custom locationBuild the wp scaffold plugin command with gathered information:
wp scaffold plugin <slug> \
--plugin_name="<name>" \
--plugin_description="<description>" \
--plugin_author="<author>" \
--plugin_author_uri="<author-uri>" \
--plugin_uri="<plugin-uri>" \
--ci=<provider>
Add --skip-tests if user declined test files.
Add --dir=<path> if custom directory specified.
After successfully scaffolding the plugin:
Verify creation - Confirm files were generated:
ls -la <plugin-directory>
Ask about activation - If wp-env is running, offer to activate:
wp-env run cli wp plugin activate <slug>wp-env run cli wp plugin activate <slug> --networkNext steps guidance - Inform user about:
<slug>/<slug>.phpwp-env run tests-cli --env-cwd=wp-content/plugins/<slug> phpunitnpm run readme, npm run i18nWhen adding test infrastructure to an existing plugin:
Determine which plugin needs tests:
--dir if non-standard)Ask which CI service the user wants:
circle (default), github, gitlab, bitbucketRun the scaffold plugin-tests command:
# Standard plugin location
wp scaffold plugin-tests <plugin-slug> --ci=<provider>
# Non-standard location
wp scaffold plugin-tests --dir=<path/to/plugin> --ci=<provider>
Add --force flag to overwrite existing test files if needed.
After generating test files:
Set up test environment - Guide user through test setup:
# Install WordPress test suite (if not using wp-env)
bash bin/install-wp-tests.sh wordpress_test root password localhost latest
# Or use wp-env for testing
wp-env run tests-cli --env-cwd=wp-content/plugins/<slug> phpunit
Verify test execution - Run the sample test:
wp-env run tests-cli --env-cwd=wp-content/plugins/<slug> phpunit
Next steps - Inform user about:
tests/ directory| Option | Description | Example |
|---|---|---|
--skip-tests |
Don't generate PHPUnit test files | --skip-tests |
--ci=<provider> |
CI configuration (circle, github, gitlab, bitbucket) | --ci=github |
--activate |
Activate plugin after creation | --activate |
--activate-network |
Network activate plugin after creation | --activate-network |
--force |
Overwrite existing files | --force |
--dir=<path> |
Custom directory for plugin | --dir=/custom/path |
Note: --activate and --activate-network flags work with local wp-cli WordPress installations but not with wp-env. For wp-env, use wp-env run cli wp plugin activate instead.
my-contact-form, analytics-dashboard, custom-post-typesSkip tests (--skip-tests) only when:
wp scaffold plugin-testsAlways include tests for:
Choose a CI provider based on your repository host:
--ci=github (GitHub Actions)--ci=gitlab (GitLab CI)--ci=bitbucket (Bitbucket Pipelines)--ci=circle (CircleCI)When developing with wp-env:
Scaffold inside wp-env directory structure:
# Create plugin in wp-env's plugin directory
cd /path/to/wp-env-project
wp scaffold plugin my-plugin --dir=plugins/
Or scaffold separately and configure .wp-env.json:
{
"plugins": [".", "../other-plugin"]
}
Activate after scaffolding:
wp-env run cli wp plugin activate my-plugin
Run tests in wp-env:
wp-env run tests-cli --env-cwd=wp-content/plugins/my-plugin phpunit
User: "Create a new WordPress plugin called 'site-analytics' for tracking visitor analytics"
Process:
wp scaffold plugin site-analytics --plugin_name="Site Analytics" --plugin_description="Track visitor analytics and generate reports" --plugin_author="Em" --ci=githubUser: "Add tests to my existing 'custom-widgets' plugin"
Process:
wp scaffold plugin-tests custom-widgets --ci=github