if (!$sidebars_widgets) {
$sidebars_widgets = array();
}
// Use ID number from new widget instance.
$new_instance_id = $id_base . '-' . $new_instance_id_number;
// Add new instance to sidebar.
$sidebars_widgets[$use_sidebar_id][] = $new_instance_id;
// Save the amended data.
update_option('sidebars_widgets', $sidebars_widgets);
// After widget import action.
$after_widget_import = array(
'sidebar' => $use_sidebar_id,
'sidebar_old' => $sidebar_id,
'widget' => $widget,
'widget_type' => $id_base,
'widget_id' => $new_instance_id,
'widget_id_old' => $widget_instance_id,
'widget_id_num' => $new_instance_id_number,
'widget_id_num_old' => $instance_id_number,
);
do_action('wie_after_widget_import', $after_widget_import);
// Success message.
if ($sidebar_available) {
$widget_message_type = 'success';
$widget_message = esc_html__('Imported', 'ansar-import');
} else {
$widget_message_type = 'warning';
$widget_message = esc_html__('Imported to Inactive', 'ansar-import');
}
}
// Result for widget instance
$results[$sidebar_id]['widgets'][$widget_instance_id]['name'] = isset($available_widgets[$id_base]['name']) ? $available_widgets[$id_base]['name'] : $id_base; // Widget name or ID if name not available (not supported by site).
$results[$sidebar_id]['widgets'][$widget_instance_id]['title'] = !empty($widget['title']) ? $widget['title'] : esc_html__('No Title', 'widget-importer-exporter'); // Show "No Title" if widget instance is untitled.
$results[$sidebar_id]['widgets'][$widget_instance_id]['message_type'] = $widget_message_type;
$results[$sidebar_id]['widgets'][$widget_instance_id]['message'] = $widget_message;
}
}
// Hook after import.
do_action('wie_after_import');
// Return results.
return apply_filters('wie_import_results', $results);
}
function ans_import_customizer_settings($custom_file) {
// Check to see if the settings have already been imported.
$template = get_template();
$imported = get_option($template . '_customizer_import', false);
// Bail if already imported.
if ($imported) {
return;
}
remove_theme_mods();
// Get the path to the customizer export file.
$path = $custom_file;
// Return if the file doesn't exist.
if (!file_exists($path)) {
return;
}
// Get the settings data.
$data = @unserialize(file_get_contents($path));
// Return if something is wrong with the data.
if ('array' != gettype($data) || !isset($data['mods'])) {
return;
}
// Import options.
if (isset($data['options'])) {
foreach ($data['options'] as $option_key => $option_value) {
update_option($option_key, $option_value);
}
}
// Import mods.
foreach ($data['mods'] as $key => $val) {
set_theme_mod($key, $val);
}
// echo 'Fixing Menu . .
';
$menu = wp_get_nav_menus();
$locations = get_theme_mod('nav_menu_locations');
foreach ($menu as $menu_key => $menu_value) {
if (array_key_exists($menu_value->name, $locations)) {
// echo "Found the Key";
$locations[$menu_value->name] = $menu_value->term_id;
}
}
set_theme_mod('nav_menu_locations', $locations);
// echo 'Seting Home and Blog page . .
';
$homepage = get_page_by_title('Home');
if ($homepage) {
update_option('page_on_front', $homepage->ID);
update_option('show_on_front', 'page');
}
$blogpage = get_page_by_title('Blog');
if ($blogpage) {
update_option('page_for_posts', $blogpage->ID);
}
}
}