I have got a establishing my theme options panel to permit the consumer to change the permalinks setting to aid friendly Web addresses. I am only permitting /%postname%/ and /%postname%.html as options.

I'd rather not be triggering an htaccess rewrite each time someone accesses a webpage on the website or sights theme options, so I am attempting to code this to prevent that.

I have got a port area in theme options that's known as $myTheme_permalinks. The default value with this is "/%postname%/" however the user may also change it out to "/%postname%.html"

Here's the code towards the top of theme options additional setting. Performs this look seem?

if(get_option('myTheme_permalinks') =="/%postname%/" && get_option('permalink_structure') !== "/%postname%/" || !get_option('myTheme_permalinks'))
{
    require_once(ABSPATH . '/wp-admin/includes/misc.php');
    require_once(ABSPATH . '/wp-admin/includes/file.php');
    global $wp_rewrite;
    $wp_rewrite->set_permalink_structure('/%postname%/');
    $wp_rewrite->flush_rules();
    update_option('permalink_structure','/%postname%/');
    update_option('myTheme_permalinks','/%postname%/');
}
else if (get_option('myTheme_permalinks') =="/%postname%.html" && get_option('permalink_structure') !== "/%postname%.html")
{
    require_once(ABSPATH . '/wp-admin/includes/misc.php');
    require_once(ABSPATH . '/wp-admin/includes/file.php');
    global $wp_rewrite;
    $wp_rewrite->set_permalink_structure('/%postname%.html');
    $wp_rewrite->flush_rules();
    update_option('permalink_structure','/%postname%.html');
}

You don't have to separate code blocks simply to add the .html. That you can do something like:

$myThemePermalinks = get_option('myTheme_permalinks');
if ( ($myThemePermalinks =="/%postname%/" && get_option('permalink_structure') !== "/%postname%/" || !$myThemePermalinks) || ($myThemePermalinks == "/%postname%.html" && get_option('permalink_structure') !== "/%postname%.html") ) {

    if (preg_match('/\.html$/', $myThemePermalinks)) {
        $ext = '.html';
    } else {
        $ext = '';
    }

    require_once(ABSPATH . '/wp-admin/includes/misc.php');
    require_once(ABSPATH . '/wp-admin/includes/file.php');
    global $wp_rewrite;
    $wp_rewrite->set_permalink_structure('/%postname%/'.$ext);
    etc..// .
}

It's not necessary to use regex if you won't want to but you get the drift. You can even result in the conditional shorter by utilizing regex to check on to have an option .html.