WordPress coding standards for Built North projects, extending WPCS with modern PHP practices.
This package provides a consistent set of coding standards for all Built North WordPress projects. It extends the WordPress Coding Standards (WPCS) while allowing modern PHP features and PSR-4 autoloading.
Add to your project via Composer:
composer require --dev builtnorth/coding-standards
Create a phpcs.xml
file in your project root:
<?xml version="1.0"?>
<ruleset name="My Project">
<description>Coding standards for my project</description>
<!-- Use Built North standards -->
<rule ref="BuiltNorth"/>
<!-- Project-specific text domain -->
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="my-text-domain"/>
</property>
</properties>
</rule>
</ruleset>
# Check your code
vendor/bin/phpcs
# Fix auto-fixable issues
vendor/bin/phpcbf
# Check specific file or directory
vendor/bin/phpcs src/
# Check with specific standard
vendor/bin/phpcs --standard=BuiltNorth
- WordPress Coding Standards (WPCS) 3.0+
- PHP Compatibility checks for PHP 8.1+
- PSR-1/PSR-2 file structure rules
- ✅ Short array syntax
[]
- ✅ Short ternary operator
?:
- ✅ Namespaces and PSR-4 autoloading
- ✅ Modern PHP 8.1+ features
- File naming conventions (we use PSR-4)
- Yoda conditions requirement
- File comment requirements
- Overly strict comment punctuation
Automatically excludes from scanning:
/vendor/
/node_modules/
/build/
and/dist/
*.min.js
and*.min.css
- WordPress core files
- Test bootstrap files
Your project's phpcs.xml
can add additional rules:
<rule ref="BuiltNorth"/>
<!-- Add project-specific rules -->
<rule ref="WordPress.WP.EnqueuedResourceParameters"/>
<!-- Or exclude specific rules -->
<rule ref="BuiltNorth">
<exclude name="WordPress.NamingConventions.PrefixAllGlobals"/>
</rule>
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<property name="prefixes" type="array">
<element value="my_prefix"/>
<element value="MyNamespace"/>
</property>
</properties>
</rule>
- name: Install dependencies
run: composer install
- name: Run PHPCS
run: vendor/bin/phpcs --report=checkstyle | cs2pr
Add to .git/hooks/pre-commit
:
#!/bin/bash
vendor/bin/phpcs --filter=GitStaged
Our coding standards aim to:
- Embrace Modern PHP: Use PHP 8.1+ features while maintaining WordPress compatibility
- Prioritize Readability: Code should be self-documenting with clear naming
- Support PSR-4: Use modern autoloading instead of WordPress file naming
- Balance Strictness: Enforce important standards without being pedantic
- Enable Consistency: Same standards across all Built North projects
- PHP >= 8.1
- Composer
- WordPress project (for context-aware rules)
To contribute to these standards:
- Clone the repository
- Make your changes to
BuiltNorth/ruleset.xml
- Test with real projects
- Submit a pull request with reasoning for changes
MIT