Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Scaffold Command Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation: No additional installation required—this package ships with WP-CLI.

    wp --info | grep scaffold-command  # Verify inclusion
    
  2. First Use Case: Generate a basic plugin scaffold:

    wp scaffold plugin my-first-plugin
    

    This creates a fully functional plugin skeleton with:

    • Main plugin file (my-first-plugin.php)
    • Test suite (phpunit.xml.dist, tests/)
    • Build tools (Gruntfile.js, package.json)
    • Documentation (readme.txt)
  3. Key Commands to Explore:

    • wp scaffold _s my-theme → Underscores starter theme
    • wp scaffold post-type movie --theme=my-theme → Custom post type
    • wp scaffold taxonomy genre --post_types=movie → Custom taxonomy

Where to Look First

  • Documentation: Run wp help scaffold for interactive CLI help.
  • Templates: Inspect generated files in /wp-content/plugins/ or /wp-content/themes/ to understand structure.
  • Underscores: For themes, visit underscores.me for reference.

Implementation Patterns

Core Workflows

1. Plugin Development

# 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:

  • Edit my-plugin.php for core logic.
  • Use Gruntfile.js for tasks (e.g., grunt i18n for translations).
  • Run tests:
    ./bin/install-wp-tests.sh
    composer test
    

2. Theme Development

# 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:

  • Customize style.css (theme metadata).
  • Extend functions.php for theme logic.
  • Use SASS (if --sassify flag was set) via node-sass or dart-sass.

3. Custom Post Types/Taxonomies

# 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:

  • Hooks: Use register_post_type_args filters to modify generated args.
  • Templates: Pair with wp generate template for custom templates.
  • REST API: Extend with register_rest_route in the generated file.

4. Testing

# Plugin tests
wp scaffold plugin-tests my-plugin --ci=circle

# Theme tests
wp scaffold theme-tests my-theme

Test Workflow:

  1. Set WP_TESTS_DIR in tests/bootstrap.php.
  2. Run:
    composer test
    
  3. Debug with:
    WP_DEBUG=1 WP_DEBUG_LOG=/tmp/debug.log composer test
    

Integration Tips

  1. Version Control:

    • Commit generated scaffolds to version control (they’re opinionated but functional).
    • Use .gitignore templates provided (e.g., ignore node_modules/).
  2. Local Development:

    • Use wp scaffold --force to regenerate files during development.
    • For themes/plugins, symlink to /wp-content/:
      ln -s /path/to/my-plugin /wp-content/plugins/
      
  3. CI/CD:

    • Leverage generated CI configs (e.g., .circleci/config.yml).
    • Add test steps to your pipeline:
      # Example GitHub Actions step
      - name: Run tests
        run: composer test
      
  4. Extending Scaffolds:

    • Override templates by copying from wp-cli/scaffold-command/src/Templates/ to your project.
    • Example: Copy post-type.php.twig to customize post type generation.

Gotchas and Tips

Pitfalls

  1. File Overwrites:

    • --force flag is destructive. Use with caution in shared environments.
    • Fix: Backup directories before scaffolding:
      cp -r /wp-content/plugins/my-plugin /tmp/my-plugin-backup
      
  2. Path Conflicts:

    • Plugins/themes with hyphens (my-plugin) may cause issues on some systems.
    • Fix: Use underscores (my_plugin) or verify paths post-generation.
  3. PHP Version Mismatches:

    • Generated composer.json may target PHP 7.4+. Ensure your server matches.
    • Fix: Update composer.json or use a .php-version file.
  4. Underscores Theme Quirks:

    • --sassify requires Node.js. Install dependencies:
      cd /wp-content/themes/my-theme && npm install
      
    • Fix: Add npm install to your deployment script.
  5. Test Environment Issues:

    • WP_TESTS_DIR must point to a WordPress install. Use:
      export WP_TESTS_DIR=/path/to/wordpress-develop
      
    • Fix: Clone WordPress to a known location and reference it.

Debugging

  1. Command Errors:

    • Run with --debug for verbose output:
      wp scaffold plugin my-plugin --debug
      
    • Check WP-CLI logs at ~/.wp-cli/logs/.
  2. Template Issues:

    • Inspect generated files against the source templates.
    • Tip: Use wp scaffold --raw to debug registration code without wrappers.
  3. Permission Problems:

    • Ensure /wp-content/ is writable:
      chown -R www-data:www-data /wp-content
      chmod -R 755 /wp-content
      

Extension Points

  1. Custom Templates:

    • Override templates by placing them in ~/.wp-cli/templates/ or your project root.
    • Example: Create ~/.wp-cli/templates/post-type.php.twig to modify post type generation.
  2. Post-Generation Hooks:

    • Use 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
      });
      
  3. Dynamic Values:

    • Pass environment variables to templates:
      export MY_CUSTOM_VAR="value"
      wp scaffold plugin my-plugin --env=MY_CUSTOM_VAR
      
    • Access in templates via {{ env.MY_CUSTOM_VAR }}.

Pro Tips

  1. 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.

  2. Dry Runs: Redirect output to a file to preview changes:

    wp scaffold post-type movie --theme=my-theme > /tmp/movie-cpt.php
    
  3. Multi-Environment Setups: Use --dir to scaffold in non-standard locations:

    wp scaffold plugin my-plugin --dir=/custom/path/
    
  4. 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
    
  5. Composer Autoloading: After scaffolding, run:

    composer dump-autoload
    

    To ensure new files are autoloaded.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views