Prefix Composer dependencies with wp-scoper (no more class conflicts with other plugins) - #336
Open
mostafasoufi wants to merge 2 commits into
Open
mostafasoufi wants to merge 2 commits into
mostafasoufi wants to merge 2 commits into
Conversation
mostafasoufi
force-pushed
the
feat/wp-scoper
branch
2 times, most recently
from
September 13, 2026 07:18
96c5a49 to
6333e8d
Compare
mostafasoufi
force-pushed
the
feat/ci-cd-tests-deploy
branch
from
September 13, 2026 07:23
c211907 to
c812909
Compare
added 2 commits
September 13, 2026 11:23
…ther plugins - Add veronalabs/wp-scoper as a dev dependency and configure it in composer.json. On composer install it copies enshrined/svg-sanitize and the Symfony polyfills into packages/ under the WPParsidate\Dependencies namespace and generates packages/autoload.php. - Load packages/autoload.php (plus inc/Functions/*.php) from the main plugin file instead of vendor/autoload.php, so vendor/ is no longer needed at runtime. - Commit packages/, git-ignore vendor/ and exclude it from the release ZIP. - Update the SVG sanitizer call site to the prefixed namespace. - Add a CI job that fails when packages/ does not match composer.lock, and tests that verify dependencies load from packages/ and polyfilled functions are available.
… lint job - Pin config.platform.php to 7.4 so composer.lock only contains packages that install on the plugin's minimum PHP version. - Exclude packages/ from the php -l job: it is vendored code and polyfill-php83/bootstrap81.php intentionally uses PHP 8.1 syntax (it is only loaded on PHP >= 8.1).
mostafasoufi
force-pushed
the
feat/wp-scoper
branch
from
September 13, 2026 07:23
6333e8d to
9a914cd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #334
🚨 Problem
vendor/shipsenshrined/svg-sanitizeand the Symfony polyfills unprefixed. Another plugin bundling the same library (Safe SVG with 1M+ installs bundlesenshrined/svg-sanitize; countless plugins bundlesymfony/polyfill-php80) can load a different version first, and we end up running against a class we never tested, or with a fatal error. Full write-up in #334.✅ What this PR does
Uses wp-scoper (a Composer plugin, same as wp-sms and its add-ons) to give every dependency our own namespace.
composer.jsonrequire-dev:veronalabs/wp-scoper ^1.4.2extra.wp-scoper: prefixWPParsidate\Dependencies, targetpackages/, packagesenshrined/svg-sanitize+ the three Symfony polyfills,update_call_sites: ["inc"],delete_vendor_packages: trueconfig.allow-pluginsfor wp-scoperGenerated on
composer install(committed)packages/– 39 prefixed PHP files, 77 KB instead of 107 KB (tests, docs and config of the libraries are not copied)packages/autoload.php– classmap autoloader for the dependencies plus PSR-4 autoloading for our ownWPParsidate\→inc/classes, plus the polyfill bootstrap filesRuntime change –
wp-parsidate.php(
inc/Functions/*.phpwere previously loaded through Composer'sautoload.files; they are now required directly sovendor/is not needed at all at runtime.)Call site updated automatically –
inc/Helper/Sanitizing.phpRepository hygiene
vendor/removed from git and added to.gitignoreand.distignore(dev only now)packages/committed, sogit clonestill works without running ComposerCI
scoperjob intesting.yml: runscomposer installand fails ifpackages/orinc/would change, so an out-of-datepackages/can never be mergeddeploy.ymlrunscomposer install(with dev dependencies so wp-scoper runs);vendor/is excluded from the ZIP by.distignoretests/unit/DependenciesTest.php: the prefixedSanitizerclass exists and is loaded frompackages/;str_contains,str_starts_with,array_is_list,json_validateare available (natively or via the bundled polyfills)🎁 Benefits
SanitizerisWPParsidate\Dependencies\enshrined\svgSanitize\Sanitizer, nobody else has that class.composer.lockis the one that runs on the site.vendor/no longer shipped.composer install. Add a dependency, runcomposer install, commitpackages/.composer.lockandpackages/fails the build.🔍 Demo – how it works in wp-sms
extra.wp-scoper)✅ Tested
Run locally on PHP 8.0, where
array_is_list()andjson_validate()are not native, so the test also proves the prefixed polyfills are loaded correctly.📝 Notes
define()constants inside the polyfill bootstrap files (FILTER_VALIDATE_BOOL,MYSQLI_REFRESH_REPLICA,CURLOPT_ISSUERCERT_BLOB). The plugin does not use any of them; polyfilled functions are not renamed and keep working.vendor/→packages/move; GitHub shows most of it as renames. The hand-written changes are incomposer.json,wp-parsidate.php,inc/Helper/Sanitizing.php,.gitignore,.distignore, the two workflows, README and the new test.