phpcompatibility/phpcompatibility-wp
WordPress-focused PHP_CodeSniffer ruleset for checking PHP cross-version compatibility. Built on PHPCompatibility, it avoids false positives by excluding WordPress backfills and polyfills so you can scan WP plugins, themes, and sites accurately.
Start by installing the package via Composer as a development dependency. Run composer require --dev phpcompatibility/phpcompatibility-wp:^3.0@dev in your WordPress project root (e.g., plugin, theme, or core derivative). The package automatically registers itself with PHP_CodeSniffer using the Composer PHPCS plugin—no manual configuration needed. Verify installation by running vendor/bin/phpcs -i; you should see PHPCompatibilityWP listed as an available standard. First use case: run vendor/bin/phpcs --standard=PHPCompatibilityWP --runtime-set testVersion 7.2- ./ to scan your codebase for PHP compatibility issues relevant to your target WordPress minimum PHP version (e.g., PHP 7.2 for WP 6.6+). Always specify testVersion—this enables detection of both deprecated/removed features and usage of newer PHP features not supported in your chosen baseline.
--extensions=php to skip non-PHP files for speed, and consider caching vendor/ for faster runs..phpcs.xml.dist file to set defaults (e.g., testVersion, error Severity, warning Severity) and exclude paths. Example:
<?xml version="1.0"?>
<ruleset name="WordPressPHPCompatibility">
<config name="testVersion" value="8.0-"/>
<rule ref="PHPCompatibilityWP">
<exclude name="PHPCompatibilityWP.Core.RewriteAPI.UseAdd_rewrite_rule_DEPRECATED"/>
</rule>
<file>.</file>
<arg name="extensions" value="php"/>
</ruleset>
git pre-commit hook recommended). Integrate with IDEs like VS Code via the PHP_CodeSniffer extension, setting phpcs.standard to PHPCompatibilityWP.vendor/bin/phpcs --standard=PHPCompatibilityWP --runtime-set testVersion 8.0- --ignore-annotations --report=baseLine > phpcs-baseline.xml, then reference it in .phpcs.xml.testVersion Quirks: The trailing dash (-) matters—it means “and higher”. Using 7.2 (without -) checks only PHP 7.2 features, missing deprecations for newer versions. Confirm your WordPress minimum version: e.g., WP 6.9 requires PHP 7.2.24+, so use testVersion 7.2.24-.phpcompatibility-wp filters out known WordPress polyfills (e.g., sodium_compat, wp_rand backfill), some edge cases remain (e.g., using IntlDateFormatter with Intl extension not loaded in older PHP versions but polyfilled in WP). Always validate warnings manually.PHPCompatibilityWP.Core.* → PHPCompatibilityWP.*). Update // phpcs:ignore comments and custom excludes accordingly—consult the changelog and PHPCompatibility 10 upgrade guide.phpcompatibility/phpcompatibility and phpcompatibility/phpcompatibility-paragonie are at compatible versions. The --with-dependencies flag is crucial during updates: composer update --dev phpcompatibility/phpcompatibility-wp --with-dependencies.vendor/bin/phpcs -v for verbose output to pinpoint slow sniffs. For large projects, run on subsets: vendor/bin/phpcs ./plugins/my-plugin/src/ --standard=PHPCompatibilityWP --runtime-set testVersion 8.0-.How can I help you explore Laravel packages today?