$widgets) { // Skip if sidebar is not valid if ($sidebar === 'wp_inactive_widgets') { $sidebars_widgets[$sidebar] = array_keys($widgets); continue; } $sidebar_widgets = []; foreach ($widgets as $widget_id => $widget_data) { // Extract base widget ID (e.g., rs_info_box_widget from rs_info_box_widget-2) $widget_base_id = preg_replace('/-\d+$/', '', $widget_id); // Get existing widget data or initialize it $existing_widget_data = get_option('widget_' . $widget_base_id, []); // Merge or update the widget instance data foreach ($widget_data as $instance_id => $instance_settings) { if ($instance_id === '_multiwidget') { $existing_widget_data['_multiwidget'] = $instance_settings; } else { $existing_widget_data[$instance_id] = $instance_settings; } } // Update the widget settings in the database update_option('widget_' . $widget_base_id, $existing_widget_data); // Add widget ID to the sidebar $sidebar_widgets[] = $widget_id; } // Assign widgets to the sidebar $sidebars_widgets[$sidebar] = $sidebar_widgets; } // Update the sidebars_widgets option update_option('sidebars_widgets', $sidebars_widgets); return true; } // Import Customizer Settings // function author_portfolio_import_customizer_settings_from_json_url($json_file_path) { // if (!file_exists($json_file_path)) { // return false; // } // $json_data = file_get_contents($json_file_path); // $customizer_data = json_decode($json_data, true); // if (!is_array($customizer_data)) { // return false; // } // foreach ($customizer_data as $key => $value) { // set_theme_mod($key, $value); // } // return true; // } function author_portfolio_import_customizer_settings_from_json_url($json_file_path = '') { if (!file_exists($json_file_path)) { return false; } $json_data = file_get_contents($json_file_path); $customizer_data = json_decode($json_data, true); if (!is_array($customizer_data)) { return false; } foreach ($customizer_data as $key => $value) { // Handle logo settings with attachment ID validation and URL fallback if (in_array($key, ['custom_logo', 'footer_logo'])) { if (author_portfolio_attachment_id_exists($value)) { set_theme_mod($key, $value); } else { // Fallback to URL if provided $image_url_key = $key . '_url'; if (isset($customizer_data[$image_url_key]) && $new_id = author_portfolio_import_image_from_url($customizer_data[$image_url_key])) { set_theme_mod($key, $new_id); } else { error_log("Attachment ID {$value} for '{$key}' not found and no valid URL provided."); remove_theme_mod($key); } } } else { set_theme_mod($key, $value); } } return true; }