PHP Coding Standards
This project follows WordPress Coding Standards for PHP code.Tools and Configuration
The project uses PHP_CodeSniffer (PHPCS) with the following rulesets:- WordPress Coding Standards (
wp-coding-standards/wpcs) - PHP Compatibility (
phpcompatibility/phpcompatibility-wp)
These tools are automatically configured when you run
composer dev in a theme or plugin directory.Running Code Linting
PHP Version Requirements
- Minimum PHP version: 8.0+
- Project standard: PHP 8.1+
PSR-4 Autoloading
Both themes and plugins use PSR-4 autoloading: Theme (bifrost-noise):Class naming and file structure
Class naming and file structure
Follow PSR-4 conventions:
- Class
Bifrost\Noise\Admin\Settings→src/Admin/Settings.php - Class
Bifrost\Music\API\Endpoint→inc/API/Endpoint.php - Use UpperCamelCase for class names
- One class per file
WordPress-Specific Standards
Follow WordPress best practices:Naming Conventions
- Functions:
snake_case - Classes:
PascalCase - Constants:
UPPERCASE_SNAKE_CASE - Hooks:
prefix_hook_name
Security
- Escape output:
esc_html(),esc_attr(),esc_url() - Sanitize input:
sanitize_text_field(), etc. - Validate and sanitize all user input
- Use nonces for forms
Database
- Use
$wpdb->prepare()for queries - Never concatenate user input into SQL
- Use WordPress functions when available
Internationalization
- Wrap strings in
__(),_e(),_n() - Use text domain consistently
- Make all user-facing strings translatable
JavaScript Standards
For JavaScript and React code:- Use modern ES6+ syntax
- Follow WordPress Gutenberg coding standards for block development
- Use
@wordpress/scriptsfor build tooling when applicable - Ensure code is linted before committing
CSS/SCSS Standards
- Follow WordPress CSS Coding Standards
- Use BEM methodology for class naming when appropriate
- Prefer CSS custom properties for theming
- Ensure responsive design principles are followed
Commit Message Format
This project follows Conventional Commits specification.Format
Types
| Type | Description | Example |
|---|---|---|
feat | New feature | feat: add user registration endpoint |
fix | Bug fix | fix: resolve null pointer in auth service |
docs | Documentation changes | docs: update API documentation |
style | Code style changes (formatting, etc.) | style: format code with phpcs |
refactor | Code refactoring | refactor: extract authentication logic |
test | Adding or updating tests | test: add unit tests for user model |
chore | Maintenance tasks | chore: update composer dependencies |
Examples
Good commit messages
Good commit messages
Commit message best practices
Commit message best practices
- Use the imperative mood: “add feature” not “added feature”
- Be concise: Keep the summary line under 72 characters
- Explain why, not what: The diff shows what changed; explain why
- Reference issues: Include issue numbers when applicable:
fix: #123 resolve login bug - Separate subject from body: Use a blank line between summary and detailed description
Writing Good Commit Messages
Testing
Before Committing
Run these checks before committing:Testing in Staging
All changes must be tested in the staging environment before merging to trunk.
staging, verify:
- Functionality works as expected
- No PHP errors or warnings
- No JavaScript console errors
- Responsive design works across devices
- No performance regressions
- WordPress admin area remains functional
Code Review Guidelines
When reviewing pull requests:Code Quality
- Follows WordPress coding standards
- No obvious bugs or security issues
- Proper error handling
- Code is readable and maintainable
Functionality
- Meets requirements
- Works in staging environment
- No breaking changes (or properly documented)
- Edge cases are handled
Documentation
- Code is properly commented
- DocBlocks for functions and classes
- README updated if needed
- Inline comments for complex logic
Testing
- Tested in staging
- QA approval obtained
- No regressions introduced
- Performance impact considered
Documentation Standards
PHP Documentation
Use PHPDoc format for all functions and classes:Inline Comments
Add comments for complex logic:README Files
Keep README files up to date:- Installation instructions
- Configuration options
- Usage examples
- API documentation
Build and Deployment
Composer Scripts
Available composer scripts:| Script | Purpose | Command |
|---|---|---|
build | Production build | composer build |
dev | Development dependencies | composer dev |
lint:php | Run PHP linting | composer lint:php |
zip | Create distribution archive | composer zip |
Vendor Folder Management
The deployment workflow:- Runs on push to
trunkorstaging - Executes
composer install --no-dev - Uploads vendor folder to the appropriate environment
- Uses GitHub Environments for credentials
Resources
WordPress Coding Standards
Official WordPress coding standards documentation
Conventional Commits
Learn more about the Conventional Commits specification
PHP_CodeSniffer
PHP_CodeSniffer documentation and usage
WordPress Developer Resources
Comprehensive WordPress development documentation
Questions?
If you have questions about coding standards:- Open an issue with the
questionlabel - Ask in code review comments
- Reach out to maintainers
