Plugin Directory

Changeset 505769


Ignore:
Timestamp:
02/16/2012 05:20:41 AM (14 years ago)
Author:
technical_mastermind
Message:

Updating trunk to dev version 1.2

Location:
latest-custom-post-type-updates/trunk
Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • latest-custom-post-type-updates/trunk/index.php

    r500264 r505769  
    33 * Plugin Name: Latest Custom Post Type Updates
    44 * Plugin URI: http://technicalmastermind.com/wordpress-plugins/latest-custom-post-type-updates/
    5  * Description: This simple plugin adds a widget that allows for the display of recent posts in any custom post type. It functions almost identically to the built-in WordPress "Recent Posts" widget with the added option of letting you choose which post type it pulls from. Just add the "Latest Custom Post Type" widget to a widget area, give it a title, how many posts to show and what post type you want it to pull from. It's that easy!
    6  * Version: 1.1
     5 * Description: This simple plugin adds a widget that allows for the display of recent posts in any custom post type. It functions almost identically to the built-in WordPress "Recent Posts" widget with the added option of letting you choose which post type it pulls from. Just add the "Latest Custom Post Type" widget to a widget area, give it a title, how many posts to show and what post type you want it to pull from. It's that easy! The option is also there to allow for filtering the results based on taxonomy tags/categories. This allows you to limit to only posts that are in, not in, or in all of the selected taxonomy tags/categories (thanks to adamlaz for requesting this feature). To keep it simple this option does not display by default making the widget options easy on the eyes unless you need the power, and then it tries to stay as short and simple as possible. As always there is no added admin panel to configure options, it's all configured from the individual widget settings.
     6 * Version: 1.2
    77 * Author: David Wood
    8  * Author URI: http://iamdavidwood.com/
     8 * Author URI: http://technicalmastermind.com/about-david-wood/
    99 * License: GPL2
    1010 */
     
    3535        else $instance['numberposts'] = 5;
    3636        $instance['post_type'] = strip_tags($new_instance['post_type']);
     37        $instance['show_advanced'] = $new_instance['show_advanced'];
     38        $instance['taxonomies'] = $new_instance['taxonomies'];
     39        if($new_instance['tax_in'] != 'in' && $new_instance['tax_in'] != 'not_in' && $new_instance['tax_in'] != 'and')
     40            $instance['tax_in'] = 'in';
     41        else
     42            $instance['tax_in'] = $new_instance['tax_in'];
     43        if(is_array($new_instance['tag_list']) && count($new_instance['tag_list']) > 0) {
     44            $instance['tag_list'] = $new_instance['tag_list'];
     45        } else {
     46            $tmp = explode(';', $new_instance['tag_list']);
     47            $tags = array();
     48            foreach($tmp as $tag) {
     49                $t = addslashes(strip_tags(trim($tag)));
     50                if(!empty($t)) $tags[] = $t;
     51            }
     52            $instance['tag_list'] = $tags;
     53        }
    3754
    3855        return $instance;
     
    5471            'post_type' => $instance['post_type'],
    5572        );
     73        // Check if we are filtering based on taxonomy tags/categories
     74        if(($instance['show_advanced'] == 'yes')
     75            && ($instance['taxonomies'] != '--')
     76            && is_array($instance['tag_list'])
     77            && (count($instance['tag_list']) > 0)
     78        ) {
     79            // We are filtering, add the filter to the query
     80            $params['tax_query'] = array(
     81                array(
     82                    'taxonomy' => $instance['taxonomies'],
     83                    'field' => 'id',
     84                    'terms' => $instance['tag_list'],
     85                    'operator' => strtoupper(str_replace('_', ' ', $instance['tax_in']))
     86                )
     87            );
     88            if(is_numeric($instance['tag_list'][0])) $params['tax_query'][0]['field'] = 'id';
     89            else $params['tax_query'][0]['field'] = 'slug';
     90        }
     91        // Get the posts!
    5692        $posts = get_posts($params);
    5793        // Print 'em out!
     
    5995            foreach($posts as $post)
    6096                echo '<li><a href="'.get_permalink($post->ID).'" title="'.$post->post_title.'">'.$post->post_title.'</a></li>';
    61         // Finish widget display
     97        // Always remember your closing tags!
    6298        echo '</ul>'.$after_widget;
     99    }
     100
     101    static function get_post_taxonomies($post_type = 'post', $current = '') {
     102        ob_start();
     103        $taxonomies = get_object_taxonomies($post_type, 'objects');
     104        echo '<option value="--">--</option>';
     105        if($taxonomies) {
     106            foreach($taxonomies as $taxonomy) {
     107                if($taxonomy->show_ui != 1) continue;
     108                echo '<option value="'.$taxonomy->name.'"';
     109                if($current == $taxonomy->name) echo ' selected="selected"';
     110                echo '>'.$taxonomy->labels->name.'</option>';
     111            }
     112        }
     113        return ob_get_clean();
     114    }
     115
     116    static function get_taxonomy_list($taxonomy, $checkbox_name, $tag_list = array()) {
     117        if(!is_array($tag_list)) $tag_list = array();
     118        $this_tax = get_taxonomy($taxonomy);
     119        if($this_tax->hierarchical == 1) {
     120            // Treat as categories
     121            ob_start();
     122            self::taxonomy_levels($taxonomy, $tag_list, $checkbox_name);
     123            return ob_get_clean();
     124        } else {
     125            // Treat as tags
     126            ob_start();
     127            echo '(Semi-colon(;) seperated list)';
     128            echo '<textarea rows="8" cols="30" name="'.$checkbox_name.'">';
     129            if(count($tag_list) > 0) echo implode('; ', $tag_list);
     130            echo '</textarea>';
     131            return ob_get_clean();
     132        }
     133    }
     134
     135    static function taxonomy_levels($taxonomy, $tag_list, $checkbox_name, $level = 0, $parent_id = 0) {
     136        $per_level = '&nbsp;&nbsp;';
     137        $checked = ' checked="checked"';
     138        $terms = get_terms($taxonomy, array('hide_empty' => false, 'parent' => $parent_id));
     139        if($terms) {
     140            foreach($terms as $term) {
     141                echo str_repeat($per_level, $level);
     142                echo '<input type="checkbox" name="'.$checkbox_name.'[]" value="'.$term->term_id.'"';
     143                if(in_array($term->term_id, $tag_list)) echo $checked;
     144                echo ' /> '.$term->name.'<br/>';
     145                self::taxonomy_levels($taxonomy, $tag_list, $checkbox_name, $level+1, $term->term_id);
     146            }
     147        }
    63148    }
    64149}
    65150// register widget
    66151add_action('widgets_init', create_function('', 'return register_widget("tm_latest_cp_widget");'));
     152add_action('wp_ajax_tm_lcptu_get_taxonomies', array('tm_latest_cp_widget', 'get_post_taxonomies'));
    67153endif;
     154
     155if(!function_exists('tm_lcptu_enqueue')):
     156    add_action('admin_enqueue_scripts', 'tm_lcptu_enqueue');
     157    function tm_lcptu_enqueue($hook) {
     158        if('widgets.php' != $hook) return;
     159        global $wp_version;
     160        if(preg_match('/^3\.[3-9]/', $wp_version)) // Add script for WP 3.3 and newer (jQuery 1.7+)
     161            wp_enqueue_script('tm-lcptu-advanced', plugins_url('/js/tm-lcptu-options-1.7.js', __FILE__), array('jquery'));
     162        else // Add script for older versions of WP
     163            wp_enqueue_script('tm-lcptu-advanced', plugins_url('/js/tm-lcptu-options-1.6.js', __FILE__), array('jquery'));
     164    }
     165endif;
     166
     167// Wrappers for AJAX calls
     168if(!function_exists('ajax_tm_lcptu_tax')):
     169    add_action('wp_ajax_tm_lcptu_tax', 'ajax_tm_lcptu_tax');
     170    function ajax_tm_lcptu_tax() {
     171        global $wpdb;
     172        if(isset($_POST['posttype'])) $post_type = $_POST['posttype'];
     173        else $post_type = 'post';
     174        echo tm_latest_cp_widget::get_post_taxonomies($post_type);
     175        die();
     176    }
     177endif;
     178
     179if(!function_exists('ajax_tm_lcptu_tags')):
     180    add_action('wp_ajax_tm_lcptu_tags', 'ajax_tm_lcptu_tags');
     181    function ajax_tm_lcptu_tags() {
     182        global $wpdb;
     183        if(isset($_POST['taxonomy'])) $taxonomy = $_POST['taxonomy'];
     184        else $taxonomy = 'post_tag';
     185        echo tm_latest_cp_widget::get_taxonomy_list($taxonomy, $_POST['checkboxName']);
     186        die();
     187    }
     188endif;
  • latest-custom-post-type-updates/trunk/options.php

    r499235 r505769  
    77        'numberposts' => 5,
    88        'post_type' => 'post',
     9        'show_advanced' => 'no',
     10        'taxonomies' => '--'
    911    )
    1012);
     
    3234<p> <!-- POST TYPE FOR WIDGET -->
    3335    <label  for="<?php echo $this->get_field_id('post_type'); ?>"><?php _e('Post Type:'); ?></label>
    34     <select name="<?php echo $this->get_field_name('post_type'); ?>" id="<?php echo $this->get_field_id('post_type'); ?>">
     36    <select name="<?php echo $this->get_field_name('post_type'); ?>" id="<?php echo $this->get_field_id('post_type'); ?>" class="tm_lcptu_post-type">
    3537        <?php
    3638        // Filter out post types that are internal such as attachments or internal theme post types used for options.
     
    4749    </select>
    4850</p>
     51
     52<p> <!-- SHOW ADVANCED FILTERING OPTIONS? -->
     53    <label  for="<?php echo $this->get_field_id('show_advanced'); ?>"><?php _e('Show advanced options:'); ?></label>
     54    <input  id="<?php echo $this->get_field_id('show_advanced'); ?>"
     55            name="<?php echo $this->get_field_name('show_advanced'); ?>"
     56            class="tm_lcptu_show-advanced"
     57            type="checkbox"
     58            value="yes"
     59            size="3"
     60            <?php if($instance['show_advanced'] == 'yes') echo $checked; ?>
     61        />
     62</p>
     63
     64<div class="<?php echo $this->get_field_id('show_advanced'); ?>" style="display: <?php echo ($instance['show_advanced'] == 'yes')? 'block' : 'none'; ?>;">
     65    <p> <!-- TAXONOMIES FOR POST TYPE -->
     66        <label for="<?php echo $this->get_field_id('taxonomies'); ?>"><?php _e('Taxonomy to filter by:'); ?></label>
     67        <select
     68            name="<?php echo $this->get_field_name('taxonomies'); ?>"
     69            id="<?php echo $this->get_field_id('taxonomies'); ?>"
     70            class="<?php echo $this->get_field_id('post_type'); ?> tm_lcptu_tax">
     71            <?php
     72            echo tm_latest_cp_widget::get_post_taxonomies($instance['post_type'], $instance['taxonomies']);
     73            ?>
     74        </select>
     75    </p>
     76    <div class="<?php echo $this->get_field_id('taxonomies'); ?>-container" style="display: <?php echo ($instance['taxonomies'] != '--')? 'block' : 'none'; ?>;">
     77        <p>
     78            <label  for="<?php echo $this->get_field_id('tax_in'); ?>"><?php _e('Only show posts that are '); ?></label><select
     79            name="<?php echo $this->get_field_name('tax_in'); ?>" id="<?php echo $this->get_field_id('tax_in'); ?>">
     80            <option value="in"<?php if($instance['tax_in'] == 'in') echo $selected; ?>>in</option>
     81            <option value="not_in"<?php if($instance['tax_in'] == 'not_in') echo $selected; ?>>not in</option>
     82            <option value="and"<?php if($instance['tax_in'] == 'and') echo $selected; ?>>in all</option>
     83            </select><label for="<?php echo $this->get_field_id('tag_list'); ?>"><?php _e(' the following tags/categories:'); ?></label>
     84        </p>
     85        <div class="<?php echo $this->get_field_id('taxonomies'); ?>" id="<?php echo $this->get_field_name('tag_list'); ?>">
     86            <?php if($instance['taxonomies'] != '--') echo tm_latest_cp_widget::get_taxonomy_list($instance['taxonomies'], $this->get_field_name('tag_list'), $instance['tag_list']); ?>
     87        </div>
     88    </div>
     89</div>
  • latest-custom-post-type-updates/trunk/readme.txt

    r500265 r505769  
    33Plugin Name:       Latest Custom Post Type Updates
    44Plugin URI:        http://technicalmastermind.com/wordpress-plugins/latest-custom-post-type-updates/
    5 Tags:              widget, custom post type, latest updates, latest post, latest posts, latest custom posts
    6 Author URI:        http://iamdavidwood.com
     5Tags:              widget, custom post type, latest updates, latest post, latest posts, latest custom posts, latest, filter posts, filter, filter custom posts, filter custom post types
     6Author URI:        http://technicalmastermind.com/about-david-wood/
    77Author:            David Wood
    88Donate link:       http://technicalmastermind.com/donate/
     
    1111Stable tag:        1.1
    1212
    13 Simple display of the latest updates to your custom post type.
     13Simple widgetized display of the latest posts in your custom post type. Also allows for easy filtered display of regular posts in a widget.
    1414
    1515== Description ==
    1616= Simplicity at its finest! =
    1717This simple plugin adds a widget that allows for the display of recent posts in any custom post type. It functions almost identically to the built-in WordPress "Recent Posts" widget with the added option of letting you choose which post type it pulls from. Just add the "Latest Custom Post Type" widget to a widget area, give it a title, how many posts to show and what post type you want it to pull from. It's that easy!
     18
     19= Advanced Options =
     20The option is also there to allow for filtering the results based on taxonomy tags/categories. This allows you to limit to only posts that are in, not in, or in all of the selected taxonomy tags/categories (thanks to [adamlaz](http://wordpress.org/support/profile/adamlaz) for requesting this feature). To keep it simple this option does not display by default making the widget options easy on the eyes unless you need the power, and then it tries to stay as short and simple as possible. As always there is no added admin panel to configure options, it's all configured from the individual widget settings.
    1821
    1922= A word on support and additional features =
     
    32351. The widget configuration options
    33362. The widget displaying the latest posts in a custom post type
     373. Advanced configuration options
    3438
    3539== Upgrade Notice ==
     40= 1.2 =
     41Added ability to restrict displayed posts by taxonomy tags/categories. This allows for displaying posts that are in, not in, or in all of the selected taxonomy tags/categories.
    3642= 1.1 =
    3743Added in missing closing UL tag
     
    4046
    4147== Changelog ==
     48= 1.2 =
     49* Added ability to restrict displayed posts by taxonomy tags/categories.
     50* Allows for displaying posts that are in, not in, or in all of the selected taxonomy tags/categories.
    4251= 1.1 =
    4352* Added in missing closing UL tag
Note: See TracChangeset for help on using the changeset viewer.