function enlightenment_build_google_fonts_list() { $fonts = $_POST['data']['items']; $local = enlightenment_web_fonts(); $output = ''; foreach ($fonts as $font) { if (array_key_exists($font['family'], $local)) { continue; } if (current_theme_supports('enlightenment-web-fonts', 'filter_by_subsets')) { $continue = false; foreach (current_theme_supports('enlightenment-web-fonts', 'subsets') as $subset) { if (!in_array($subset, $font['subsets'])) { $continue = true; } } if ($continue) { continue; } } $output .= enlightenment_checkbox(array('name' => current_theme_supports('enlightenment-theme-settings', 'option_name') . '[web_fonts][' . $font['family'] . '][family]', 'value' => $font['family'], 'checked' => false, 'label' => $font['family']), false); $output .= enlightenment_hidden_input(array('name' => current_theme_supports('enlightenment-theme-settings', 'option_name') . '[web_fonts][' . $font['family'] . '][category]', 'value' => $font['category']), false); $output .= enlightenment_hidden_input(array('name' => current_theme_supports('enlightenment-theme-settings', 'option_name') . '[web_fonts][' . $font['family'] . '][variants]', 'value' => join(',', $font['variants'])), false); $output .= enlightenment_hidden_input(array('name' => current_theme_supports('enlightenment-theme-settings', 'option_name') . '[web_fonts][' . $font['family'] . '][subsets]', 'value' => join(',', $font['subsets'])), false); $output .= '<br />'; } echo apply_filters('enlightenment_build_google_fonts_list', $output); die; }
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_color_picker($args, $echo = true) { $defaults = array('transparent' => false, 'alpha' => false, 'class' => '', 'id' => '', 'description' => ''); $args = wp_parse_args($args, $defaults); if (!isset($args['name']) || empty($args['name'])) { _doing_it_wrong(__FUNCTION__, __('Please specify a name attribute for your color picker.', 'enlightenment'), ''); return; } $description = $args['description']; unset($args['description']); $picker_args = $args; if ($args['transparent'] || $args['alpha']) { $picker_args['name'] .= '[hex]'; $picker_args['value'] = $args['value']['hex']; } $picker_args['class'] .= ' wp-color-picker'; wp_enqueue_style('wp-color-picker'); wp_enqueue_script('wp-color-picker'); $output = enlightenment_text_input($picker_args, false); if ($args['transparent'] || $args['alpha']) { if ($args['alpha']) { wp_enqueue_script('jquery-ui-slider'); $alpha_args = $args; $alpha_args['name'] .= '[alpha]'; $alpha_args['value'] = $args['value']['alpha']; $alpha_args['size'] = 3; $alpha_args['readonly'] = true; $output .= ' <br />'; $output .= enlightenment_open_tag('div', 'enlightenment-opacity-slider'); $output .= enlightenment_open_tag('div', 'enlightenment-jquery-ui-slider'); $output .= enlightenment_close_tag('div'); $output .= __('Opacity:', 'enlightenment'); $output .= ' '; $output .= enlightenment_text_input($alpha_args, false); $output .= enlightenment_close_tag('div'); $args['name'] = str_replace('[alpha]', '', $args['name']); } if ($args['transparent']) { $transparent_args = $args; $transparent_args['name'] .= '[transparent]'; $transparent_args['checked'] = $transparent_args['value']['transparent']; $transparent_args['label'] = __('Transparent', 'enlightenment'); $transparent_args['value'] = 1; $output .= ' <br />'; $output .= enlightenment_checkbox($transparent_args, false); } $output .= '<br />'; } $output .= empty($description) ? '' : '<p class="description">' . strip_tags($description, '<a><abbr><img>') . '</p>'; $output = apply_filters('enlightenment_color_picker', $output, $args); if (!$echo) { return $output; } echo $output; }
function enlightenment_checkboxes($args, $echo = true) { $defaults = array('class' => '', 'boxes' => array(), 'description' => ''); $args = wp_parse_args($args, $defaults); $output = '<fieldset>'; foreach ($args['boxes'] as $checkbox) { $checkbox = wp_parse_args($checkbox, $args); unset($checkbox['description']); $output .= enlightenment_checkbox($checkbox, false); $values = array_values($args['boxes']); if ($checkbox != end($values)) { $output .= '<br />'; } } $output .= '</fieldset>'; $output .= empty($args['description']) ? '' : '<p class="description">' . strip_tags($args['description'], '<a><abbr><img>') . '</p>'; $output = apply_filters('enlightenment_checkboxes', $output, $args); if (!$echo) { return $output; } echo $output; }
function enlightenment_unlimited_sidebars_form($post) { if (!isset($_GET['post'])) { _e('Please save this post as Draft to use Unlimited Sidebars.', 'enlightenment'); return; } wp_nonce_field('enlightenment_unlimited_sidebars_form', 'enlightenment_unlimited_sidebars_form_nonce'); echo '<p>'; enlightenment_checkbox(array('name' => 'enlightenment_default_sidebar_locations', 'checked' => '' == get_post_meta($post->ID, '_enlightenment_sidebar_locations', true), 'label' => sprintf(__('Use default sidebar locations for %1$s', 'enlightenment'), $post->post_type))); echo '</p>'; echo enlightenment_open_tag('div', 'sidebar-locations'); $sidebar_locations = enlightenment_sidebar_locations(); $post_type = get_post_type($_GET['post']); $post_meta = get_post_meta($post->ID, '_enlightenment_sidebar_locations', true); $locations = $sidebar_locations[$post_type]; foreach ($locations as $location => $sidebar) { if (isset($post_meta[$location])) { $sidebar['sidebar'] = $post_meta[$location]; } $args = array('name' => 'enlightenment_sidebar_locations[' . $location . ']', 'value' => $sidebar['sidebar'], 'description' => ''); echo enlightenment_open_tag('div', 'sidebar-location'); echo enlightenment_open_tag('h3'); echo $sidebar['name']; echo enlightenment_close_tag('h3'); enlightenment_edit_sidebar_location($args); echo enlightenment_close_tag(); } echo enlightenment_close_tag(); }
/** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. */ public function form($instance) { $defaults = array('title' => '', 'tagline' => '', 'type' => 'list', 'grid' => 'onecol', 'query' => 'sticky_posts', 'post_type' => 'post', 'p' => null, 'page_id' => null, 'pages' => array(), 'images' => array(), 'author' => null, 'taxonomy' => 'category', 'term' => null, 'posts_per_page' => 5, 'leading_posts' => 1, 'link_to_archive' => false, 'link_to_archive_label' => __('See all posts →', 'enlightenment')); $instance = wp_parse_args($instance, $defaults); echo enlightenment_open_tag('p'); enlightenment_text_input(array('label' => __('Title:', 'enlightenment'), 'name' => $this->get_field_name('title'), 'class' => 'widefat', 'id' => $this->get_field_id('title'), 'value' => $instance['title'])); echo enlightenment_close_tag('p'); echo enlightenment_open_tag('p'); enlightenment_textarea(array('label' => __('Tagline:', 'enlightenment'), 'name' => $this->get_field_name('tagline'), 'class' => 'widefat', 'id' => $this->get_field_id('tagline'), 'value' => $instance['tagline'])); echo enlightenment_close_tag('p'); echo enlightenment_open_tag('p', 'type'); $options = array('list' => __('List', 'enlightenment'), 'gallery' => __('Gallery', 'enlightenment'), 'slider' => __('Slider', 'enlightenment'), 'carousel' => __('Carousel', 'enlightenment')); enlightenment_select_box(array('label' => __('Type:', 'enlightenment'), 'name' => $this->get_field_name('type'), 'class' => 'widefat', 'id' => $this->get_field_id('type'), 'options' => $options, 'value' => $instance['type'])); echo enlightenment_close_tag('p'); if (current_theme_supports('enlightenment-grid-loop')) { echo enlightenment_open_tag('p', 'grid'); $options = array(); foreach (enlightenment_grid_columns() as $grid => $atts) { $options[$grid] = $atts['name']; } enlightenment_select_box(array('label' => __('Grid:', 'enlightenment'), 'name' => $this->get_field_name('grid'), 'class' => 'widefat', 'id' => $this->get_field_id('grid'), 'options' => $options, 'value' => $instance['grid'])); echo enlightenment_close_tag('p'); } echo enlightenment_open_tag('p', 'query'); $queries = enlightenment_custom_queries(); $options = array(); foreach ($queries as $query => $atts) { $options[$query] = $atts['name']; } enlightenment_select_box(array('label' => __('Query:', 'enlightenment'), 'name' => $this->get_field_name('query'), 'class' => 'widefat', 'id' => $this->get_field_id('query'), 'options' => $options, 'value' => $instance['query'])); echo enlightenment_close_tag('p'); echo enlightenment_open_tag('p', 'post-types' . ('post_type_archive' == $instance['query'] || 'post_type' == $instance['query'] ? ' show' : '')); $options = array(); $post_types = enlightenment_custom_post_types(); foreach ($post_types as $post_type => $atts) { $options[$post_type] = $atts['name']; } enlightenment_select_box(array('label' => __('Post Type:', 'enlightenment'), 'name' => $this->get_field_name('post_type'), 'class' => 'widefat', 'id' => $this->get_field_id('post_type'), 'options' => $options, 'value' => $instance['post_type'])); echo enlightenment_close_tag('p'); echo enlightenment_open_tag('p', 'post-type' . ('post_type' == $instance['query'] ? ' show' : '')); $posts = get_posts(array('post_type' => esc_attr($instance['post_type']), 'posts_per_page' => -1)); $options = array(); foreach ($posts as $post) { $options[$post->ID] = get_the_title($post->ID); } enlightenment_select_box(array('label' => __('Post:', 'enlightenment'), 'name' => $this->get_field_name('p'), 'class' => 'widefat', 'id' => $this->get_field_id('p'), 'options' => $options, 'value' => $instance['p'])); echo enlightenment_close_tag('p'); echo enlightenment_open_tag('p', 'page' . ('page' == $instance['query'] ? ' show' : '')); $posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'page')); $options = array(); foreach ($posts as $post) { $options[$post->ID] = get_the_title($post->ID); } enlightenment_select_box(array('label' => __('Page:', 'enlightenment'), 'name' => $this->get_field_name('page_id'), 'class' => 'widefat', 'id' => $this->get_field_id('page_id'), 'options' => $options, 'value' => $instance['page_id'])); echo enlightenment_close_tag('p'); echo enlightenment_open_tag('div', 'pages' . ('pages' == $instance['query'] ? ' show' : '')); $posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'page')); $boxes = array(); $i = 0; foreach ($posts as $post) { $boxes[$i] = array(); $boxes[$i]['label'] = get_the_title($post->ID); $boxes[$i]['name'] = $this->get_field_name('pages') . '[' . $post->ID . ']'; $boxes[$i]['checked'] = in_array($post->ID, $instance['pages']); $i++; } echo '<label>' . __('Select Pages:', 'enlightenment') . '</label><br />'; echo enlightenment_open_tag('div', 'pages-inner'); enlightenment_checkboxes(array('boxes' => $boxes, 'value' => $instance['p'])); echo enlightenment_close_tag('div'); echo enlightenment_close_tag('div'); echo enlightenment_open_tag('p', 'image-gallery' . ('gallery' == $instance['query'] ? ' show' : '')); enlightenment_upload_media(array('name' => $this->get_field_name('images'), 'upload_button_text' => __('Choose Images', 'enlightenment'), 'uploader_title' => __('Insert Images', 'enlightenment'), 'uploader_button_text' => __('Select', 'enlightenment'), 'remove_button_text' => '', 'mime_type' => 'image', 'multiple' => true, 'thumbnail' => null, 'value' => implode(',', $instance['images']))); echo enlightenment_close_tag('p'); echo enlightenment_open_tag('p', 'author' . ('author' == $instance['query'] ? ' show' : '')); $authors = get_users(array('who' => 'authors')); $options = array(); foreach ($authors as $author) { $options[$author->ID] = $author->display_name; } enlightenment_select_box(array('label' => __('Select Author:', 'enlightenment'), 'name' => $this->get_field_name('author'), 'class' => 'widefat', 'id' => $this->get_field_id('author'), 'options' => $options, 'value' => $instance['author'])); echo enlightenment_close_tag('p'); echo enlightenment_open_tag('p', 'taxonomy' . ('taxonomy' == $instance['query'] ? ' show' : '')); $taxonomies = get_taxonomies(array('public' => true), 'objects'); $options = array(); foreach ($taxonomies as $name => $taxonomy) { if ('post_format' == $name) { $taxonomy->labels->singular_name = __('Post Format', 'enlightenment'); } $options[$name] = $taxonomy->labels->singular_name; } enlightenment_select_box(array('label' => __('Taxonomy:', 'enlightenment'), 'name' => $this->get_field_name('taxonomy'), 'class' => 'widefat', 'id' => $this->get_field_id('taxonomy'), 'options' => $options, 'value' => $instance['taxonomy'])); echo enlightenment_close_tag('p'); echo enlightenment_open_tag('p', 'term' . ('taxonomy' == $instance['query'] ? ' show' : '')); $terms = get_terms($instance['taxonomy']); $options = array(); foreach ($terms as $term) { $options[$term->slug] = $term->name; } enlightenment_select_box(array('label' => __('Term:', 'enlightenment'), 'name' => $this->get_field_name('term'), 'class' => 'widefat', 'id' => $this->get_field_id('term'), 'options' => $options, 'value' => $instance['term'])); echo enlightenment_close_tag('p'); echo enlightenment_open_tag('p', 'posts-count' . ('post_type_archive' == $instance['query'] || 'author' == $instance['query'] || 'taxonomy' == $instance['query'] ? ' show' : '')); enlightenment_text_input(array('label' => __('Total number of entries:', 'enlightenment'), 'name' => $this->get_field_name('posts_per_page'), 'id' => $this->get_field_id('posts_per_page'), 'value' => $instance['posts_per_page'], 'size' => 3)); echo enlightenment_close_tag('p'); echo enlightenment_open_tag('p', 'lead-posts' . ('slider' != $instance['type'] && 'carousel' != $instance['type'] && ('sticky_posts' == $instance['query'] || 'post_type_archive' == $instance['query'] || 'pages' == $instance['query'] || 'gallery' == $instance['query'] || 'author' == $instance['query'] || 'taxonomy' == $instance['query']) ? ' show' : '')); enlightenment_text_input(array('label' => __('Number of leading entries:', 'enlightenment'), 'name' => $this->get_field_name('leading_posts'), 'id' => $this->get_field_id('leading_posts'), 'value' => $instance['leading_posts'], 'size' => 3)); echo enlightenment_close_tag('p'); echo enlightenment_open_tag('p', 'archive-link' . ('post_type_archive' == $instance['query'] || 'author' == $instance['query'] || 'taxonomy' == $instance['query'] ? ' show' : '')); enlightenment_checkbox(array('label' => __('Show Link to Archive', 'enlightenment'), 'name' => $this->get_field_name('link_to_archive'), 'id' => $this->get_field_id('link_to_archive'), 'checked' => $instance['link_to_archive'])); echo enlightenment_close_tag('p'); echo enlightenment_open_tag('p', 'archive-link-label' . (('post_type_archive' == $instance['query'] || 'author' == $instance['query'] || 'taxonomy' == $instance['query']) && $instance['link_to_archive'] ? ' show' : '')); enlightenment_text_input(array('label' => __('Link to Archive Label:', 'enlightenment'), 'name' => $this->get_field_name('link_to_archive_label'), 'class' => 'widefat', 'id' => $this->get_field_id('link_to_archive_label'), 'value' => $instance['link_to_archive_label'])); echo enlightenment_close_tag('p'); ?> <script> jQuery(document).ready(function($) { $('.type select').change(function() { var container = $(this).closest('.widget-content'); var val = $(this).val(); if(val == 'slider' || val == 'carousel') $('.lead-posts', container).hide(); else { var query = $('.query select', container).val(); if(query == 'post_type' || query == 'page') $('.lead-posts', container).hide(); else $('.lead-posts', container).show(); } }); $('.query select').change(function() { var container = $(this).closest('.widget-content'); var val = $(this).val(); var type = $('.type select', container).val(); if(val == 'sticky_posts') { $('.post-types', container).hide(); $('.post-type', container).hide(); $('.page', container).hide(); $('.pages', container).hide(); $('.image-gallery', container).hide(); $('.author', container).hide(); $('.taxonomy', container).hide(); $('.term', container).hide(); $('.posts-count', container).hide(); if(type != 'slider' && type != 'carousel') $('.lead-posts', container).show(); $('.archive-link', container).hide(); $('.archive-link-label', container).hide(); } else if(val == 'post_type_archive') { $('.post-types', container).show(); $('.post-type', container).hide(); $('.page', container).hide(); $('.pages', container).hide(); $('.image-gallery', container).hide(); $('.author', container).hide(); $('.taxonomy', container).hide(); $('.term', container).hide(); $('.posts-count', container).show(); if(type != 'slider' && type != 'carousel') $('.lead-posts', container).show(); $('.archive-link', container).show(); if($('.archive-link', container).is(':checked')) $('.archive-link-label', container).show(); } else if(val == 'post_type') { $('.post-types', container).show(); $('.post-type', container).show(); $('.page', container).hide(); $('.pages', container).hide(); $('.image-gallery', container).hide(); $('.author', container).hide(); $('.taxonomy', container).hide(); $('.term', container).hide(); $('.posts-count', container).hide(); $('.lead-posts', container).hide(); $('.archive-link', container).hide(); $('.archive-link-label', container).hide(); } else if(val == 'page') { $('.post-types', container).hide(); $('.post-type', container).hide(); $('.page', container).show(); $('.pages', container).hide(); $('.image-gallery', container).hide(); $('.author', container).hide(); $('.taxonomy', container).hide(); $('.term', container).hide(); $('.posts-count', container).hide(); $('.lead-posts', container).hide(); $('.archive-link', container).hide(); $('.archive-link-label', container).hide(); } else if(val == 'pages') { $('.post-types', container).hide(); $('.post-type', container).hide(); $('.page', container).hide(); $('.pages', container).show(); $('.image-gallery', container).hide(); $('.author', container).hide(); $('.taxonomy', container).hide(); $('.term', container).hide(); $('.posts-count', container).hide(); if(type != 'slider' && type != 'carousel') $('.lead-posts', container).show(); $('.archive-link', container).hide(); $('.archive-link-label', container).hide(); } else if(val == 'gallery') { $('.post-types', container).hide(); $('.post-type', container).hide(); $('.page', container).hide(); $('.pages', container).hide(); $('.image-gallery', container).show(); $('.author', container).hide(); $('.taxonomy', container).hide(); $('.term', container).hide(); $('.posts-count', container).hide(); if(type != 'slider' && type != 'carousel') $('.lead-posts', container).show(); $('.archive-link', container).hide(); $('.archive-link-label', container).hide(); } else if(val == 'author') { $('.post-types', container).hide(); $('.post-type', container).hide(); $('.page', container).hide(); $('.pages', container).hide(); $('.image-gallery', container).hide(); $('.author', container).show(); $('.taxonomy', container).hide(); $('.term', container).hide(); $('.posts-count', container).show(); if(type != 'slider' && type != 'carousel') $('.lead-posts', container).show(); $('.archive-link', container).show(); if($('.archive-link', container).is(':checked')) $('.archive-link-label', container).show(); } else if(val == 'taxonomy') { $('.post-types', container).hide(); $('.post-type', container).hide(); $('.page', container).hide(); $('.pages', container).hide(); $('.image-gallery', container).hide(); $('.author', container).hide(); $('.taxonomy', container).show(); $('.term', container).show(); $('.posts-count', container).show(); if(type != 'slider' && type != 'carousel') $('.lead-posts', container).show(); $('.archive-link', container).show(); if($('.archive-link', container).is(':checked')) $('.archive-link-label', container).show(); } }); $('.post-types select').change(function() { var container = $(this).closest('.widget-content'); var data = { action: 'enlightenment_ajax_get_post_types', post_type: $('.post-types select', container).val(), name: '<?php echo $this->get_field_name('p'); ?> ', id: '<?php echo $this->get_field_id('p'); ?> ', value: '<?php echo $instance['p']; ?> ', } $.post(ajaxurl, data, function(r) { var html = document.createElement( 'div' ); $(html).html(r); $('.post-type select', container).html($('select', $(html)).html()); }); }); $('.taxonomy select').change(function() { var container = $(this).closest('.widget-content'); var data = { action: 'enlightenment_ajax_get_terms', taxonomy: $('.taxonomy select', container).val(), name: '<?php echo $this->get_field_name('term'); ?> ', id: '<?php echo $this->get_field_id('term'); ?> ', value: '<?php echo $instance['term']; ?> ', } $.post(ajaxurl, data, function(r) { var html = document.createElement( 'div' ); $(html).html(r); $('.term', container).remove(); $('.taxonomy', container).after($(html).html()); }); }); $('.archive-link input').each(function() { var container = $(this).closest('.widget-content'); var query = $('.query select', container).val(); if( query == 'post_type_archive' || query == 'author' || query == 'taxonomy' ) { if($(this).is(':checked')) $('.archive-link-label', container).show(); else $('.archive-link-label', container).hide(); } }); $('.archive-link input').change(function() { var container = $(this).closest('.widget-content'); if($(this).is(':checked')) $('.archive-link-label', container).show(); else $('.archive-link-label', container).hide(); }); }); </script> <?php }