/**
 * Adds the classes to the widget in the front-end
 */
function weaverx_add_widget_classes($params)
{
    global $wp_registered_widgets;
    $arr_registered_widgets = wp_get_sidebars_widgets();
    // Get an array of ALL registered widgets
    $sb_id = $params[0]['id'];
    // Get the id for the current sidebar we're processing
    $widget_id = $params[0]['widget_id'];
    // add first, last, even, and odd, and widget classes
    $area_map = array('primary-widget-area' => 'primary', 'secondary-widget-area' => 'secondary', 'footer-widget-area' => 'footer', 'sitewide-top-widget-area' => 'top', 'page-top-widget-area' => 'top', 'postpages-widget-area' => 'top', 'blog-top-widget-area' => 'top', 'sitewide-bottom-widget-area' => 'bottom', 'page-bottom-widget-area' => 'bottom', 'blog-bottom-widget-area' => 'bottom', 'header-widget-area' => 'header_sb', 'footer-widget-area' => 'footer_sb', 'primary' => 'primary', 'secondary' => 'secondary', 'widget' => 'widget', 'header' => 'header_sb', 'footer' => 'footer_sb', 'top' => 'top', 'bottom' => 'bottom');
    $opt_name = 'widget';
    // default styling option name: widget-xxx
    $search_sb_id = $sb_id;
    if (weaverx_t_get('use_widget_area')) {
        // map from replacement area or [extra_widget_area]
        $search_sb_id = weaverx_t_get('use_widget_area');
    }
    foreach ($area_map as $area => $opt) {
        // need to find name to use for option values
        if ($search_sb_id == $area) {
            $opt_name = $opt;
            break;
        }
    }
    $cols = weaverx_getopt_default($opt_name . '_cols_int', 1);
    if ($cols > 8) {
        $cols = 8;
    }
    // sanity check
    $show_number = true;
    $show_evenodd = true;
    if (!isset($arr_registered_widgets[$sb_id]) || !is_array($arr_registered_widgets[$sb_id])) {
        return $params;
    }
    if (empty($GLOBALS['wvr_widget_number']) || !isset($GLOBALS['wvr_widget_number']) || !$GLOBALS['wvr_widget_number']) {
        // global to keep track of which widget this is
        $GLOBALS['wvr_widget_number'] = array();
    }
    if (isset($GLOBALS['wvr_widget_number'][$sb_id])) {
        // initialize or bump widget number
        $GLOBALS['wvr_widget_number'][$sb_id]++;
    } else {
        $GLOBALS['wvr_widget_number'][$sb_id] = 1;
    }
    $is_sidebar = in_array($sb_id, array('primary-widget-area', 'secondary-widget-area'));
    // this is a vertical widget
    $no_smart = weaverx_getopt($opt_name . '_no_widget_margins');
    $is_vert = $cols == 1;
    $per_row_tail = $is_vert || $no_smart ? ' ' : '-m ';
    $class = '';
    $sides = $is_sidebar ? '-b' : '-rb';
    $cur_widget = $GLOBALS['wvr_widget_number'][$sb_id];
    $widget_count = count($arr_registered_widgets[$sb_id]);
    $first = $cur_widget == 1;
    $last = $cur_widget == $widget_count;
    $def_bottom = 'margin-bottom';
    if ($opt_name == 'header_sb') {
        $def_bottom = 'no-margin-vertical ';
    }
    $area_class = weaverx_area_class('widget', 'not-pad', $sides, $def_bottom) . ' ';
    if ($area_class) {
        $class .= $area_class;
    }
    if (!$is_vert) {
        $class .= 'per-row-' . $cols . $per_row_tail;
        $end_of_row = $cur_widget % $cols == 0;
        if ($widget_count > 1 && !$end_of_row && !$no_smart) {
            $class .= 'smart-rm ';
        }
        if ($end_of_row) {
            $class .= 'end-of-row ';
        }
        if ($cur_widget % $cols == 1) {
            $class .= 'begin-of-row ';
        }
    }
    $class .= 'widget-' . $GLOBALS['wvr_widget_number'][$sb_id] . ' ';
    if ($is_vert) {
        $widget_first = 'widget-first widget-first-vert ';
        $widget_last = 'widget-last widget-last-vert ';
    } else {
        $widget_first = 'widget-first ';
        $widget_last = 'widget-last ';
    }
    if ($first) {
        $class .= $widget_first;
    }
    if ($last) {
        $class .= $widget_last;
    }
    if ($show_evenodd) {
        $widget_even = 'widget-even ';
        $widget_odd = 'widget-odd ';
        $class .= $cur_widget % 2 ? $widget_odd : $widget_even;
    }
    // need no-margin-bottom if $cols > 1
    $params[0]['before_widget'] = str_replace('">', ' ' . trim($class) . '">', $params[0]['before_widget']);
    $title_class = weaverx_title_class('widget_title', true);
    if ($title_class) {
        $params[0]['before_title'] = str_replace('">', ' ' . trim($title_class) . '">', $params[0]['before_title']);
    }
    return $params;
}
function weaverx_excerpt_length($length)
{
    /**
     * Sets the post excerpt length to 40 words.
     *
     * To override this length in a child theme, remove the filter and add your own
     * function tied to the excerpt_length filter hook.
     */
    $val = weaverx_t_get('excerpt_length');
    if (!$val) {
        $val = weaverx_getopt('excerpt_length');
    }
    if ($val > 0 || $val === '0') {
        return $val;
    }
    return 40;
}
function weaverx_do_excerpt()
{
    // return true if this kind of page should be excerpted
    if (weaverx_t_get('show') == 'excerpt') {
        // for Weaver Xtreme Plus
        return true;
    }
    if (weaverx_t_get('show') == 'full') {
        // for Weaver Xtreme Plus
        return false;
    }
    if (weaverx_is_checked_post_opt('_pp_force_post_excerpt')) {
        return true;
    }
    if (weaverx_is_checked_post_opt('_pp_force_post_full')) {
        return false;
    }
    $n1 = weaverx_get_per_page_value('_pp_fullposts');
    if (!$n1) {
        $n1 = weaverx_getopt('fullpost_first');
    }
    if ($n1) {
        global $page, $paged;
        if (!($paged >= 2 || $page >= 2) && weaverx_post_count() <= $n1) {
            return false;
        }
    }
    $pwp = weaverx_get_per_page_value('_pp_wvrx_pwp_type');
    if ($pwp == 'full') {
        // need to check before archive/search
        return false;
    }
    // override global setting
    if ($pwp == 'excerpt') {
        return true;
    }
    // override global setting
    if (is_search()) {
        return !weaverx_getopt_checked('fullpost_search');
    }
    if (is_archive()) {
        return !weaverx_getopt_checked('fullpost_archive');
    }
    return !weaverx_getopt_checked('fullpost_blog');
}