wp-configr
A Python package for reading and writing configuration values in a WordPress wp-config.php file.
Overview
A default wp-config.php might look like this:
<?php
define( 'DB_NAME', 'database_name_here' );
wpconfigr will help you update the file to:
<?php
define( 'SOMETHING_ENTIRELY_NEW', 'garnet' );
define( 'DB_NAME', 'my_blog' );
wpconfigr exposes two functions:
set(key, value)will update a property of namekeyif it exists, otherwise will create it.get(key)will return the value of the property of namekey, orNoneif it doesn't exist.
Installation
pip install wpconfigr
Command-line usage
Writing values to wp-config.php
Named parameters:
--filename: Full path and filename of thewp-config.phpfile.--key: Name of the property to create/update.--value: String value to set.--set-true: Set the value to booleantrue.--set-false: Set the value to booleanfalse.--log-level: (Optional) Log level.
python -m wpconfigr --filename /www/wp-config.php \
--key DB_NAME \
--value my_blog \
--log-level info
Reading values from wp-config.php
As above, but do not specify a value (via the --value, --set-true or --set-false arguments).
python -m wpconfigr --filename /www/wp-config.php \
--key DB_NAME
Code usage
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 wpconfigr 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')
Development
Prerequisites
wp-configr requires Python 3.x.
Installing dependencies
pip install -e .[dev]
Running tests
python test.py
Changelog
v1.4 - 2018-12-06
- Fixed bug where commented properties were read and updated.
v1.3 - 2018-12-02
- Added
--set-trueand--set-falsecommand-line flags.
v1.2 - 2018-12-02
- No longer re-writes the configuration file if nothing has changed.
v1.1 - 2018-12-02
- Added logging.
- Test runs log everything.
- Running from the command-line logs only
CRITICALby default, but can be overridden with the new optional--log-levelargument.
- Made the documentation a little clearer, and fixed a typo in a code sample.
- Replaced internal naming references to
FRACTIONALwithFLOAT. The word utterly eluded me for v1.0. - Fixed some code formatting and Pylint warnings.
- Ignore
coverageHTML reports in source control.
v1.0 - 2018-12-01
- Initial release.
Metadata
Release files for wpconfigger 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wpconfigger-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / wpconfigger-1.0.0-py3-none-any.whl
| Download URL | wpconfigger-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5ae2b23e22a1b26f6201ffb5edb2bca3b8dd24055286b002454577d0be994d03
|
|
BLAKE2b-256 checksum How to use checksums |
c5ba33b71859e0911f91273c5e032a3928cfe3d4eb03a84cf7f2302e49e14765
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.5
|