Using wp-cli to edit a WordPress options array

So you probably know that you can change WordPress options directly in the database with an SQL query, and maybe you’ve come across the /wp-admin/options.php page where you can edit them directly from WordPress. But if the options are held as serialized data, then it gets a bit more tricky. Luckily wp-cli can help.

I’ll assume you can figure out how to download and install wp-cli yourselves. On this occasion I was trying to get rid of the annoying pop-up screen of Really Simple SSL plugin. It should disappear, never to return, when you click the x in the corner of the message, but in my case it was coming back every time I loaded every single page. Which was irritating, to say the least, and it takes up a fair chunk of space at the top of the screen. So I decided to nail it for once and for all. I found out on Google that the key was altering the rlrsssl_options => ssl_success_message_shown option.

So if you use wp-cli to get the option value it looks like this:

wp-cli option get rlrsssl_options
array (
  'site_has_ssl' => true,
  'hsts' => false,
  'htaccess_warning_shown' => false,
  'review_notice_shown' => false,
  'ssl_success_message_shown' => false,
  'autoreplace_insecure_links' => true,
  'plugin_db_version' => '3.3.5',
  'debug' => false,
  'do_not_edit_htaccess' => false,
  'htaccess_redirect' => true,
  'ssl_enabled' => true,
  'javascript_redirect' => false,
  'wp_redirect' => true,
  'switch_mixed_content_fixer_hook' => false,
  'dismiss_all_notices' => false,
  'dismiss_review_notice' => false,

There is also the option to display that as json, which is what we need, so lets do that, and pipe it out to a text file.

wp-cli option get rlrsssl_options --format=json > ssl.txt

cat ssl.txt 

So now we edit the ssl.txt file and change this bit from false to true.


Then we can just send that json file back into the database with the following:

wp-cli option update rlrsssl_options --format=json < ssl.txt

Leave a Comment