From http://wp-snippets.com/set-permalink-settings-from-functions-php/