PHPackages                             wpify/scoper - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. wpify/scoper

ActiveComposer-plugin[Utility &amp; Helpers](/categories/utility)

wpify/scoper
============

Composer plugin that scopes WordPress and WooCommerce dependencies for usage in WordPress plugins and themes.

4.0.0(2w ago)3376.5k↓64%2[1 PRs](https://github.com/wpify/scoper/pulls)8GPL-2.0-or-laterPHPPHP ^8.2CI passing

Since Mar 19Pushed 1w ago3 watchersCompare

[ Source](https://github.com/wpify/scoper)[ Packagist](https://packagist.org/packages/wpify/scoper)[ Docs](https://github.com/wpify/scoper)[ RSS](/packages/wpify-scoper/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (24)Versions (68)Used By (8)

wpify/scoper
============

[](#wpifyscoper)

[![CI](https://github.com/wpify/scoper/actions/workflows/ci.yml/badge.svg)](https://github.com/wpify/scoper/actions/workflows/ci.yml)[![Packagist](https://camo.githubusercontent.com/10b9cde1b34fb5d22d307597225698f502f2477d04dfad36bb3f3a7e3763655e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f77706966792f73636f7065722e737667)](https://packagist.org/packages/wpify/scoper)[![Downloads](https://camo.githubusercontent.com/9d1a28c8be2d4c46a01668a417f63a8a73a2f64cd4d389f8ecd0ad295c350c11/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77706966792f73636f7065722e737667)](https://packagist.org/packages/wpify/scoper)[![PHP](https://camo.githubusercontent.com/66b6905cae43f251ef01d91f2c3b111da507de5b64b147434d6bd3c612839040/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f77706966792f73636f7065722f7068702e737667)](https://packagist.org/packages/wpify/scoper)[![License](https://camo.githubusercontent.com/3bece0c09b333cce17e0708874d44f28e25641df5be6c0711784287dbee61a6b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77706966792f73636f7065722e737667)](LICENSE)

A Composer plugin that moves your dependencies into a namespace of your own, so that your WordPress plugin or theme cannot collide with anybody else's.

The problem
-----------

[](#the-problem)

WordPress loads every active plugin into one PHP process, and PHP has one global namespace. Your plugin requires `guzzlehttp/guzzle` 7. Another plugin on the same site bundles Guzzle 6. Whichever autoloader registers first wins, the other plugin gets a class it does not recognise, and something fatals — on a site you do not control and cannot test against.

[PHP Scoper](https://github.com/humbug/php-scoper) solves this by rewriting your dependencies under a prefix that nobody else will use. But it prefixes *everything* it can see, WordPress's own functions and classes included, so a scoped plugin ends up calling `MyPlugin\Deps\add_action()` — which does not exist.

This plugin is PHP Scoper wired up correctly for WordPress. It ships a generated database of every symbol declared by WordPress, WooCommerce, Action Scheduler and WP-CLI, and keeps those unprefixed while everything else moves into your namespace.

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

[](#requirements)

**PHP 8.2 or newer**, and Composer 2.6 or newer.

Quickstart
----------

[](#quickstart)

Install the plugin globally, pinned to a major version:

```
composer global config --no-plugins allow-plugins.wpify/scoper true
composer global require wpify/scoper:^4.0
```

In your plugin, declare the dependencies you want scoped in `composer-deps.json` — same format as `composer.json`, but it holds *only* the dependencies that get prefixed:

```
{
  "require": {
    "guzzlehttp/guzzle": "^7.0"
  },
  "config": {
    "platform": {
      "php": "8.2.0"
    }
  }
}
```

Then tell the plugin what namespace to use, in your ordinary `composer.json`:

```
{
  "config": {
    "allow-plugins": {
      "wpify/scoper": true
    }
  },
  "extra": {
    "wpify-scoper": {
      "prefix": "MyPlugin\\Deps"
    }
  }
}
```

Run Composer:

```
composer install
```

The scoped tree is written to `deps/`. Load its autoloader alongside Composer's own:

```
