A Python package for reading and writing configuration values in a WordPress wp-config.php file.
MIT License
A Python package for reading and writing configuration values in a WordPress wp-config.php
file.
A default wp-config.php
might look like this:
<?php
define( 'DB_NAME', 'database_name_here' );
wpconfigger
will help you update the file to:
<?php
define( 'SOMETHING_ENTIRELY_NEW', 'garnet' );
define( 'DB_NAME', 'my_blog' );
wpconfigger
exposes two functions:
set(key, value)
will update a property of name key
if it exists, otherwise will create it.get(key)
will return the value of the property of name key
, or None
if it doesn't exist.pip install wpconfigger
Named parameters:
--filename
: Full path and filename of the wp-config.php
file.--key
: Name of the property to create/update.--value
: String value to set.--set-true
: Set the value to boolean true
.--set-false
: Set the value to boolean false
.--log-level
: (Optional) Log level.python -m wpconfigger --filename /www/wp-config.php \
--key DB_NAME \
--value my_blog \
--log-level info
As above, but do not specify a value (via the --value
, --set-true
or --set-false
arguments).
python -m wpconfigger --filename /www/wp-config.php \
--key DB_NAME
To update a string holding wp-config.php
content:
from wpconfigr import WpConfigString
config = WpConfigString(config_string)
config.set('DB_NAME', 'my_blog')
updated_config_string = config.content
To directly update a wp-config.php
file:
from wpconfigger import WpConfigFile
config = WpConfigFile(filename)
config.set('DB_NAME', 'my_blog')
# File is updated immediately after each property update.
To read a property value:
db_name = config.get('DB_NAME')
wpconfigger
requires Python 3.x.
pip install -e .[dev]
python test.py
wpconfigger
.--set-true
and --set-false
command-line flags.CRITICAL
by default, but can be overridden with the new optional --log-level
argument.FRACTIONAL
with FLOAT
. The word utterly eluded me for v1.0.coverage
HTML reports in source control.