{"id":606,"date":"2020-09-04T14:15:37","date_gmt":"2020-09-04T06:15:37","guid":{"rendered":"https:\/\/play.datalude.com\/blog\/?p=606"},"modified":"2020-09-04T14:18:46","modified_gmt":"2020-09-04T06:18:46","slug":"using-wp-cli-to-edit-wordpress-options-array","status":"publish","type":"post","link":"https:\/\/play.datalude.com\/blog\/2020\/09\/using-wp-cli-to-edit-wordpress-options-array\/","title":{"rendered":"Using wp-cli to edit a WordPress options array"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">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 <a href=\"https:\/\/play.datalude.com\/blog\/2017\/02\/secret-wordpress-options-page\/\" data-type=\"post\" data-id=\"383\">\/wp-admin\/options.php<\/a> 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. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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 <em>every time I loaded every single page<\/em>. 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 <strong>rlrsssl_options => ssl_success_message_shown<\/strong> option. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So if you use wp-cli to get the option value it looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp-cli option get rlrsssl_options\narray (\n  'site_has_ssl' => true,\n  'hsts' => false,\n  'htaccess_warning_shown' => false,\n  'review_notice_shown' => false,\n  'ssl_success_message_shown' => false,\n  'autoreplace_insecure_links' => true,\n  'plugin_db_version' => '3.3.5',\n  'debug' => false,\n  'do_not_edit_htaccess' => false,\n  'htaccess_redirect' => true,\n  'ssl_enabled' => true,\n  'javascript_redirect' => false,\n  'wp_redirect' => true,\n  'switch_mixed_content_fixer_hook' => false,\n  'dismiss_all_notices' => false,\n  'dismiss_review_notice' => false,\n)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">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. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp-cli option get rlrsssl_options --format=json > ssl.txt\n\ncat ssl.txt \n{\"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}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So now we edit the ssl.txt file and change this bit from false to true.<\/p>\n\n\n\n<pre id=\"block-e88dfd60-88c4-4e0b-a0aa-c088a9cdaebf\" class=\"wp-block-code\"><code>\"ssl_success_message_shown\":true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then we can just send that json file back into the database with the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wp-cli option update rlrsssl_options --format=json &lt; ssl.txt<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8230; <a title=\"Using wp-cli to edit a WordPress options array\" class=\"read-more\" href=\"https:\/\/play.datalude.com\/blog\/2020\/09\/using-wp-cli-to-edit-wordpress-options-array\/\" aria-label=\"Read more about Using wp-cli to edit a WordPress options array\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1,137],"tags":[],"class_list":["post-606","post","type-post","status-publish","format-standard","hentry","category-it","category-wordpress"],"_links":{"self":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts\/606","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/comments?post=606"}],"version-history":[{"count":0,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/posts\/606\/revisions"}],"wp:attachment":[{"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/media?parent=606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/categories?post=606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/play.datalude.com\/blog\/wp-json\/wp\/v2\/tags?post=606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}