I'm calling the function below after each "save changes" on my plugin's settings file via the sanitization callback.
The plugin allows the end user to change their category base, and needs to completely rewrite the permalinks in order to avoid 404 errors. However, I'm still getting 404s. The only way I can resolve them is to go to the "Settings > Permalinks" manager and clicking "Save Changes".
What am I missing in this function to get rid of the 404s?
function myplugin_refresh() {
wp_cache_flush();
global $wp_rewrite;
$my_permalinks = get_option('permalink_structure');
$wp_rewrite->set_permalink_structure($my_permalinks);
$wp_rewrite->flush_rules();
}