Support » Plugin: OptionTree » Making Changes in Option Tree via database

  • Hello,
    I am having an issue with Option Tree whenever I attempt to make a change to the database manually. The I am editing under wp_options with the option_name… option_tree. My purpose for doing is to edit the url when moving the site from staging to production. If I make a change in anything under the option_value, the site is broken and can only be fixed by returning the value back to the original. Let’s say I have s:4:”logo”,s:88:””… etc…. and I change it to s:4:”logo”,s:88:”” the site is broken… simply meaning that the option tree commands for getting data do not return any values.
    I’m assuming there is some other reference for option tree that sets how things “should be” and when the two aren’t the same… then that breaks things. I’m also assuming it may have something to do with the export page in option tree that gives you large values for exporting settings etc from one site to another. Is that stored somewhere? Is there a way to reset it so that maybe option tree re-initializes things?
    I simply need a way to make changes to option tree without using the gui because there are a large number of options. Any help is very appreciated….

Viewing 1 replies (of 1 total)
  • So I thought I would save other people from the same frustration. The reason you can’t simply do a find and replace on the database when moving from one url to another is because the data stored in option_value for option_tree is serialized. So for every value in the array, it has the number of characters associated with it. So the values that I posted before:
    … are messed up because it thinks that there are 88 characters in the url and when there are not, it breaks the site.
    So Here’s what I did. I initially attempted to go directly to the database to put the serialized string. For some reason it failed. So I tracked down how it was done in the plugin (used the get_option(‘option_tree’)) and started the process of storing it to an array and then finding the values I needed to replace and replacing them and storing them back into the array.
    You can simply change the str_replace values with your own to make it work. After that, I attempted to serialize the array and then dump it back into the option but that didn’t work. So I am simply echoing out the serialized array and then base64 encoding it to use it in the import portion of the plugin. If you import it in using the developer’s tool… then it works like a champ. The last thing I had to do was to run a couple of update commands on the database:

    UPDATE wp_options SET option_value=replace(option_value, “”, “”);
    UPDATE wp_posts SET guid=replace(guid, “”, “”);
    UPDATE wp_options SET option_value=replace(option_value, “”, “”);
    UPDATE wp_posts SET guid=replace(guid, “”, “”);

    Here’s the php code:

    define('WP_USE_THEMES', false);
    global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
    $array = replaceVal(get_option('option_tree'));
    function replaceVal(&$array) {
    foreach ($array as $key=>$val){
    	if (is_array($val)) {
    		$val = replaceVal($val);
    	else {
    $val = str_replace('','',$val);
    		$val = str_replace('','',$val);
    			$array[$key] = $val;
    return $array;
    $serializedandencoded = base64_encode(serialize($array));
    echo '<pre>';print_r($serializedandencoded);echo '</pre>';

    I would really like a way to change the database directly without having to run the import, but it was as good as I could get with needing it really quickly.
    I could see the developer possibly adding a “change url” field so that all the pictures etc could be changed dynamically. Or maybe switching to json would alleviate painpoint as well. All just suggestions. If anyone figures out how to write it directly to the database instead of doing an import I would LOVE to see it. 🙂

Viewing 1 replies (of 1 total)
  • The topic ‘Making Changes in Option Tree via database’ is closed to new replies.