Git Product home page Git Product logo

wordpress-stubs's Introduction

WordPress Stubs

Build Status

This package is a fork of giacocorsiglia/stubs-generator. 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, which is not able to parse WordPress as it is not OOP code.

The stubs are generated directly from the source using giacocorsiglia/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 libsodium or install the paragonie/sodium_compat package
  • For PHP <7.3 install the symfony/polyfill-php73 as 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

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

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

wordpress-stubs's People

Contributors

szepeviktor avatar giacocorsiglia avatar localheinz avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.