コード例 #1
0
function enlightenment_dynamic_sidebar_grid($args, $echo = true)
{
    $defaults = array('class' => '', 'id' => '', 'value' => '', 'description' => '');
    $args = wp_parse_args($args, $defaults);
    $args = apply_filters('enlightenment_dynamic_sidebar_grid_args', $args);
    $args['multiple'] = false;
    $args['options'] = array();
    $grids = enlightenment_grid_columns();
    foreach ($grids as $grid => $atts) {
        $args['options'][$grid] = $atts['name'];
    }
    if (!empty($args['options'])) {
        $name = $args['name'];
        $args['name'] = str_replace('[name]', '[grid]', $args['name']);
        $output = enlightenment_select_box($args, false);
        $args['name'] = $name;
    }
    $output .= empty($args['description']) ? '' : '<p class="description">' . strip_tags($args['description'], '<a><abbr><img>') . '</p>';
    $output = apply_filters('enlightenment_dynamic_sidebar_grid', $output, $args);
    if (!$echo) {
        return $output;
    }
    echo $output;
}
コード例 #2
0
function enlightenment_validate_grid_loop_options($input)
{
    $template = $input['select_template'];
    $templates = enlightenment_grid_loop_templates();
    if (!array_key_exists($template, $templates)) {
        unset($input['grids'][$template]);
    }
    unset($input['select_template']);
    if ('default' == $template) {
        $grid = $input['grids'][$template]['grid'];
        if (!array_key_exists($grid, enlightenment_grid_columns())) {
            $input['grids'] = enlightenment_archive_grids();
            return $input;
        }
        $lead_posts = intval($input['grids'][$template]['lead_posts']);
        if (0 > $lead_posts || get_option('posts_per_page') < $lead_posts) {
            $input['grids'] = enlightenment_archive_grids();
            return $input;
        }
        $templates = array_keys($templates);
        foreach ($templates as $template) {
            $input['grids'][$template]['grid'] = $grid;
            $input['lead_posts'][$template]['lead_posts'] = $grid;
        }
        unset($input['grids']['default']);
        return $input;
    }
    $grids = enlightenment_archive_grids();
    foreach ($input['grids'] as $template => $grid) {
        if (!array_key_exists($template, enlightenment_grid_loop_templates())) {
            unset($input['grids'][$template]);
        }
        if (!array_key_exists($grid['grid'], enlightenment_grid_columns())) {
            $input['grids'][$template]['grid'] = $grids[$template]['grid'];
        }
        if (0 > $grid['lead_posts'] || get_option('posts_per_page') < $grid['lead_posts']) {
            $input['grids'][$template]['lead_posts'] = $grids[$template]['lead_posts'];
        }
    }
    $input['grids'] = array_merge($grids, $input['grids']);
    return $input;
}
コード例 #3
0
 /**
  * Sanitize widget form values as they are saved.
  *
  * @see WP_Widget::update()
  *
  * @param array $new_instance Values just sent to be saved.
  * @param array $old_instance Previously saved values from database.
  *
  * @return array Updated safe values to be saved.
  */
 public function update($new_instance, $old_instance)
 {
     $instance = array();
     $instance['title'] = !empty($new_instance['title']) ? strip_tags($new_instance['title']) : '';
     $instance['tagline'] = !empty($new_instance['tagline']) ? strip_tags($new_instance['tagline'], '<p><a><img>') : '';
     $types = array('list', 'gallery', 'slider', 'carousel');
     $instance['type'] = in_array($new_instance['type'], $types) ? $new_instance['type'] : $old_instance['type'];
     if (current_theme_supports('enlightenment-grid-loop')) {
         $instance['grid'] = array_key_exists($new_instance['grid'], enlightenment_grid_columns()) ? $new_instance['grid'] : $old_instance['grid'];
     }
     $options[$grid] = $atts['name'];
     $queries = array('sticky_posts', 'post_type_archive', 'post_type', 'page', 'pages', 'gallery', 'author', 'taxonomy');
     $instance['query'] = in_array($new_instance['query'], $queries) ? $new_instance['query'] : $old_instance['query'];
     $post_types = enlightenment_custom_post_types();
     $instance['post_type'] = array_key_exists($new_instance['post_type'], $post_types) ? $new_instance['post_type'] : $old_instance['post_type'];
     $post = get_post($new_instance['p']);
     $instance['p'] = $post->post_type == $instance['post_type'] ? $new_instance['p'] : $old_instance['p'];
     $page = get_post($new_instance['page_id']);
     $instance['page_id'] = 'page' == $page->post_type ? $new_instance['page_id'] : $old_instance['page_id'];
     if (empty($new_instance['pages'])) {
         $instance['pages'] = array();
     } else {
         $post__in = array();
         foreach ($new_instance['pages'] as $post_id => $bool) {
             $post__in[] = $post_id;
         }
         $posts = get_posts(array('post__in' => $post__in, 'post_type' => 'page', 'posts_per_page' => -1));
         $instance['pages'] = array();
         foreach ($posts as $post) {
             $instance['pages'][] = $post->ID;
         }
     }
     if (empty($new_instance['images'])) {
         $instance['images'] = array();
     } else {
         $post__in = explode(',', $new_instance['images']);
         $posts = get_posts(array('post__in' => $post__in, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'posts_per_page' => -1, 'post_status' => 'inherit'));
         foreach ($posts as $post) {
             $instance['images'][] = $post->ID;
         }
     }
     $authors = get_users(array('who' => 'authors'));
     $valid = false;
     foreach ($authors as $author) {
         if ($author->ID == $new_instance['author']) {
             $valid = true;
         }
     }
     $instance['author'] = $valid ? $new_instance['author'] : $old_instance['author'];
     $instance['taxonomy'] = taxonomy_exists($new_instance['taxonomy']) ? $new_instance['taxonomy'] : $old_instance['taxonomy'];
     $instance['term'] = term_exists($new_instance['term'], $instance['taxonomy']) ? $new_instance['term'] : $old_instance['term'];
     $instance['posts_per_page'] = !empty($new_instance['posts_per_page']) ? intval($new_instance['posts_per_page']) : $old_instance['posts_per_page'];
     $instance['leading_posts'] = !empty($new_instance['leading_posts']) ? intval($new_instance['leading_posts']) : $old_instance['leading_posts'];
     $instance['link_to_archive'] = isset($new_instance['link_to_archive']);
     $instance['link_to_archive_label'] = !empty($new_instance['link_to_archive_label']) ? strip_tags($new_instance['link_to_archive_label']) : '';
     return $instance;
 }
コード例 #4
0
function enlightenment_get_grid($grid)
{
    $grids = enlightenment_grid_columns();
    if (isset($grids[$grid])) {
        return $grids[$grid];
    }
    return false;
}