Skip to content

Скептична яма за идеи

и други бележки към мене си

  • начало
  • tech
  • блог
  • здраве
  • приключения
  • ядене
  • бизнес
  • деца
  • Кой?

Automating plugin settings with WP CLI

Posted on 2021.01.18 by vloo

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:

  1. Install a clean WP instance.
  2. Configure the plugin in interest on that instance.
  3. Check all the wp_options settings entries that were created after the plugin activation.
    1. 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.
    2. 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.
    3. Consider whether any of the options values should be v
  4. For each wp_options entry that has been created or changed, we should create a corresponding WP-CLI command like this:
    1. When the value is a simple string or a number: wp option update OPTION_NAME "OPTION_VALUE"
    2. When the value is a serialized object or array: wp option update OPTION_NAME 'OPTION_VALUE' --format="json"

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 whicharray()wrappers should be replaced by[]` in order to reach a valid JSON format.

  1. 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.
Posted in techTagged automation, wordpress

Post navigation

Качамак по древнотракийски
Никой не е по-важен

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Proudly powered by WordPress | Theme: micro, developed by DevriX.