WP-CFM is a new free tool for WordPress created by Matt Gibbs, author of the popular Custom Field Suite plugin. It provides configuration management for WordPress database changes, similar to Drupal’s Features module.
WP-CFM lets you create and store bundles, which are essentially a group of one or more configuration options. The first step after installing the plugin is to create a /wp-content/config/ directory and grant write access.
WP-CFM provides a friendly interface for viewing the contents of the wp_options table so that you can select the options you want to be stored in a specific bundle. For example, let’s say that you want to grab all of your Jetpack options for deploying somewhere else. Create a Jetpack bundle:
Each bundle has options for diff, push and pull:
- diff – comparison of database version vs the file version
- push – write database changes to the file system
- pull – import file changes in the database
Selecting ‘push’ will store the database configuration in the file system (wp-content/config) as a .json file that you can then pull into your database at a later time or pull into another server.
One very common example where WP-CFM would be helpful is in the case of widgets options. Step one is to create a widgets bundle:
Next you would create a widgets diff:
From here you can push those changes to the filesystem so they’re ready to deploy at another time. Most of the time when using WP-CFM, you’ll follow this basic workflow for storing and deploying configurations:
- Make database changes
- Store them in configuration management
- Push the file to another server
The ‘push’ option on the All Bundles item writes all of your bundles to the file system at once, which is fairly handy. WP-CFM also includes developer hooks for registering custom configuration items, including a callback parameter for configuration data that is not stored within wp_options.
Deploying bundles is really easy with WP-CFM’s support for WP-CLI, which enables you to pull or push bundles from the command line. Setting the bundle_name to “all” will push/pull all at once:
wp config pull <bundle_name> wp config push <bundle_name>
Benefits of using WP-CFM
WP-CFM can save you quite a bit of time when working alone but it really shines when working with team of multiple developers. In the docs, Gibbs identifies the benefits of including it in your workflow:
- Less need to copy the database. If you make changes, Push your bundle to the filesystem. To load changes, Pull the bundle into your database.
- No need to manually apply database settings changes. No more “fire drills” where you’re rushing to figure out which settings you forgot to change.
- Track and migrate configuration files using git, subversion, etc.