{"id":4243,"date":"2016-06-01T12:59:44","date_gmt":"2016-06-01T12:59:44","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=4243"},"modified":"2016-06-01T12:59:44","modified_gmt":"2016-06-01T12:59:44","slug":"wordpress-exporting-settings-plugin","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/wordpress-exporting-settings-plugin\/","title":{"rendered":"WordPress: Exporting Settings for a plugin"},"content":{"rendered":"<p>Since every WordPress plugin runs custom PHP code, it can write to the filesystem, your database, and potentially remote storage (e.g. if you use a DropBox backup plugin). In this example I&#8217;m going to show how to export settings for iThemes security, since this has a moderately complex installation.<\/p>\n<p>To see what this look like, you can log into your database and list out the tables:<\/p>\n<pre lang=\"sql\">\nmysql -u root -p\nselect garysielingcom;\nshow tables;\n<\/pre>\n<pre>\n+---------------------------+\n| Tables_in_garysielingcom  |\n+---------------------------+\n| wp_appsin_settings        |\n| wp_commentmeta            |\n| wp_comments               |\n| wp_cpd_counter            |\n| wp_easy_todo              |\n| wp_itsec_lockouts         |\n| wp_itsec_log              |\n| wp_itsec_temp             |\n| wp_layerslider            |\n| wp_links                  |\n| wp_nf_objectmeta          |\n| wp_nf_objects             |\n| wp_nf_relationships       |\n| wp_ninja_forms_fav_fields |\n| wp_ninja_forms_fields     |\n| wp_options                |\n| wp_popularpostsdata       |\n| wp_popularpostssummary    |\n| wp_postmeta               |\n| wp_posts                  |\n| wp_term_relationships     |\n| wp_term_taxonomy          |\n| wp_termmeta               |\n| wp_terms                  |\n| wp_usermeta               |\n| wp_users                  |\n| wp_wsal_metadata          |\n| wp_wsal_occurrences       |\n+---------------------------+\n<\/pre>\n<p>Some of these are obviously WordPress tables (wp_posts, wp_users, etc), but several are for plugins I&#8217;ve installed (e.g. WP Security has several &#8211; wp_itsec_lockouts, wp_itsec_log, and wp_itsec_temp). The &#8220;wp_&#8221; part of the table name is configured at install time &#8211; if you have multiple WordPress installs in a database they would have different prefixes. This indicates that WordPress plugins with this prefix are using a WordPress API to set the table up.<\/p>\n<p>Consequently, if you want to see where these are created, you need to search your site for the table name without the prefix:<\/p>\n<pre lang=\"bash\">\ngrep -irl itsec_temp *    \n<\/pre>\n<pre>\nwp-content\/plugins\/better-wp-security\/core\/class-itsec-setup.php\nwp-content\/plugins\/better-wp-security\/core\/class-itsec-lockout.php\nwp-content\/plugins\/better-wp-security\/core\/modules\/backup\/settings.php\nwp-content\/plugins\/better-wp-security\/core\/class-itsec-lib.php\n<\/pre>\n<p>To export one of these tables, you can use &#8220;mysqldump&#8221;, like so:<\/p>\n<pre lang=\"bash\">\nmysqldump -p garysielingcom wp_itsec_lockouts > wp_itsec_lockouts.sql\n<\/pre>\n<p>When you inspect these, you&#8217;ll see that iThemes Security has a &#8220;create_database_tables&#8221; function that creates the above tables. However, it also shows that WordPress has settings that are tied to the site<sup><a href=\"#footnote_0_4243\" id=\"identifier_0_4243\" class=\"footnote-link footnote-identifier-link\" title=\"https:\/\/codex.wordpress.org\/Function_Reference\/add_site_option\">1<\/a><\/sup>, rather than the plugin. <\/p>\n<p>These are stored in &#8220;wp_options&#8221;:<\/p>\n<pre lang=\"sql\">\nmysql> select * from wp_options limit 10;\n<\/pre>\n<pre>\n+-----------+--------------------+----------------------------------+----------+\n| option_id | option_name        | option_value                     | autoload |\n+-----------+--------------------+----------------------------------+----------+\n|         3 | siteurl            | https:\/\/www.garysieling.com\/blog | yes      |\n|         4 | blogname           | Gary Sieling                     | yes      |\n|         5 | blogdescription    | Philadelphia Software Developer  | yes      |\n|         6 | users_can_register | 0                                | yes      |\n|         7 | admin_email        | gary@garysieling.com             | yes      |\n|         8 | start_of_week      | 1                                | yes      |\n|         9 | use_balanceTags    | 0                                | yes      |\n|        10 | use_smilies        | 1                                | yes      |\n|        11 | require_name_email | 1                                | yes      |\n|        12 | comments_notify    | 1                                | yes      |\n+-----------+--------------------+----------------------------------+----------+\n<\/pre>\n<p>The iThemes security values are a bit long, but you can see there are 17 of them:<\/p>\n<pre lang=sql\">\n select count(*) from wp_options where option_name like 'itsec%';\n<\/pre>\n<pre>\n+----------+\n| count(*) |\n+----------+\n|       17 |\n+----------+\n<\/pre>\n<p>You can then use the mysqldump command above, but just exporting the relevant values from iThemes Security:<\/p>\n<pre lang=\"sql\">\nmysqldump -p garysielingcom wp_options --where=\"option_name like 'itsec%'\" > wp_options.sql\n<\/pre>\n<p>To re-import these settings, you just need to run statements to delete the values you&#8217;re importing, then re-run the SQL scripts you&#8217;ve created. Deleting the values that match what you export allows you to simply re-import (i.e. there would be no issues merging values the plugin install code may have created if you&#8217;re migrating to another site).<\/p>\n<ol class=\"footnotes\"><li id=\"footnote_0_4243\" class=\"footnote\">https:\/\/codex.wordpress.org\/Function_Reference\/add_site_option<span class=\"footnote-back-link-wrapper\"> [<a href=\"#identifier_0_4243\" class=\"footnote-link footnote-back-link\">&#8617;<\/a>]<\/span><\/li><\/ol>","protected":false},"excerpt":{"rendered":"<p>How to approach exporting settings for a Wordpress plugin<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[12],"tags":[601],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4243"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=4243"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/4243\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=4243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=4243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=4243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}