Skip to content

Instantly share code, notes, and snippets.

@maxchirkov
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxchirkov/1b806fa9bf3a5f90b4c8 to your computer and use it in GitHub Desktop.
Save maxchirkov/1b806fa9bf3a5f90b4c8 to your computer and use it in GitHub Desktop.
Widgets Mapper from previous to the current theme
<?php
add_action('after_setup_theme', 'mapThemeWidgets');
function mapThemeWidgets()
{
$theme_slug = 'twentytwelve';
// Hash of old to new sidebar IDs
$map = array(
'sidebar-1' => 'hjitw-right-widgets',
'sidebar-2' => 'hjitw-footerwidgets'
);
// Previous theme's sidebar IDs
if ($old_sidebars = get_option('theme_mods_' . $theme_slug))
{
// Current theme's sidebar IDs
$current_sidebars = get_option('sidebars_widgets');
// Assign old sidebar's content to the new sidebars via the hashmap
foreach ($old_sidebars['sidebars_widgets']['data'] as $sidebar => $data)
{
$newSidebar = $map[$sidebar];
$current_sidebars[$newSidebar] = $data;
}
// Update current sidebars option
update_option('sidebars_widgets', $current_sidebars);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment