2

I created a theme while back when I was new to Customizer API and for some weird reasons I named theme settings as:

$wp_customize->add_setting('thefunk_theme_options[header_color]

Instead of just header_color and saved every setting in an array like thefunk_theme_options[header_color]

So I recently found out that it's generating some issues, so I want to save every setting, let's say, thefunk_theme_options[header_color] to header_color or thefunk_header_color.

Now I know how I can change the settings in the Customizer. However, it will affect everyone who is currently using the theme. All the customization will be gone, so does any one know how I can import the data from the old tables and add it to the new tables?

  • Are you sure the old data is removed, I don't think so. In that case just try to change the old data's key to the new one. – Fleuv Dec 28 '15 at 7:07
  • @Fleuv I mean data is removed from their site, not database. But how can I change keys of 30-40 some options? Any idea? – Hardeep Asrani Dec 28 '15 at 10:20
  • I dont know the solution you are looking for. But I am interested what type of problem you faced. I am using like you did in my several themes. – Nilambar Sharma Apr 17 '16 at 17:40
0

Personally I think keeping your mods in an array is a nice solution, but transferring them shouldn't be too difficult. Just loop through the array like this:

$all_mods = get_theme_mod('thefunk_theme_options'); // retrieve array
foreach ($all_mods as $key -> $value) {
    if (!empty($value)) set_theme_mod ($key,$value); // set array element as separate mod
    } 

Since you have to do this only once, when the updated theme is ran first, you may want to insert an extra check upfront and delete the array afterwards.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.