function enlightenment_post_formats_settings()
{
    add_settings_section('select_post_format', __('Select Post Format', 'enlightenment'), '__return_false', 'enlightenment_theme_options');
    add_settings_field('select_post_format', __('Select Post Format to Edit', 'enlightenment'), 'enlightenment_select_post_format', 'enlightenment_theme_options', 'select_post_format', array('name' => 'select_post_format', 'class' => 'select-post-format'));
    add_settings_section('template_hooks', __('Template Hooks', 'enlightenment'), '__return_false', 'enlightenment_theme_options');
    $template = enlightenment_get_template('blog');
    foreach (array_keys(enlightenment_entry_hooks()) as $hook) {
        $atts = enlightenment_get_template_hook($hook);
        if (!empty($atts['functions'])) {
            add_settings_field('template_hooks_' . $hook, $atts['name'], 'enlightenment_template_hook_actions', 'enlightenment_theme_options', 'template_hooks', array('hook' => $hook, 'name' => 'template_hooks[' . enlightenment_current_post_format_template() . '][' . $hook . ']', 'class' => 'template-hooks'));
        }
    }
}
function enlightenment_page_builder_form($post)
{
    if (!isset($_GET['post'])) {
        _e('Please save this post as Draft to use the Page Builder.', 'enlightenment');
        return;
    }
    wp_nonce_field('enlightenment_page_builder_form', 'enlightenment_page_builder_form_nonce');
    echo enlightenment_open_tag('p');
    enlightenment_checkbox(array('name' => 'enlightenment_default_template_hooks', 'checked' => '' == get_post_meta($post->ID, '_enlightenment_page_builder', true), 'label' => sprintf(__('Use default template hooks for %1$s', 'enlightenment'), $post->post_type)));
    echo enlightenment_close_tag('p');
    $template = enlightenment_get_template(get_post_type());
    $template['hooks'] = array_keys(enlightenment_template_hooks());
    do_action('enlightenment_before_page_builder');
    echo enlightenment_open_tag('div', 'template-hooks');
    foreach ($template['hooks'] as $hook) {
        $atts = enlightenment_get_template_hook($hook);
        $available_functions = $atts['functions'];
        $template_hooks = get_post_meta($post->ID, '_enlightenment_page_builder', true);
        if ('' == $template_hooks) {
            $template_hooks = enlightenment_theme_option('template_hooks');
        }
        if (isset($template_hooks[enlightenment_current_template()][$hook])) {
            $hooked_functions = $template_hooks[enlightenment_current_template()][$hook];
        } else {
            $hooked_functions = array();
            global $wp_filter;
            if (isset($wp_filter[$hook]) && isset($wp_filter[$hook][10])) {
                foreach ($wp_filter[$hook][10] as $function) {
                    $hooked_functions[] = $function['function'];
                }
            }
        }
        $available_functions = array_diff($available_functions, $hooked_functions);
        if (!empty($available_functions) || !empty($hooked_functions)) {
            echo '<h2>' . esc_attr($atts['name']) . '</h2>';
            enlightenment_template_hook_actions(array('hook' => $hook, 'name' => 'enlightenment_page_builder[' . $hook . ']', 'class' => 'template-hooks'));
        }
    }
    echo enlightenment_close_tag();
    do_action('enlightenment_after_page_builder');
}
function enlightenment_validate_template_editor($input)
{
    foreach ($input['template_hooks'] as $template => $hooks) {
        if ($template != $input['select_template']) {
            unset($input['template_hooks'][$template]);
        }
    }
    $template = $input['select_template'];
    unset($input['select_template']);
    $atts = enlightenment_get_template($template);
    foreach ($input['template_hooks'][$template] as $hook => $functions) {
        if (!in_array($hook, $atts['hooks'])) {
            unset($input['template_hooks'][$template][$hook]);
        }
    }
    foreach ($input['template_hooks'][$template] as $hook => $functions) {
        $functions = explode(',', $functions);
        $atts = enlightenment_get_template_hook($hook);
        foreach ($functions as $key => $function) {
            if (!in_array($function, $atts['functions'])) {
                unset($functions[$key]);
            }
        }
        $input['template_hooks'][$template][$hook] = $functions;
    }
    $option = enlightenment_theme_option('template_hooks', array());
    $input['template_hooks'] = array_merge($option, $input['template_hooks']);
    return $input;
}