wearerequired / composer-wp-config
A composer plugin to create the WordPress configuration file which automagically defines constants from a .env file. Also includes path of Composer's autoloader in wp-config.php.
Installs: 16 426
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 3
Forks: 1
Open Issues: 5
Type:composer-plugin
Requires
- php: >=7.4
- composer-plugin-api: ^2.0
- oscarotero/env: ^2.1
- vlucas/phpdotenv: ^5.1
Requires (Dev)
- composer/composer: ^2.0
- composer/semver: ^3.0
- dealerdirect/phpcodesniffer-composer-installer: ^0.7 || ^1.0
- wearerequired/coding-standards: ^5.0
This package is auto-updated.
Last update: 2024-11-27 10:50:12 UTC
README
A plugin for Composer to create the WordPress configuration file which automagically defines constants from a .env file. Also includes path of Composer's autoloader in wp-config.php.
Installation
Via Composer
composer require johnpbloch/wordpress wearerequired/composer-wp-config
Copy .env.example
and save it as .env
. By default the variables are searched in a .env
file in the same directory as wp-config.php
.
List of required variables
_HTTP_HOST
(Used when$_SERVER['SERVER_NAME']
is not set, like WP-CLI.)DB_NAME
DB_USER
DB_PASSWORD
AUTH_KEY
SECURE_AUTH_KEY
LOGGED_IN_KEY
NONCE_KEY
AUTH_SALT
SECURE_AUTH_SALT
LOGGED_IN_SALT
NONCE_SALT
See also the list of default constants.
Customize path to .env file
You can override the path(s) with the following extra in your composer.json
:
{ "extra": { "wp-config-env-paths": [ "../", "../configs" ] } }
Note that the path must be relative to the wp-config.php
file. Run composer build-wp-config
to rebuild the wp-config.php
file.
Features
- Creates
wp-config.php
one level above the WordPress installation. - The
wp-config.php
includes the path to Composer's autoloader. - Searches for
.env
file with the help of PHP dotenv. - Defines all variables as constants unless a constant is already set.
- Defines reasonable default values for database, object cache, debug, URL, and path constants.
- Use
{{DIR}}
as placeholder in variable values to get it replaced with__DIR__
ofwp-config.php
. - Supports
URL_DEVELOPMENT
,URL_STAGING
, andURL_PRODUCTION
for WordPress Stage Switcher. Requires at least v2.1. - Supports loading
wp-config-prepend.php
before andwp-config-append.php
after the default config as part ofwp-config.php
. - Loads the WordPress plugin API early so actions and filters can be used.
Default Constants
If the following variables are not defined they will be assigned a default value:
Planned Features
- Allow to change required variables via
composer.json
. - Allow to change variables not used as a constant via
composer.json
. - Let us know what you think is missing…