wp-cli/scaffold-command
WP-CLI scaffold-command generates boilerplate code for WordPress: plugins, themes (including _s/Underscores), child themes, blocks, post types, and taxonomies. Create ready-to-customize files fast, with options like activation, network enablement, and overwriting.
Installation: No additional installation required—this package ships with WP-CLI.
wp --info | grep scaffold-command # Verify inclusion
First Use Case: Generate a basic plugin scaffold:
wp scaffold plugin my-first-plugin
This creates a fully functional plugin skeleton with:
my-first-plugin.php)phpunit.xml.dist, tests/)Gruntfile.js, package.json)readme.txt)Key Commands to Explore:
wp scaffold _s my-theme → Underscores starter themewp scaffold post-type movie --theme=my-theme → Custom post typewp scaffold taxonomy genre --post_types=movie → Custom taxonomywp help scaffold for interactive CLI help./wp-content/plugins/ or /wp-content/themes/ to understand structure.# Standard workflow
wp scaffold plugin my-plugin \
--plugin_name="My Plugin" \
--plugin_description="Does amazing things" \
--plugin_author="Jane Doe" \
--activate
# With CI/CD (GitHub Actions)
wp scaffold plugin my-plugin --ci=github
Post-Generation Steps:
my-plugin.php for core logic.Gruntfile.js for tasks (e.g., grunt i18n for translations)../bin/install-wp-tests.sh
composer test
# Underscores starter theme
wp scaffold _s my-theme \
--theme_name="My Theme" \
--author="Jane Doe" \
--sassify \
--woocommerce
# Child theme
wp scaffold child-theme my-child-theme \
--parent_theme=twentyseventeen \
--activate
Post-Generation Steps:
style.css (theme metadata).functions.php for theme logic.--sassify flag was set) via node-sass or dart-sass.# In a theme
wp scaffold post-type portfolio \
--label="Portfolio Item" \
--dashicon="portfolio" \
--theme=my-theme
# In a plugin
wp scaffold taxonomy skill \
--post_types=portfolio \
--label="Skill" \
--plugin=my-plugin
Integration Tips:
register_post_type_args filters to modify generated args.wp generate template for custom templates.register_rest_route in the generated file.# Plugin tests
wp scaffold plugin-tests my-plugin --ci=circle
# Theme tests
wp scaffold theme-tests my-theme
Test Workflow:
WP_TESTS_DIR in tests/bootstrap.php.composer test
WP_DEBUG=1 WP_DEBUG_LOG=/tmp/debug.log composer test
Version Control:
.gitignore templates provided (e.g., ignore node_modules/).Local Development:
wp scaffold --force to regenerate files during development./wp-content/:
ln -s /path/to/my-plugin /wp-content/plugins/
CI/CD:
.circleci/config.yml).# Example GitHub Actions step
- name: Run tests
run: composer test
Extending Scaffolds:
wp-cli/scaffold-command/src/Templates/ to your project.post-type.php.twig to customize post type generation.File Overwrites:
--force flag is destructive. Use with caution in shared environments.cp -r /wp-content/plugins/my-plugin /tmp/my-plugin-backup
Path Conflicts:
my-plugin) may cause issues on some systems.my_plugin) or verify paths post-generation.PHP Version Mismatches:
composer.json may target PHP 7.4+. Ensure your server matches.composer.json or use a .php-version file.Underscores Theme Quirks:
--sassify requires Node.js. Install dependencies:
cd /wp-content/themes/my-theme && npm install
npm install to your deployment script.Test Environment Issues:
WP_TESTS_DIR must point to a WordPress install. Use:
export WP_TESTS_DIR=/path/to/wordpress-develop
Command Errors:
--debug for verbose output:
wp scaffold plugin my-plugin --debug
~/.wp-cli/logs/.Template Issues:
wp scaffold --raw to debug registration code without wrappers.Permission Problems:
/wp-content/ is writable:
chown -R www-data:www-data /wp-content
chmod -R 755 /wp-content
Custom Templates:
~/.wp-cli/templates/ or your project root.~/.wp-cli/templates/post-type.php.twig to modify post type generation.Post-Generation Hooks:
wp-cli/scaffold-command's post-scaffold hook (undocumented but available):
add_action('wp-cli/scaffold-command/post-scaffold', function($command, $args) {
// Custom logic after scaffold
});
Dynamic Values:
export MY_CUSTOM_VAR="value"
wp scaffold plugin my-plugin --env=MY_CUSTOM_VAR
{{ env.MY_CUSTOM_VAR }}.Alias for Speed:
Add to ~/.wp-cli/config.yml:
aliases:
sp: scaffold plugin
st: scaffold _s
cpt: scaffold post-type
Now use wp sp my-plugin instead of wp scaffold plugin my-plugin.
Dry Runs: Redirect output to a file to preview changes:
wp scaffold post-type movie --theme=my-theme > /tmp/movie-cpt.php
Multi-Environment Setups:
Use --dir to scaffold in non-standard locations:
wp scaffold plugin my-plugin --dir=/custom/path/
Legacy WordPress:
For older WP versions (<5.0), use --raw to avoid compatibility issues:
wp scaffold post-type movie --raw > /wp-content/themes/my-theme/post-types/movie.php
Composer Autoloading: After scaffolding, run:
composer dump-autoload
To ensure new files are autoloaded.
How can I help you explore Laravel packages today?