wordpress-stubs
wordpress-stubs copied to clipboard
Up-to-date WordPress function and class declaration stubs for static analysis by PHPStan
WordPress Stubs
It provides stub declarations for WordPress core functions, classes and interfaces, globals are not included. These stubs can help plugin and theme developers leverage static analysis tools like PHPStan.
The stubs are generated from @johnpbloch's package using php-stubs/generator.
Requirements
- PHP 7.1+
- Sodium PHP extension as latest WordPress core uses it and compat code is removed from stubs,
Sodium is included in PHP from version 7.2, in 7.1 issue
pecl install libsodiumor install theparagonie/sodium_compatpackage - For PHP <7.3 install the
symfony/polyfill-php73as development dependency
Installation
Require this package as a development dependency with Composer.
composer require --dev php-stubs/wordpress-stubs
Alternatively you may download wordpress-stubs.php directly.
Usage with PHPStan
composer require --dev szepeviktor/phpstan-wordpress
The package szepeviktor/phpstan-wordpress
depends on phpstan/phpstan and this one.
Please do read
that package's README
and see the example directory over there.
Usage with Psalm
Update your Psalm config to include this section.
<stubs>
<file name="vendor/php-stubs/wordpress-stubs/wordpress-stubs.php" />
</stubs>
Furthermore ensure WordPress core is not included in <projectFiles>.
Usage in Intellisense
If your IDE has trouble parsing all of WordPress you may find the stubs useful for enabling code completion and related features. For example there are instructions for usage with VSCode's Intelephense extension.
Versioning
This package is versioned to match the WordPress version from which the stubs are generated.
Generating stubs for a different WordPress version
- Run modern PHP version
- Clone this repository and
cdinto it - Update
"johnpbloch/wordpress": "x.x.x"incomposer.jsonwith the desired version - Run
composer update - And run
./generate.sh
The wordpress-stubs.php file should now be updated.