WordPress plugin project structure

WordPress plugin project structure

Explorer

  • .git…
  • binnew
  • seed-demo-content.shnew
  • build…, not committed
  • includesnew
  • Plugin.phpnew
  • Lifecycle.phpnew
  • languagesnew
  • simple-reviews.potnew
  • node_modules…, not committed
  • src
  • templatesnew
  • testsnew
  • vendor…new, not committed
  • .editorconfig
  • .gitignore
  • .nvmrcnew
  • .wp-env.json
  • .wp-env.override.jsonnew, not committed
  • composer.jsonnew
  • composer.locknew
  • package.json
  • package-lock.json
  • phpcs.xml.distnew
  • phpstan.neon.distnew
  • phpunit.xml.distnew
  • README.mdnew
  • readme.txt
  • simple-reviews.php
  • uninstall.phpnew
  • webpack.config.jsnew
  1. # Scaffold the plugin with a dynamic block and a wp-env config (needs Node and Docker)

    npx @wordpress/create-block@latest simple-reviews --variant dynamic --wp-env
  2. # Start a local WordPress with the plugin active (http://localhost:8888, admin / password)

    cd simple-reviews && npx wp-env start
  3. # Rebuild blocks on every save

    npm start
  4. # Add a second block to the same plugin

    cd src && npx @wordpress/create-block@latest review-form --no-plugin --variant dynamic
  5. # Add Composer autoloading, coding standards, static analysis and the test suite

    composer require --dev wp-coding-standards/wpcs szepeviktor/phpstan-wordpress wp-phpunit/wp-phpunit yoast/phpunit-polyfills "phpunit/phpunit:^9.6"
  6. # Run the PHP tests inside the wp-env tests container

    npx wp-env run tests-cli --env-cwd=wp-content/plugins/simple-reviews vendor/bin/phpunit
  7. # Build the release zip using package.json "files"

    npm run build && npm run plugin-zip