Skip to content

Up-to-date WordPress function and class declaration stubs for static analysis by PHPStan

License

Notifications You must be signed in to change notification settings

php-stubs/wordpress-stubs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

c04f96c · Feb 12, 2025
Oct 12, 2024
Feb 12, 2025
Oct 5, 2024
Nov 25, 2024
Mar 31, 2023
Sep 30, 2024
Apr 19, 2023
Oct 12, 2024
Oct 12, 2019
Feb 12, 2024
Nov 12, 2024
Feb 12, 2025
Feb 5, 2025
May 11, 2023
Sep 30, 2024
May 9, 2024
Apr 19, 2023
Nov 24, 2024
Apr 17, 2024
Feb 12, 2025

Repository files navigation

Important

Hello everyone! This is Viktor who runs the php-stubs organization. I am planning to stop contributing to the WordPress ecosystem because it is extremely difficult and I do not earn (min) €100/month.

Please support my work to avoid abandoning this package.

Sponsor

Thank you!

WordPress Stubs

Packagist stats Packagist Build Status

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.4 or 8.0

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

  1. Run modern PHP version
  2. Clone this repository and cd into it
  3. Update "johnpbloch/wordpress": "x.x.x" in source/composer.json with the desired version
  4. Run composer update
  5. And run ./generate.sh

The wordpress-stubs.php file should now be updated.