function enlightenment_current_layout()
{
    if (is_admin()) {
        return;
    }
    $layouts = enlightenment_archive_layouts();
    if (is_404()) {
        $layout = $layouts['error404'];
    } elseif (is_search()) {
        $layout = $layouts['search'];
    } elseif (is_home()) {
        $layout = $layouts['blog'];
    } elseif (is_author()) {
        $layout = $layouts['author'];
    } elseif (is_date()) {
        $layout = $layouts['date'];
    } elseif (is_category()) {
        $layout = $layouts['category'];
    } elseif (is_tag()) {
        $layout = $layouts['post_tag'];
    } elseif (is_post_type_archive()) {
        $layout = $layouts[get_query_var('post_type') . '-archive'];
    } elseif (is_tax('post_format')) {
        $layout = $layouts['blog'];
    } elseif (is_tax()) {
        $layout = $layouts[get_queried_object()->taxonomy];
    } elseif (is_singular()) {
        if ('' != get_post_meta(get_the_ID(), '_enlightenment_custom_layout', true)) {
            $layout = get_post_meta(get_the_ID(), '_enlightenment_custom_layout', true);
        } elseif (!is_singular(array('post', 'page', 'attachment'))) {
            $layout = $layouts[get_post_type()];
        } elseif (is_single()) {
            $layout = $layouts['post'];
        } elseif (is_page()) {
            $layout = $layouts['page'];
        }
    }
    return apply_filters('enlightenment_current_layout', $layout);
}
function enlightenment_validate_layout_options($input)
{
    $template = $input['select_template'];
    $templates = enlightenment_layout_templates();
    if (!array_key_exists($template, $templates)) {
        unset($input['layouts'][$template]);
    }
    unset($input['select_template']);
    if ('default' == $template) {
        $layout = $input['layouts'][$template];
        if (!array_key_exists($layout, enlightenment_custom_layouts())) {
            $input['layouts'] = enlightenment_archive_layouts();
            return $input;
        }
        $templates = array_keys($templates);
        foreach ($templates as $template) {
            $input['layouts'][$template] = $layout;
        }
        unset($input['layouts']['default']);
        return $input;
    }
    $layouts = enlightenment_archive_layouts();
    foreach ($input['layouts'] as $template => $layout) {
        if (!array_key_exists($template, enlightenment_layout_templates())) {
            unset($input['layouts'][$template]);
        }
        if (!array_key_exists($layout, enlightenment_custom_layouts())) {
            $input['layouts'][$template] = $layouts[$template];
        }
    }
    $input['layouts'] = array_merge($layouts, $input['layouts']);
    return $input;
}