function weaverx_fwrite_current_css()
{
    // write the current generated CSS to a file - called only from Weaver II Admin
    if (!weaverx_f_file_access_available() || !current_user_can('edit_theme_options')) {
        return '';
    }
    $save_dir = weaverx_f_uploads_base_dir() . 'weaverx-subthemes';
    $save_url = weaverx_f_uploads_base_url() . 'weaverx-subthemes';
    $usename = 'style-weaverxt.css';
    $theme_dir_exists = weaverx_f_mkdir($save_dir);
    if (!$theme_dir_exists) {
        weaverx_f_file_access_fail(__('Unable to create directory. Probably a file system permission problem. Directory', 'weaver-xtreme') . $save_dir);
    }
    $theme_dir_writable = $theme_dir_exists;
    if (!weaverx_f_is_writable($save_dir)) {
        weaverx_f_file_access_fail(__('Directory not writable. Probably a file system permission problem. Directory: ', 'weaver-xtreme') . $save_dir);
        $theme_dir_writable = false;
    }
    $filename = $save_dir . '/' . $usename;
    // we will add txt
    if (!$theme_dir_writable || !$theme_dir_exists || !($handle = weaverx_f_open($filename, 'w'))) {
        weaverx_f_file_access_fail(__('Unable to create file. Probably a file system permission problem. File: ', 'weaver-xtreme') . $filename);
        return '';
    }
    // This string goes in the generated CSS file
    weaverx_f_write($handle, sprintf("/* WARNING: Do not edit this file. It is dynamically generated. Any edits you make will be overwritten. */\n/* This file generated using %s %s subtheme: %s */\n", WEAVERX_THEMENAME, WEAVERX_VERSION, weaverx_getopt('wii_subtheme')));
    weaverx_output_style($handle);
    if (!weaverx_f_close($handle)) {
        weaverx_f_file_access_fail(__('Unable to create file. Probably a file system permission problem. File: ', 'weaver-xtreme') . $filename);
        return '';
    }
    return $save_url . '/' . $usename;
}
 function weaverx_generate_wphead()
 {
     /* this guy does ALL the work for generating theme look - it writes out the over-rides to the standard style.css */
     global $weaverx_main_options, $weaverx_cur_page_ID;
     global $post;
     $weaverx_cur_page_ID = 0;
     // need this for 404 page when this is not valid
     if (is_object($post)) {
         $weaverx_cur_page_ID = get_the_ID();
     }
     // we're on a page now, so set the post id for the rest of the session
     printf("\n<!-- This site is using %s %s (%s) subtheme: %s -->\n", WEAVERX_THEMENAME, WEAVERX_VERSION, weaverx_getopt('style_version'), weaverx_getopt('themename'));
     do_action('weaverxplus_show_version');
     if (weaverx_use_inline_css(weaverx_get_css_filename())) {
         // generate inline CSS
         echo '<style type="text/css">' . "\n";
         if (isset($_REQUEST['wp_customize'])) {
             // don't use cached CSS from customizer
             $css = '';
         } else {
             $css = weaverx_getopt_default('wvrx_css_saved', '');
         }
         if ($css == '' || $css[0] != '/') {
             // there isn't an entry in the DB, so do it on the fly
             require_once get_template_directory() . '/includes/generatecss.php';
             // include only now at runtime.
             $output = weaverx_f_open('php://output', 'w+');
             weaverx_output_style($output);
         } else {
             weaverx_echo_css($css);
         }
         echo "\n</style> <!-- end of main options style section -->\n";
     } else {
         // include generated file
         $vers = weaverx_getopt('style_version');
         if (!$vers) {
             $vers = '1';
         } else {
             $vers = sprintf("%d", $vers);
         }
         wp_enqueue_style('weaverxp-style-sheet', weaverx_get_css_url(), array('weaver-root-style-sheet'), $vers);
         wp_enqueue_style('weaverxp-style-sheet');
     }
     /* now head options */
     weaverx_echo_css(weaverx_getopt('_althead_opts'));
     weaverx_echo_css(weaverx_getopt('head_opts'));
     /* let the user have the last word! */
     $per_page_code = weaverx_get_per_page_value('page-head-code');
     if (!empty($per_page_code)) {
         weaverx_echo_css($per_page_code);
     }
     if (weaverx_is_checked_page_opt('_pp_hide_site_title')) {
         /* best to just do this inline */
         echo '<style type="text/css">#site-title,#site-tagline{display:none;}#nav-header-mini{margin-top:32px!important;}</style>' . "\n";
     }
     if ($ppsb = weaverx_get_per_page_value('_pp_sidebar_width') > 0) {
         require_once get_template_directory() . '/includes/generatecss.php';
         // include only now at runtime.
         $ppsb = weaverx_get_per_page_value('_pp_sidebar_width');
         echo "<style type=\"text/css\"> /* Per Page Sidebar Width */\n";
         weaverx_sidebar_style('echo', $ppsb);
         echo "</style>\n";
     }
     echo "\n<!-- End of Weaver Xtreme options -->\n";
 }
function weaverx_save_opts($who = '', $bump = true)
{
    // Save options
    // Here's the strategy. Using weaverx_getopt always loads the cache if it hasn't been.
    // Using weaverx_setopt will save the cache to the database by default
    // So we take advantage of this by bumping the style version, and using weaverx_setopt,
    // which saves to the database
    //$vers = weaverx_getopt('style_version');
    if ($who == 'customizer') {
        // really need to refresh the cache
        weaverx_clear_opt_cache($who);
        $old = weaverx_getopt('style_date');
        // and reload the cache
    }
    if ($bump) {
        //$vers = $vers ? $vers + 1 : 1;	// bump or init
        // put the CSS into the DB
        require_once get_template_directory() . '/includes/generatecss.php';
        unset($GLOBALS['wvrx_css_saved']);
        $GLOBALS['wvrx_css_saved'] = '';
        weaverx_f_write('wvrx_css_saved', '/* -wvrx_css- */');
        weaverx_output_style('wvrx_css_saved');
        weaverx_setopt('wvrx_css_saved', $GLOBALS['wvrx_css_saved']);
        unset($GLOBALS['wvrx_css_saved']);
    }
    weaverx_setopt('style_date', date('Y-m-d-H:i:s'), $bump);
    //weaverx_setopt('style_version',$vers, $bump);	// update options, style version
    if (weaverx_f_file_access_available()) {
        // and now is the time to update the style file
        require_once get_template_directory() . '/includes/generatecss.php';
        weaverx_fwrite_current_css();
    }
}