Skip to main content
This guide will walk you through setting up a local development environment for contributing to or extending the Visual Portfolio plugin.

Prerequisites

Before you begin, ensure you have the following installed on your system:

Required Software

  • PHP >= 7.2 - Required for WordPress compatibility
  • Node.js >= 18.0 - For building JavaScript and CSS assets
  • Composer >= 2.0 - For PHP dependency management
  • Docker - For running the WordPress test environment
  • Git - For version control

Verify Installation

Check your versions:

Installation

1. Clone the Repository

2. Install Dependencies

Install both npm and Composer dependencies:
The npm install command will:
  • Install all npm packages
  • Set up Husky git hooks
  • Automatically run composer install

3. Configure Git Hooks

Git hooks are automatically configured via Husky during npm install. These hooks run: Pre-commit:
  • PHP CodeSniffer (WPCS)
  • ESLint (JavaScript)
  • Stylelint (SCSS)
Pre-push:
  • Additional lint checks
  • Ensure code quality before pushing

Development Commands

Build Commands

Start Development Mode

Run webpack in watch mode with hot module replacement:
This command:
  • Watches for file changes
  • Automatically rebuilds assets
  • Enables hot module replacement
  • Shows detailed progress
  • Generates source maps for debugging

Build for Development

Create a one-time development build:
This generates unminified assets with source maps in the build/ directory.

Build for Production

⚠️ Warning: This command:
  • Generates translation files (.pot and .json)
  • Builds minified production assets
  • Creates a plugin zip file
  • Should only be run for releases
Do not run build:prod during regular development.

Code Quality

Linting

Check code quality without making changes:

Auto-Fixing

Automatically fix linting issues:

Testing

WordPress Test Environment

Visual Portfolio uses wp-env (WordPress’s official testing environment powered by Docker):
After starting the environment:

Running Tests

Note: Ensure wp-env is running before executing tests:

Development Workflow

Typical Development Session

  1. Start development build:
  2. Start WordPress environment (in another terminal):
  3. Make your changes to PHP, JavaScript, or SCSS files
  4. Test your changes in the browser at http://localhost:8888
  5. Run linters before committing:
  6. Commit your changes (hooks will run automatically):

Working with PHP

When modifying PHP files:
  1. Edit the file in classes/ or main plugin file
  2. Always run PHP linter after changes:
  3. Fix any issues reported by WPCS:
  4. Refresh the WordPress site to see changes

Working with JavaScript

When modifying JavaScript files in assets/js/ or gutenberg/:
  1. Edit the file with ES6+ syntax
  2. Webpack auto-rebuilds (if npm run dev is running)
  3. Check browser console for errors
  4. Run linter:
  5. Auto-fix issues:

Working with SCSS

When modifying styles in assets/css/, gutenberg/, or templates/:
  1. Edit the .scss file
  2. Webpack auto-rebuilds CSS (if npm run dev is running)
  3. Check browser for style changes
  4. Run linter:
  5. Auto-fix issues:

Working with Gutenberg Blocks

For React components in gutenberg/:
  1. Edit React component files
  2. Webpack auto-rebuilds (if npm run dev is running)
  3. Refresh the block editor to see changes
  4. Check browser console for React errors
  5. Test in block editor at http://localhost:8888/wp-admin/post-new.php

Build Output

Webpack compiles source files into the build/ directory:
Do not edit files in build/ directly - they will be overwritten. Always edit source files in:
  • assets/ for CSS and JavaScript
  • gutenberg/ for React components
  • classes/ for PHP

Debugging

Enable WordPress Debug Mode

Edit wp-config.php in your wp-env environment:

Source Maps

Development builds include source maps for debugging:
  • JavaScript: build/*.js.map
  • CSS: build/*.css.map
Use browser DevTools to debug with original source files.

PHP Debugging

Add debug output:
View logs:

Troubleshooting

Port Already in Use

If port 8888 is already in use:

Node Modules Issues

If you encounter dependency issues:

Composer Issues

If PHP dependencies are problematic:

wp-env Issues

Reset the WordPress environment:

Build Issues

Clear webpack cache:

IDE Configuration

VS Code

The project includes VS Code settings in .vscode/:
  • ESLint integration
  • Stylelint integration
  • PHP formatting
  • Recommended extensions
Install recommended extensions when prompted.

PHP IntelliSense

For better PHP autocomplete, install WordPress stubs:

Next Steps