PHPackages                             szepeviktor/phpstan-wordpress - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. szepeviktor/phpstan-wordpress

ActivePhpstan-extension[Testing &amp; Quality](/categories/testing)

szepeviktor/phpstan-wordpress
=============================

WordPress extensions for PHPStan

v2.0.3(8mo ago)3287.8M↑31%30[12 issues](https://github.com/szepeviktor/phpstan-wordpress/issues)[1 PRs](https://github.com/szepeviktor/phpstan-wordpress/pulls)20MITPHPPHP ^7.4 || ^8.0CI failing

Since May 4Pushed 7mo ago11 watchersCompare

[ Source](https://github.com/szepeviktor/phpstan-wordpress)[ Packagist](https://packagist.org/packages/szepeviktor/phpstan-wordpress)[ RSS](/packages/szepeviktor-phpstan-wordpress/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (55)Used By (20)

Important

Hello everyone! This is Viktor who runs this PHPStan extension. I am planning to stop contributing to the WordPress ecosystem because it is extremely difficult and no one asks me **to join his team** as I am a thinker, a devops person, a tool maker (not a builder).

Please support my work to avoid abandoning this package.

[![Sponsor](https://github.com/szepeviktor/.github/raw/master/.github/assets/github-like-sponsor-button.svg)](https://github.com/sponsors/szepeviktor)

Thank you!

WordPress Extensions for PHPStan
================================

[](#wordpress-extensions-for-phpstan)

[![Packagist stats](https://camo.githubusercontent.com/6f0f96e93b23ecddb2e631106df4f15bba41d6ef66da15305fdc2141ab5546fa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f737a65706576696b746f722f7068707374616e2d776f726470726573732e737667)](https://packagist.org/packages/szepeviktor/phpstan-wordpress/stats)[![Packagist](https://camo.githubusercontent.com/105d4965f2646add801a3172e936b5c3ebf2f6445d7209aa0adb2a5a878c0544/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737a65706576696b746f722f7068707374616e2d776f726470726573732e7376673f636f6c6f723d323339393232267374796c653d706f706f7574)](https://packagist.org/packages/szepeviktor/phpstan-wordpress)[![Tweet](https://camo.githubusercontent.com/f2c37423b05bb0697239f01a903bb61244243215e49041792283fa299469597a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54776565742d73686172652d6435643564353f7374796c653d736f6369616c266c6f676f3d74776974746572)](https://twitter.com/intent/tweet?text=Static%20analysis%20for%20WordPress&url=https%3A%2F%2Fgithub.com%2Fszepeviktor%2Fphpstan-wordpress)[![Build Status](https://camo.githubusercontent.com/939e17fb2501452f8c896cc8c0ed3deddf8a94f310160f103166745b6e085e40/68747470733a2f2f6170702e7472617669732d63692e636f6d2f737a65706576696b746f722f7068707374616e2d776f726470726573732e7376673f746f6b656e3d43675956787353644e566e524e43444e56337147266272616e63683d6d6173746572)](https://app.travis-ci.com/szepeviktor/phpstan-wordpress)[![PHPStan](https://camo.githubusercontent.com/c961f520ec74aa0d9e60565e511aebb1c4930b5a0ea635e9be3e99bf562be287/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d323339393232)](https://github.com/phpstan/phpstan)

Static analysis for the WordPress ecosystem.

- [PHPStan](https://phpstan.org/)
- [WordPress](https://wordpress.org/)

Features
--------

[](#features)

- Enables PHPStan to analyze WordPress plugins and themes.
- Loads the [`php-stubs/wordpress-stubs`](https://github.com/php-stubs/wordpress-stubs) package.
- Provides dynamic return type extensions for functions that are not covered in [`php-stubs/wordpress-stubs`](https://github.com/php-stubs/wordpress-stubs/blob/master/functionMap.php)
- Defines some WordPress core constants.
- Validates optional docblocks before `apply_filters()` and `do_action()` calls, treating the type of the first `@param` as definitive.

Requirements
------------

[](#requirements)

- PHPStan 2.0 or higher
- PHP 7.4 or higher (tested up to PHP 8.3)

Installation
------------

[](#installation)

To use this extension, require it in [Composer](https://getcomposer.org/):

```
composer require --dev szepeviktor/phpstan-wordpress
```

If you also install [phpstan/extension-installer](https://github.com/phpstan/extension-installer) then you're all set!

### Manual Installation

[](#manual-installation)

If you don't want to use `phpstan/extension-installer`, include `extension.neon` in your project's PHPStan config:

```
includes:
    - vendor/szepeviktor/phpstan-wordpress/extension.neon
```

Configuration
-------------

[](#configuration)

No additional setup is needed. 😃 Just configure PHPStan - for example - as shown below:

```
parameters:
    level: 5
    paths:
        - plugin.php
        - inc/
```

For more details, visit the [PHPStan Config Reference](https://phpstan.org/config-reference).

💡 Use the Composer autoloader or a [custom autoloader](https://github.com/szepeviktor/debian-server-tools/blob/master/webserver/wp-install/wordpress-autoloader.php)!

Usage
-----

[](#usage)

Run the analysis with:

```
vendor/bin/phpstan analyze
```

then fix an error and `GOTO 10`!

You find further information in the `examples` directory, e.g. [`examples/phpstan.neon.dist`](/examples/phpstan.neon.dist)

### Usage in WooCommerce Webshops

[](#usage-in-woocommerce-webshops)

Refer to [WooCommerce Stubs](https://github.com/php-stubs/woocommerce-stubs) for specific guidance.

### Usage of an `apply_filters()` Docblock

[](#usage-of-an-apply_filters-docblock)

The WordPress ecosystem often uses PHPDoc docblocks in a non-standard way to document parameters passed to `apply_filters()`. Here’s an example:

```
/**
 * Filters the page title when creating an HTML drop-down list of pages.
 *
 * @param string  $title Page title.
 * @param WP_Post $page  Page data object.
 */
$title = apply_filters( 'list_pages', $title, $page );
```

This extension reads these docblocks and instructs PHPStan to treat the filter’s return type as certain, based on the first `@param` tag. In this example, PHPStan interprets `$title` as `string`.

For best results, ensure the first `@param` tag in these docblocks is accurate.

Make Your Code Testable
-----------------------

[](#make-your-code-testable)

- Write clean OOP code: 1 class per file, and no additional code outside `class Name { ... }`.
- Use consistent class naming (WPCS or PSR-4) and store classes in a dedicated `inc/` directory.
- Add precise PHPDoc blocks to classes, properties, methods, functions, and `apply_filters()` calls.
- Choose your [main plugin file parts](https://github.com/szepeviktor/starter-plugin).
- Avoid using core constants, use core functions.
- Avoid bad PHP practices, such as:
    - functions: `eval`, `extract`, `compact`, `list`
    - [type juggling](https://www.php.net/manual/en/language.types.type-juggling.php): `$a = '15'; if ($a) ...`
- If you need robust code try avoiding all kinds of type juggling (e.g. `if` needs a boolean), see [Variable handling functions](https://www.php.net/manual/en/ref.var.php)
- Avoid enabling `exit_error` in `WP_CLI::launch` or `WP_CLI::runcommand` for improved testability.

Dirty Corner (FAQ)
------------------

[](#dirty-corner-faq)

WordPress uses conditional function and class definition to allow overrides. Use `sed` command to exclude function stubs when they are previously defined.

```
sed -i -e 's#function is_gd_image#function __is_gd_image#' vendor/php-stubs/wordpress-stubs/wordpress-stubs.php
```

###  Health Score

66

—

FairBetter than 99% of packages

Maintenance62

Regular maintenance activity

Popularity65

Solid adoption and visibility

Community49

Growing community involvement

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 50.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~44 days

Recently: every ~75 days

Total

53

Last Release

247d ago

Major Versions

v0.7.7 → v1.0.02021-11-01

v1.3.5 → v2.0.0-rc.12024-11-11

PHP version history (4 changes)0.1.0PHP ~7.1

v0.7.0PHP ^7.1 || ^8.0

v1.1.0PHP ^7.2 || ^8.0

v2.0.0-rc.1PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/135d8104cdf926e2b15b6a06413153a9582729f0cd48ccba7bc7e62878a39781?d=identicon)[szepeviktor](/maintainers/szepeviktor)

---

Top Contributors

[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (235 commits)")[![johnbillion](https://avatars.githubusercontent.com/u/208434?v=4)](https://github.com/johnbillion "johnbillion (113 commits)")[![IanDelMar](https://avatars.githubusercontent.com/u/42134098?v=4)](https://github.com/IanDelMar "IanDelMar (72 commits)")[![herndlm](https://avatars.githubusercontent.com/u/5738896?v=4)](https://github.com/herndlm "herndlm (21 commits)")[![swissspidy](https://avatars.githubusercontent.com/u/841956?v=4)](https://github.com/swissspidy "swissspidy (5 commits)")[![westonruter](https://avatars.githubusercontent.com/u/134745?v=4)](https://github.com/westonruter "westonruter (4 commits)")[![dingo-d](https://avatars.githubusercontent.com/u/8638515?v=4)](https://github.com/dingo-d "dingo-d (2 commits)")[![lipemat](https://avatars.githubusercontent.com/u/1688181?v=4)](https://github.com/lipemat "lipemat (2 commits)")[![merlindiavova](https://avatars.githubusercontent.com/u/1636456?v=4)](https://github.com/merlindiavova "merlindiavova (2 commits)")[![ondrejmirtes](https://avatars.githubusercontent.com/u/104888?v=4)](https://github.com/ondrejmirtes "ondrejmirtes (2 commits)")[![ZebulanStanphill](https://avatars.githubusercontent.com/u/19592990?v=4)](https://github.com/ZebulanStanphill "ZebulanStanphill (1 commits)")[![Hug0-Drelon](https://avatars.githubusercontent.com/u/69580439?v=4)](https://github.com/Hug0-Drelon "Hug0-Drelon (1 commits)")[![mundschenk-at](https://avatars.githubusercontent.com/u/6943905?v=4)](https://github.com/mundschenk-at "mundschenk-at (1 commits)")[![bart-jaskulski](https://avatars.githubusercontent.com/u/56613051?v=4)](https://github.com/bart-jaskulski "bart-jaskulski (1 commits)")

---

Tags

phpstanphpstan-extensionstatic-analysiswordpressPHPStanwordpressstatic analysiscode analysiscode analyse

###  Code Quality

TestsPHPUnit

Type Coverage Yes

### Embed Badge

![Health badge](/badges/szepeviktor-phpstan-wordpress/health.svg)

```
[![Health](https://phpackages.com/badges/szepeviktor-phpstan-wordpress/health.svg)](https://phpackages.com/packages/szepeviktor-phpstan-wordpress)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[ekino/phpstan-banned-code

Detected banned code using PHPStan

2925.6M92](/packages/ekino-phpstan-banned-code)[shipmonk/dead-code-detector

Dead code detector to find unused PHP code via PHPStan extension. Can automatically remove dead PHP code. Supports libraries like Symfony, Doctrine, PHPUnit etc. Detects dead cycles. Can detect dead code that is tested.

3462.2M52](/packages/shipmonk-dead-code-detector)[php-stubs/acf-pro-stubs

Advanced Custom Fields PRO stubs for static analysis.

73692.8k50](/packages/php-stubs-acf-pro-stubs)[calebdw/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

1484.6k3](/packages/calebdw-larastan)[shipmonk/phpstan-rules

Various extra strict PHPStan rules we found useful in ShipMonk.

1491.7M114](/packages/shipmonk-phpstan-rules)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
