The approach is rather manual at first, but once done, it should allow for automating it all through using wp option update
.
Here are the steps:
- Install a clean WP instance.
- Configure the plugin in interest on that instance.
- Check all the wp_options settings entries that were created after the plugin activation.
- Consider whether the plugin configuration might have changed already existing settings on the site in wp_options table, as these will have to be added to the list too.
- Consider whether the plugin configuration might be keeping settings or data in other database tables, so that means of automating theese will have to be “invented” too.
- Consider whether any of the options values should be v
- For each wp_options entry that has been created or changed, we should create a corresponding WP-CLI command like this:
- When the value is a simple string or a number:
wp option update OPTION_NAME "OPTION_VALUE"
- When the value is a serialized object or array:
wp option update OPTION_NAME 'OPTION_VALUE' --format="json"
- When the value is a simple string or a number:
OPTION_VALUE in 4.2. is formed by getting the actual serialized string from the database and passing it through the unserialize() function in PHP. One could use php -a
(the interactive mode) for executing the followin line: ‘var_export( unserialize( ‘OPTION_VALUE’ ) );which would print a data structure, in which
array()wrappers should be replaced by
[]` in order to reach a valid JSON format.
- Testing each
wp option update
line against the test database and checking the values in the database + the plugin settings page for any issues is the final step that would verify that the commands are doing their job.