Last active
August 29, 2015 14:13
-
-
Save maxchirkov/1b806fa9bf3a5f90b4c8 to your computer and use it in GitHub Desktop.
Widgets Mapper from previous to the current theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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