function enlightenment_dynamic_sidebar()
{
    if (is_admin()) {
        return;
    }
    $locations = enlightenment_sidebar_locations();
    $sidebar = enlightenment_current_sidebar_name();
    $template = '';
    if (is_404()) {
        $template = 'error404';
    } elseif (is_search()) {
        $template = 'search';
    } elseif (is_home()) {
        $template = 'blog';
    } elseif (is_page()) {
        $template = 'page';
    } elseif (is_author()) {
        $template = 'author';
    } elseif (is_date()) {
        $template = 'date';
    } elseif (is_category()) {
        $template = 'category';
    } elseif (is_tag()) {
        $template = 'post_tag';
    } elseif (is_post_type_archive()) {
        $template = get_queried_object()->name . '-archive';
    } elseif (is_singular()) {
        $template = get_post_type();
    } elseif (is_tax()) {
        $template = get_queried_object()->taxonomy;
    }
    if (isset($locations[$template][$sidebar])) {
        $template = $locations[$template][$sidebar]['sidebar'];
    }
    return apply_filters('enlightenment_dynamic_sidebar', $template);
}
function enlightenment_sidebar_heading($args = null)
{
    $defaults = array('container' => 'header', 'container_class' => 'sidebar-heading', 'container_id' => '', 'container_extra_atts' => '', 'sidebar_title_tag' => 'h2', 'sidebar_title_class' => 'sidebar-title', 'sidebar_title_id' => '', 'sidebar_title_extra_atts' => '', 'sidebar_description_tag' => 'div', 'sidebar_description_class' => 'sidebar-description', 'sidebar_description_id' => '', 'sidebar_description_extra_atts' => '', 'echo' => true);
    $defaults = apply_filters('enlightenment_sidebar_header_args', $defaults);
    $args = wp_parse_args($args, $defaults);
    $locations = enlightenment_sidebar_locations();
    $template = enlightenment_current_sidebars_template();
    $location = enlightenment_current_sidebar_name();
    $sidebars = enlightenment_registered_sidebars();
    $sidebar = $sidebars[$locations[$template][$location]['sidebar']];
    $sidebar_title = apply_filters('enlightenment_sidebar_title', $sidebar['name']);
    $sidebar_description = apply_filters('enlightenment_sidebar_description', $sidebar['description']);
    if (!$sidebar['display_title'] && !$sidebar['display_description']) {
        return;
    }
    $output = enlightenment_open_tag($args['container'], $args['container_class'], $args['container_id'], $args['container_extra_atts']);
    if ($sidebar['display_title']) {
        $output .= enlightenment_open_tag($args['sidebar_title_tag'], $args['sidebar_title_class'], $args['sidebar_title_id'], $args['sidebar_title_extra_atts']);
        $output .= $sidebar_title;
        $output .= enlightenment_close_tag($args['sidebar_title_tag']);
    }
    if ($sidebar['display_description'] && !empty($sidebar_description)) {
        $output .= enlightenment_open_tag($args['sidebar_description_tag'], $args['sidebar_description_class'], $args['sidebar_description_id'], $args['sidebar_description_extra_atts']);
        $output .= $sidebar_description . "\n";
        $output .= enlightenment_close_tag($args['sidebar_description_tag']);
    }
    $output .= enlightenment_close_tag($args['container']);
    $output = apply_filters('enlightenment_sidebar_header', $output, $args);
    if (!$args['echo']) {
        return $output;
    }
    echo $output;
}
function enlightenment_unlimited_sidebars_form_save_postdata($post_id)
{
    if (!isset($_POST['enlightenment_sidebar_locations'])) {
        return $post_id;
    }
    $nonce = $_POST['enlightenment_unlimited_sidebars_form_nonce'];
    if (!wp_verify_nonce($nonce, 'enlightenment_unlimited_sidebars_form')) {
        return $post_id;
    }
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $post_id;
    }
    $post = get_post($post_id);
    if (!current_user_can(get_post_type_object($post->post_type)->cap->edit_post, $post_id)) {
        return $post_id;
    }
    if (isset($_POST['enlightenment_default_sidebar_locations']) && $_POST['enlightenment_default_sidebar_locations']) {
        update_post_meta($post_id, '_enlightenment_sidebar_locations', '');
        return;
    }
    $input = $_POST['enlightenment_sidebar_locations'];
    $locations = enlightenment_sidebar_locations();
    global $wp_registered_sidebars;
    foreach ($input as $location => $sidebar) {
        if ('' != $location) {
            if (!isset($locations[get_post_type($post_id)])) {
                $locations[get_post_type($post_id)] = array();
            }
            if (!array_key_exists($location, $locations[get_post_type($post_id)])) {
                unset($input[$location]);
            }
            if (!array_key_exists($sidebar, $wp_registered_sidebars)) {
                unset($input[$location]);
            }
        }
    }
    update_post_meta($post_id, '_enlightenment_sidebar_locations', $input);
}