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.

3.2.21(1y ago)3367.9k↓28.7%2[1 issues](https://github.com/wpify/scoper/issues)GPL-2.0-or-laterPHPPHP ^8.1

Since Mar 19Pushed 1y ago3 watchersCompare

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

READMEChangelogDependencies (10)Versions (67)Used By (0)

WPify Scoper - A scoper for WordPress plugins and themes
========================================================

[](#wpify-scoper---a-scoper-for-wordpress-plugins-and-themes)

Using Composer in your WordPress plugin or theme can benefit from that. But it also comes with a danger of conflicts with dependencies of other plugins or themes. Luckily, a great tool called [PHP Scoper](https://github.com/humbug/php-scoper) adds all your needed dependencies to your namespace to prevent conflicts. Unfortunately, the configuration is non-trivial, and for that reason, we created the Composer plugin to make scoping easy in WordPress projects.

The main issue with PHP Scoper is that it also scopes global functions, constants and classes. Usually, that is what you want, but that also means that WordPress functions, classes and constants will be scoped. This Composer plugin solves that. It has an up-to-date database of all WordPress and WooCommerce symbols that we want to keep unscoped.

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

[](#requirements)

- wpify/scoper:**3.1**
    - PHP 7.4 || 8.0
- wpify/scoper:**3.2**
    - PHP &gt;= 8.1

Usage
-----

[](#usage)

1. This composer plugin is meant to be installed globally, but you can also require it as a dev dependency.
2. The configuration requires creating `composer-deps.json` file, that has exactly same structure like `composer.json`file, but serves only for scoped dependencies. Dependencies that you don't want to scope comes to `composer.json`.
3. Add `extra.wpify-scoper.prefix` to you `composer.json`, where you can specify the namespace, where your dependencies will be in. All other config options (`folder`, `globals`, `composerjson`, `composerlock`, `autorun`) are optional.
4. The easiest way how to use the scoper on development environment is to install WPify Scoper as a dev dependency. After each `composer install` or `composer update`, all the dependencies specified in `composer-deps.json` will be scoped for you.
5. Add a `config.platform` option in your composer.json and composer-deps.json. This settings will make sure that the dependencies will be installed with the correct PHP version.

**Example of `composer.json` with its default values**

```
{
  "config": {
    "platform": {
      "php": "8.0.30"
    }
  },
  "scripts": {
    "wpify-scoper": "wpify-scoper"
  },
  "extra": {
    "wpify-scoper": {
      "prefix": "MyNamespaceForDeps",
      "folder": "deps",
      "globals": [
        "wordpress",
        "woocommerce",
        "action-scheduler",
        "wp-cli"
      ],
      "composerjson": "composer-deps.json",
      "composerlock": "composer-deps.lock",
      "autorun": true
    }
  }
}
```

6. Option `autorun` defaults to `true` so that scoping is run automatically upon composer `update` or `install` command. That is not what you want in all cases, so you can set it `false` if you need. To start prefixing manually, you need to add for example the line `"wpify-scoper": "wpify-scoper"` to the "scripts" section of your composer.json. You then run the script with the command `composer wpify-scoper install` or `composer wpify-scoper update`.
7. Scoped dependencies will be in `deps` folder of your project. You must include the scoped autoload alongside with the composer autoloader.
8. After that, you can use your dependencies with the namespace.

**Example PHP file:**

```
