Skip to content

Allow multiple config files for e.g. environment-specific dependencies#74

Open
sixmonkey wants to merge 2 commits into
afragen:developfrom
sixmonkey:develop
Open

Allow multiple config files for e.g. environment-specific dependencies#74
sixmonkey wants to merge 2 commits into
afragen:developfrom
sixmonkey:develop

Conversation

@sixmonkey

Copy link
Copy Markdown

Hey! Thanks for the great work on this package — it fills a real gap in the WordPress ecosystem.

I came across it while working on folivoro/sloth, a WordPress framework, and immediately saw the need for environment-specific plugin dependencies. I came up with the following idea:

Problem

Currently WP_Dependency_Installer reads from a single hardcoded filename wp-dependencies.json. There is no way to have a base config and extend it e.g. per environment without duplicating the entire file.

Solution

Make the config file list a public static property — defaulting to the existing wp-dependencies.json so there is no breaking change. Callers can override it before calling run() to load multiple files in order, with later files merged on top of earlier ones.

Usage

Base + environment-specific overrides:

add_action( 'plugins_loaded', static function() {
    WP_Dependency_Installer::$config_files = [
        'wp-dependencies.json',                      // base — shared across all environments
        'wp-dependencies.' . WP_ENV . '.json',       // env-specific — optional, merged on top
    ];
    WP_Dependency_Installer::instance( __DIR__ )->run();
});

Example files:

// wp-dependencies.json — always loaded
[
    {
        "name": "Advanced Custom Fields Pro",
        "host": "direct",
        "slug": "advanced-custom-fields-pro/acf.php",
        "uri": "https://my-storage.example.com/acf-pro.zip",
        "required": true
    }
]
// wp-dependencies.local.json — only loaded in local environment
[
    {
        "name": "Query Monitor",
        "host": "wordpress",
        "slug": "query-monitor/query-monitor.php",
        "uri": "https://wordpress.org/plugins/query-monitor/",
        "required": true
    }
]

Missing env-specific files are silently ignored — no errors if wp-dependencies.local.json doesn't exist in production.

Backwards compatibility

Fully backwards compatible. The default value of $config_files is ['wp-dependencies.json'] — identical behaviour to the current implementation if the property is not overridden.

@afragen

afragen commented May 22, 2026

Copy link
Copy Markdown
Owner

You can also use a config array instead of a json file.

See wiki for more information.

https://github.com/afragen/wp-dependency-installer/wiki

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants