markhadjar/wp-config

Define WordPress constants using environment variables.

Maintainers

Package info

github.com/markhadjar/wp-config

pkg:composer/markhadjar/wp-config

Fund package maintenance!

Buy Me A Coffee

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-05-05 02:41 UTC

This package is auto-updated.

Last update: 2026-05-05 02:49:04 UTC


README

Define WordPress constants using environment variables.

Requirements

PHP 8.4+

Installation

Install via Composer:

composer require markhadjar/wp-config

Usage

Define constants with explicit values:

$config = new \MarkHadjar\WpConfig\WpConfig();

$config
    ->set('DB_NAME', 'wordpress')
    ->set('DB_USER', 'root')
    ->set('DB_PASSWORD', 'password')
    ->set('DB_HOST', 'localhost');

Define constants from environment variables using typed defaults:

$config = new \MarkHadjar\WpConfig\WpConfig();

$config
    ->env('DB_NAME', 'wordpress')
    ->env('DB_USER', 'root')
    ->env('DB_PASSWORD', 'password')
    ->env('DB_HOST', 'localhost');

Apply all entries as constants:

$config->apply();

Check whether an entry exists or read its value:

if ($config->has('DB_HOST')) {
    $host = $config->get('DB_HOST');
}

Note: Calling set() or env() with a key that is already a defined constant will throw a ConstantWasAlreadyDefined exception. Calling apply() will throw if a constant was defined externally with a different value between configuration and apply. Calling env() with a default value whose type is not bool, int, float, string, or null will throw a DefaultValueTypeWasNotSupported exception.