/**
  * Sets up theme defaults and registers support for various WordPress features.
  *
  * Note that this function is hooked into the after_setup_theme hook, which runs
  * before the init hook. The init hook is too late for some features, such as indicating
  * support post thumbnails.
  *
  * To override weaverx_setup() in a child theme, add your own weaverx_setup to your child theme's
  * functions.php file.
  *
  * @uses load_theme_textdomain() For translation/localization support.
  * @uses add_editor_style() To style the visual editor.
  * @uses add_theme_support() To add support for post thumbnails, automatic feed links, and Post Formats.
  * @uses register_nav_menus() To add support for navigation menus.
  * @uses register_default_headers() To register the default custom header images provided with the theme.
  * @uses set_post_thumbnail_size() To set a custom post thumbnail size
  * @uses add_theme_support( 'custom-header', $weaverx_header ) for WP 3.4+ custom header
  *
  *
  */
 function weaverx_setup()
 {
     $GLOBALS['wvrx_timer'] = microtime(true);
     // don't have options loaded, so just always get the current time.
     // Set the content width based on the theme's design and stylesheet.
     if (!isset($content_width)) {
         $content_width = 705;
     }
     // 940 * .75 - default for content with a sidebar
     /* Make Weaver Xtreme available for translation.
      *
      * We will first allow the possibility that the user has a private translation in
      * wp-content/languages/ (to avoid the update overwrite problem), then load the theme's files.
      */
     load_theme_textdomain('weaver-xtreme', get_template_directory() . '/languages');
     // now theme's translations as fallback
     // This theme styles the visual editor with editor-style.css to match the theme style.
     add_editor_style();
     //add_editor_style( str_replace( ',', '%2C', 'https://fonts.googleapis.com/css?family=Alegreya+Sans:400,700,400italic,700italic|Alegreya:400,700,700italic,400italic|Roboto:400,400italic,700,700italic|Roboto+Condensed:400,700|Roboto+Slab:400,700|Source+Sans+Pro:400,400italic,700,700italic|Source+Serif+Pro:400,700|Handlee|Inconsolata&subset=latin-ext,latin,cyrillic,greek' ) );
     add_editor_style(str_replace(',', '%2C', "https://fonts.googleapis.com/css?family=Open+Sans:400,700,700italic,400italic|Open+Sans+Condensed:300,700|Alegreya:400,400italic,700,700italic|Alegreya+Sans:400,400italic,700,700italic|Droid+Sans:400,700|Droid+Serif:400,400italic,700,700italic|Exo+2:400,700|Lato:400,400italic,700,700italic|Lora:400,400italic,700,700italic|Arvo:400,700,400italic,700italic|Roboto:400,400italic,700,700italic|Roboto+Condensed:400,700|Roboto+Slab:400,700|Archivo+Black|Source+Sans+Pro:400,400italic,700,700italic|Source+Serif+Pro:400,700|Vollkorn:400,400italic,700,700italic|Arimo:400,700|Tinos:400,400italic,700,700italic|Roboto+Mono:400,700|Inconsolata|Handlee|Ultra&subset=latin,latin-ext"));
     // Add default posts and comments RSS feed links to <head>.
     add_theme_support('automatic-feed-links');
     // html5 for search
     add_theme_support('html5', array('search-form'));
     // Weaver Xtreme supports two main nav menus
     register_nav_menus(array('primary' => __('Primary Navigation: if specified, used instead of Default menu', 'weaver-xtreme'), 'secondary' => __('Secondary Navigation: if specified, adds 2nd menu bar', 'weaver-xtreme'), 'header-mini' => __('Header Mini Menu: if specified, adds horizontal mini-menu to header', 'weaver-xtreme')));
     // Add support for a variety of post formats
     add_theme_support('post-formats', array('aside', 'audio', 'gallery', 'image', 'link', 'quote', 'status', 'video'));
     // This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images
     add_theme_support('post-thumbnails');
     add_theme_support('title-tag');
     // now, need Weaver Xtreme settings available for everything else
     weaverx_init_opts('functions');
     $width = weaverx_getopt_default('theme_width_int');
     if (!$width) {
         $width = 940;
     }
     $height = weaverx_getopt('header_image_height_int');
     if (!$height) {
         $height = 188;
     }
     // now that everything is responsive, we can just set this to an arbitrary height.
     global $weaverx_header;
     $weaverx_header = array('default-image' => '%s/assets/images/headers/maroon-bells.jpg', 'random-default' => true, 'width' => $width, 'height' => $height, 'flex-height' => true, 'flex-width' => true, 'default-text-color' => '', 'header-text' => false, 'uploads' => true, 'wp-head-callback' => '', 'admin-head-callback' => 'weaverx_admin_header_style', 'admin-preview-callback' => '');
     global $content_width;
     $content_width = $width;
     // let the WP $content_width be the same as theme width, and let our responsive CSS make it work.
     if (function_exists('get_custom_header')) {
         add_theme_support('custom-header', $weaverx_header);
         add_theme_support('custom-background');
     }
     // We'll be using post thumbnails for custom header images on posts and pages.
     // We want them to be the size of the header image that we just defined
     // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
     // CHANGE NOTE: This call was removed from Weaver Xtreme 1.1. The semantics of WP have changed
     // since this was first added and was causing the unnecessary auto-generation of a pretty large
     // file for each and every image added to the media library.
     // set_post_thumbnail_size( $weaverx_header['width'], $weaverx_header['height'], true );
     // ... and thus ends the changeable header business.
     weaverx_register_header_images();
 }
function weaverx_process_options_themes()
{
    if (weaverx_submitted('set_subtheme')) {
        // invoked from Weaver Xtreme Subthemes tab (this file)
        if (isset($_POST['theme_picked'])) {
            $theme = weaverx_filter_textarea($_POST['theme_picked']);
            if (weaverx_activate_subtheme($theme)) {
                weaverx_save_msg(__("Subtheme Selected: ", 'weaver-xtreme') . $theme);
            } else {
                weaverx_save_msg(__("Invalid Subtheme file detected. Your installation of Weaver Xtreme may be broken.", 'weaver-xtreme'));
            }
        } else {
            weaverx_save_msg(__("Please select a subtheme.", 'weaver-xtreme'));
        }
        return true;
    }
    if (weaverx_submitted('save_mytheme')) {
        // invoked from Save/Restore tab
        weaverx_save_msg(__("Current settings saved in WordPress database.", 'weaver-xtreme'));
        global $weaverx_opts_cache;
        if (!$weaverx_opts_cache) {
            $weaverx_opts_cache = get_option(apply_filters('weaverx_options', 'weaverx_settings'), array());
        }
        if (current_user_can('manage_options')) {
            $compressed = array_filter($weaverx_opts_cache, 'strlen');
            // filter out all null options (strlen == 0)
            update_option(apply_filters('weaverx_options', 'weaverx_settings_backup'), $compressed);
            if (apply_filters('weaverx_xtra_type', '+backup') != 'inactive') {
                delete_option('weaverx_plus_backup');
            }
        }
        return true;
    }
    if (weaverx_submitted('restore_mytheme')) {
        // invoked from Save/Restore tab
        global $weaverx_opts_cache;
        $saved = get_option(apply_filters('weaverx_options', 'weaverx_settings_backup'), array());
        if (!empty($saved)) {
            $weaverx_opts_cache = $saved;
            weaverx_wpupdate_option('weaverx_settings', $weaverx_opts_cache);
        }
        weaverx_save_msg(__("Current settings restored from WordPress database.", 'weaver-xtreme'));
        return true;
    }
    if (weaverx_submitted('hide_thumbs')) {
        $hide = weaverx_getopt('_hide_theme_thumbs');
        weaverx_setopt('_hide_theme_thumbs', !$hide);
        return true;
    }
    // save/restore options
    if (weaverx_submitted('weaverx_clear_messages')) {
        return true;
    }
    if (weaverx_submitted('reset_weaverx')) {
        if (!current_user_can('manage_options')) {
            wp_die(__('You do not have the capability to do that.', 'weaver-xtreme'));
        }
        // delete everything!
        weaverx_save_msg(__('All Weaver Xtreme settings have been reset to the defaults.', 'weaver-xtreme'));
        delete_option(apply_filters('weaverx_options', 'weaverx_settings'));
        global $weaverx_opts_cache;
        $weaverx_opts_cache = false;
        // clear the cache
        weaverx_init_opts('reset_weaverx');
        delete_option(apply_filters('weaverx_options', 'weaverx_settings_backup'));
        do_action('weaverxplus_admin', 'reset_weaverxplus');
        update_user_meta(get_current_user_id(), 'tgmpa_dismissed_notice', 0);
        // reset the dismiss on the plugin loader
        return true;
    }
    if (weaverx_submitted('uploadtheme') && function_exists('weaverx_loadtheme')) {
        weaverx_loadtheme();
        return true;
    }
    return false;
}
function weaverx_process_options_admin_standard($processed)
{
    if (weaverx_submitted('weaverx_clear_messages')) {
        return true;
    }
    if (weaverx_submitted('reset_weaverx')) {
        if (!current_user_can('manage_options')) {
            wp_die(__('You do not have the capability to do that.', 'weaver-xtreme'));
        }
        // delete everything!
        weaverx_save_msg(__('All Weaver Xtreme settings have been reset to the defaults.', 'weaver-xtreme'));
        delete_option(apply_filters('weaverx_options', 'weaverx_settings'));
        global $weaverx_opts_cache;
        $weaverx_opts_cache = false;
        // clear the cache
        weaverx_init_opts('reset_weaverx');
        delete_option(apply_filters('weaverx_options', 'weaverx_settings_backup'));
        do_action('weaverxplus_admin', 'reset_weaverxplus');
        update_user_meta(get_current_user_id(), 'tgmpa_dismissed_notice', 0);
        // reset the dismiss on the plugin loader
        return true;
    }
    if (weaverx_submitted('uploadtheme') && function_exists('weaverx_loadtheme')) {
        weaverx_loadtheme();
        return true;
    }
    return $processed;
}