function enlightenment_templates()
{
    $templates = array('error404' => array('name' => __('404', 'enlightenment'), 'conditional' => 'is_404', 'type' => 'special'), 'search' => array('name' => __('Search', 'enlightenment'), 'conditional' => 'is_search', 'type' => 'archive'), 'blog' => array('name' => __('Blog', 'enlightenment'), 'conditional' => 'is_home', 'type' => 'post_type_archive'), 'post' => array('name' => __('Post', 'enlightenment'), 'conditional' => 'is_single', 'type' => 'post_type'), 'page' => array('name' => __('Page', 'enlightenment'), 'conditional' => 'is_page', 'type' => 'post_type'), 'author' => array('name' => __('Author', 'enlightenment'), 'conditional' => 'is_author', 'type' => 'archive'), 'date' => array('name' => __('Date', 'enlightenment'), 'conditional' => 'is_date', 'type' => 'archive'), 'category' => array('name' => __('Category', 'enlightenment'), 'conditional' => 'is_category', 'type' => 'archive'), 'post_tag' => array('name' => __('Tag', 'enlightenment'), 'conditional' => 'is_tag', 'type' => 'archive'), 'comments' => array('name' => __('Comments', 'enlightenment'), 'conditional' => 'is_singular', 'hooks' => array_keys(enlightenment_comments_hooks()), 'type' => 'special'));
    $post_types = get_post_types(array('has_archive' => true), 'objects');
    foreach ($post_types as $name => $post_type) {
        $templates[$name . '-archive'] = array('name' => sprintf(__('%1$s Archive', 'enlightenment'), $post_type->labels->name), 'conditional' => array('is_post_type_archive', $name), 'type' => 'post_type_archive');
    }
    $post_types = get_post_types(array('publicly_queryable' => true), 'objects');
    foreach ($post_types as $name => $post_type) {
        $templates[$name] = array('name' => $post_type->labels->singular_name, 'conditional' => array('is_singular', $name), 'type' => 'post_type');
    }
    $taxonomies = get_taxonomies(array('public' => true), 'objects');
    unset($taxonomies['post_format']);
    unset($taxonomies['category']);
    unset($taxonomies['post_tag']);
    foreach ($taxonomies as $name => $taxonomy) {
        $templates[$name] = array('name' => $taxonomy->labels->singular_name, 'conditional' => array('is_tax', $name), 'type' => 'taxonomy');
    }
    $default_hooks = array_keys(enlightenment_template_hooks());
    foreach ($templates as $name => $template) {
        if (!isset($template['hooks']) || empty($template['hooks'])) {
            $templates[$name]['hooks'] = $default_hooks;
        }
    }
    return apply_filters('enlightenment_templates', $templates);
}
Example #2
0
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');
}