unloc/composer-compatibility-enforcer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

unloc/composer-compatibility-enforcer

Composer 安装命令:

composer require unloc/composer-compatibility-enforcer

包简介

Remove selected namespaces/classes from plugin Composer autoloaders.

README 文档

README

Removes selected namespaces and classes from plugin Composer autoloaders to avoid vendor conflicts.

This is primarily useful in Bedrock projects running Roots Acorn, where multiple Composer autoloaders can introduce conflicting versions of shared libraries. For background, see the Acorn compatibility notes.

This MU plugin aims to provide a cleaner alternative to often brittle Composer patches. It does not ship with default rules; configure it via a WordPress filter.

Requirements

  • PHP 8.1+
  • WordPress 5.9+
  • Composer-based WordPress installation (e.g., Bedrock)

Installation

composer require unloc/composer-compatibility-enforcer

The package type is wordpress-muplugin, so it will automatically install to web/app/mu-plugins/ on Bedrock setups.

Configuration

This plugin ships with no default rules. Add rules via the composer_compatibility_enforcer_rules filter.

Since this is an MU plugin, the filter must be registered in code that loads before or during plugins_loaded (priority < 11). The recommended approach is a separate MU plugin file:

web/app/mu-plugins/composer-compatibility-enforcer-rules.php

<?php

add_filter('composer_compatibility_enforcer_rules', static function (array $rules): array {
    $rules[] = [
        'plugin_file' => 'google-listings-and-ads/google-listings-and-ads.php',
        'namespaces'  => ['Psr\\Log\\', 'Monolog\\'],
    ];

    return $rules;
});

Bedrock note: Files directly in mu-plugins/ are auto-loaded by WordPress. The rules file needs no loader entry — just drop it in.

Rule Array Keys

Each rule array supports:

  • plugin_file (required) — string; plugin main file path (relative to WP_PLUGIN_DIR)
  • namespaces (optional) — array of namespace prefixes to remove from that plugin's autoloader
  • classes (optional) — array of fully-qualified class names to block (sets classmap to false)

If both namespaces and classes are empty, the rule is skipped.

Logging

Logs are written to the default PHP error log only when the composer_compatibility_enforcer_enable_logging filter returns true.

Known Offenders

Some plugins with known compatibility issues. PRs welcome!

Google for WooCommerce | wpackagist-plugin/google-listings-and-ads

$rules[] = [
    'plugin_file' => 'google-listings-and-ads/google-listings-and-ads.php',
    'namespaces' => ['Psr\\Log\\', 'Monolog\\'],
];

Boekuwzending for Woocommerce | wpackagist-plugin/boekuwzending-for-woocommerce

$rules[] = [
    'plugin_file' => 'boekuwzending-for-woocommerce/boekuwzending-for-woocommerce.php',
    'namespaces'  => ['Psr\\Log\\'],
];

统计信息

  • 总下载量: 471
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固