WordPress.org

Plugin Directory

Changeset 553443


Ignore:
Timestamp:
06/05/12 16:05:26 (23 months ago)
Author:
eddiemoya
Message:

tagging 1.4: now works as object instead of static class - allows for multiple taxonomy metaboxes

Location:
media-categories-2
Files:
2 edited
3 copied

Legend:

Unmodified
Added
Removed
  • media-categories-2/tags/1.4/media-categories.php

    r549552 r553443  
    33Plugin URI: http://wordpress.org/extend/plugins/media-categories-2 
    44Description:  Allows users to assign categories to media with a clean and simplified, filterable category meta box and use shortcodes to display category galleries 
    5 Version: 1.3.1 
     5Version: 1.4 
    66Author: Eddie Moya 
    77Author URL: http://eddiemoya.com 
     
    1010class Media_Categories { 
    1111 
    12     /** 
    13      * Start your engines. 
    14      *  
    15      * @author Eddie Moya 
    16      */ 
    17     function init() { 
    18         add_action('init', array(__CLASS__, 'register_media_categories')); 
    19         add_action('init', array(__CLASS__, 'custom_gallery_shortcode')); 
     12    public static $instances; 
     13    public $taxonomy; 
     14     
     15    /** 
     16     * While normally run statically, this allows  
     17     * @param type $taxonomy  
     18     */ 
     19    public function __construct($taxonomy) { 
     20         
     21        // Store each instance of this class (for use when localizing scripts) 
     22        $this->taxonomy = $taxonomy; 
     23        self::$instances[] = $this; 
     24         
     25        add_action('init', array(&$this, 'register_media_categories')); 
     26        add_action('init', array(&$this, 'custom_gallery_shortcode')); 
     27        add_filter('attachment_fields_to_edit', array(&$this, 'add_media_categories_metabox'), null, 2); 
     28         
     29        /* These only need to occur once */ 
     30        add_filter('attachment_fields_to_edit', array(__CLASS__, 'get_attachment_fields_to_edit'), 11, 2); 
    2031        add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_media_categories_scripts')); 
    2132        add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_media_categories_styles') ); 
    22         add_filter('attachment_fields_to_edit', array(__CLASS__, 'add_media_categories_metabox'), null, 2); 
    23         add_filter('attachment_fields_to_edit', array(__CLASS__, 'get_attachment_fields_to_edit'), 11, 2); 
    24          
    25     } 
    26  
     33         
     34         
     35 
     36    } 
     37 
     38    /** 
     39     * Enqueue javascript 
     40     */ 
    2741    function enqueue_media_categories_scripts() { 
    2842        if (is_admin()) { 
    29  
    30             $tax_name = array('name' => apply_filters('mc_taxonomy', 'category')); 
    31              
     43             
     44            // Get each instance of this class, and pass each taxonomy in to javascript 
     45            foreach (self::$instances as $instance){ 
     46                $tax[] = apply_filters('mc_taxonomy', $instance->taxonomy); 
     47            } 
     48                 
     49         
    3250            wp_register_script('media_categories_metabox_script', plugins_url('media-categories-script.js', __FILE__)); 
    3351            wp_enqueue_script('media_categories_metabox_script'); 
    3452             
    35             wp_localize_script('media_categories_metabox_script', 'tax', $tax_name); 
     53            wp_localize_script('media_categories_metabox_script', 'taxonomy',  $tax); 
    3654        } 
    3755    } 
    3856     
     57    /** 
     58     *  
     59     */ 
    3960    function enqueue_media_categories_styles() { 
    4061        if (is_admin()) {  
     
    5172     */ 
    5273    function register_media_categories() { 
    53         $tax_name = apply_filters('mc_taxonomy', 'category'); 
     74        $tax_name = apply_filters('mc_taxonomy', $this->taxonomy); 
    5475         
    5576        register_taxonomy_for_object_type($tax_name, 'attachment'); 
     
    6485        require_once('./includes/meta-boxes.php'); 
    6586         
    66         $tax_name = apply_filters('mc_taxonomy', 'category'); 
     87        $tax_name = apply_filters('mc_taxonomy', $this->taxonomy); 
    6788        $taxonomy = get_taxonomy($tax_name); 
    6889 
    6990        ob_start(); 
    7091         
    71             self::media_categories_meta_box($post, array('args' => array ('taxonomy' => $tax_name, 'tax' => $taxonomy))); 
     92            $this->media_categories_meta_box($post, array('args' => array ('taxonomy' => $tax_name, 'tax' => $taxonomy))); 
    7293             
    7394        $metabox = ob_get_clean(); 
    74  
    75         $form_fields['category_metabox']['label'] = $taxonomy->labels->name; 
    76         $form_fields['category_metabox']['helps'] = sprintf(__('Select a %s, use the text fields above to filter'), strtolower($taxonomy->labels->singular_name)); 
    77         $form_fields['category_metabox']['input'] = 'html'; 
    78         $form_fields['category_metabox']['html'] = $metabox; 
     95         
     96        $form_slug = $this->taxonomy . '_metabox'; 
     97             
     98        $form_fields[$form_slug]['label'] = $taxonomy->labels->name; 
     99        $form_fields[$form_slug]['helps'] = sprintf(__('Select a %s, use the text fields above to filter'), strtolower($taxonomy->labels->singular_name)); 
     100        $form_fields[$form_slug]['input'] = 'html'; 
     101        $form_fields[$form_slug]['html'] = $metabox; 
     102         
    79103        return $form_fields; 
    80104    } 
     
    94118        require_once(plugin_dir_path(__FILE__) . 'attachment-walker-category-checklist-class.php'); 
    95119              
    96         $defaults = array('taxonomy' => apply_filters('mc_taxonomy','category')); 
     120        $defaults = array('taxonomy' => apply_filters('mc_taxonomy',$this->taxonomy)); 
    97121         
    98122        if (!isset($box['args']) || !is_array($box['args'])) 
     
    106130        <div> 
    107131            <label class='category-filter' for="category-filter">Search <?php echo $tax->labels->name; ?>:</label> 
    108             <input id='catsearch' name="category-filter" type='text' /></div> 
     132            <input id='<?php echo $taxonomy?>-search' name="category-filter" type='text' /></div> 
    109133            <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv"> 
    110134 
     
    115139 
    116140            <div id="<?php echo $taxonomy; ?>-pop" class="tabs-panel" style="display: none;"> 
    117                 <ul id="<?php echo $taxonomy; ?>checklist-pop" class="categorychecklist form-no-clear" > 
     141                <ul id="<?php echo $taxonomy; ?>checklist-pop" class="<?php echo $taxonomy; ?>checklist form-no-clear" > 
    118142                    <?php $popular_ids = wp_popular_terms_checklist($taxonomy); ?> 
    119143                </ul> 
     
    126150                ?> 
    127151                 
    128                 <ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy ?> categorychecklist form-no-clear"> 
     152                <ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy ?> <?php echo $taxonomy; ?>checklist form-no-clear"> 
    129153                    <?php $custom_walker = new Attachment_Walker_Category_Checklist ?> 
    130154                    <?php wp_terms_checklist($post->ID, array('taxonomy' => $taxonomy, 'popular_cats' => $popular_ids, 'walker' => $custom_walker)) ?> 
     
    165189    function custom_gallery_shortcode(){ 
    166190        remove_shortcode('gallery'); 
    167         add_shortcode('gallery', array(__CLASS__,'gallery_shortcode')); 
     191        add_shortcode('gallery', array(&$this,'gallery_shortcode')); 
    168192    } 
    169193     
     
    201225        } 
    202226 
    203         $mc_tax = apply_filters('mc_taxonomy', 'category'); 
     227        $mc_tax = apply_filters('mc_taxonomy', $this->taxonomy); 
    204228        extract(shortcode_atts(array( 
    205229            'order'      => 'ASC', 
     
    314338    } 
    315339     
     340    
    316341    /** 
    317342     * This function serves to work around the problem explained in trac ticket 20765 and reported 
     
    358383} 
    359384 
    360 Media_Categories::init(); 
     385$mc_category_metabox = new Media_Categories('category'); 
  • media-categories-2/tags/1.4/readme.txt

    r549552 r553443  
    44Tags: media categories, media, category, categories, attachment categories, taxonomy, category metabox, metabox, admin, media library, media editor, attachment editor, attachment, images, gallery shortcode, gallery, shortcode, gallery category, filter, media taxonomy, post tags 
    55Requires at least: 3.0 
    6 Tested up to: 3.3.1 
    7 Stable tag: 1.3.1 
     6Tested up to: 3.3.2 
     7Stable tag: 1.4 
    88License: GPLv2 or later 
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html 
     
    1313== Description == 
    1414 
    15 Allows users to assign categories to items in their Media Library with a clean and simplified, searchable version of the standard category meta box.  
     15Allows users to assign categories (or other taxonomy terms) to items in their Media Library with a clean and simplified, searchable version of the standard category meta box.  
    1616The "Search Categories" field allows you to narrow your search for a category as you type - this functionality is not native to WordPress but is instead borrowed from Jason Corradino's  
    1717[Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin. If you would like to enable this feature for your posts 
     
    2020 
    2121= Updates = 
    22 * **NEW! Since version 1.3**: A **filter** has been added to allow developers to modify which taxonomy is being used. See 'Other Notes' > 'Taxonomy Filter Usage' for details 
     22* **NEW! Since version 1.4 : This plugin allows for **multiple metaboxes** to be created for any number of taxonomies. 
     23* Since version 1.3 : A **filter** has been added to allow developers to modify which taxonomy is being used. See 'Other Notes' > 'Taxonomy Filter Usage' for details 
    2324* Since version 1.2 : This plugin extends the native **[gallery] shortcode** of WordPress so that it has a 'category' parameter. See the "Shortcode Usage" under "Other Notes" for more details.  
    2425 
    2526 
     27== Shortcode Usage == 
     28 
     29= Normal Shortcode Usage = 
     30 
     31This plugin takes advantage of the existing `[gallery]` shortcode for showing images by adding the `'category'` parameter.  
     32The value passed to the `'category'` parameter can be either the `category` `slug`, or the `term_id`. 
     33 
     34`[gallery category="my-category-slug"] 
     35OR 
     36[gallery category="12"]` 
     37 
     38Its important to note that when passing the `'category'` parameter, the `[gallery]` shortcode will by default **ignore the current post 
     39and simply try to include all images from the category**. The syntax above will retrieve any images that are assigned  
     40to `'my-category-slug'` a.k.a term id `#12`, regardless of whether or not those images are attached to the current post. 
     41 
     42To query within a post (even the current post), you'll need to explicitly add the post id as such... 
     43 
     44`[gallery category="my-category-slug" id="43"]` 
     45 
     46This shortcode will retrieve any images attached to post `#43` that are categorized as `'my-slug-category'`. 
     47 
     48Aside from this behavior, the [gallery] shortcode should behave exactly as it does by default with the built-in shortcode.  
     49The `id` parameter will behave as normal when the `category` parameter is not invoked. 
     50For more information on using the built-in [gallery shortcode checkout the codex page](http://codex.wordpress.org/Gallery_Shortcode). 
     51 
     52 
     53 
     54= Other Taxonomy Shortcode Usage = 
     55 
     56If a developer implementing this plugin has made use of the `mc_taxonomy` filter to modify which taxonomy 
     57this plugin uses for attachments, then the name of that particular taxonomy will need to be used in place of `category`  
     58as the shortcode parameter. For example, if you applied 'Post Tags' to your images then users should use the `post_tag` parameter 
     59in the Gallery Shortcode. 
     60 
     61`[gallery post_tag="my-tag-slug"] 
     62OR 
     63[gallery post_tag="12"]` 
     64 
     65 
     66*[Warning: nerdy developer stuff ahead]* 
     67 
     68== Multiple Taxonomy Metaboxes  *NEW!* == 
     69 
     70Since 1.4 this plugin allows developers to create metaboxes for any number of taxonomies. While previous the previous version allowed  
     71developers to change the taxonomy being used, it still only allowed a single taxonomy metabox to be generated. With 1.4, that has changed. 
     72 
     73All a developer needs to do, is create a new instance of the Media_Categories class and pass their desired taxonomy as an argument. 
     74 
     75` 
     76$my_custom_media_metabox = new Media_Categories('my_custom_taxonomy'); 
     77` 
     78 
     79Thats it!, nothing else to it, the plugin will take care of the rest. You can create as many instances as you like - just make sure to be careful 
     80when doing this in conjunction with the `mc_taxonomy` filter - always check the current taxonomy. 
     81 
     82Obviously this works with any taxonomy, including built-in taxonomies such as 'post_tag', 'link_categories',  
     83and yes, even 'nav_menu'. I'll leave it to you developers out uses for that. 
     84 
     85 
    2686== Taxonomy Filter Usage: 'mc_taxonomy'  == 
     87 
     88**Note**: Since 1.4, this plugin allows developers to generate any number of metaboxes, for any number of different taxonomies. Because of this, 
     89it is important that when filtering the taxonomy, developers conditionally check the current taxonomy before returning a different - otherwise 
     90the filter would override *all* instances of the plugin's metaboxes with the same taxonomy. The examples below have been changes accordingly 
    2791 
    2892Since version 1.3, the Media Categories plugin includes a filter allowing developers to modify the taxonomy being used.  
     
    3498` 
    3599add_filter('mc_taxonomy', 'mc_filter_taxonomy'); 
    36 function mc_filter_taxonomy(){ 
    37     return 'post_tag'; 
     100 
     101function mc_filter_taxonomy($taxonomy){ 
     102 
     103    if($taxonomy == 'category'){ 
     104        $taxonomy = 'post_tag'; 
     105    } 
     106 
     107    return $taxonomy 
    38108} 
    39109` 
     
    48118 
    49119 
    50 == Shortcode Usage == 
    51  
    52 = Normal Shortcode Usage = 
    53  
    54 This plugin takes advantage of the existing `[gallery]` shortcode for showing images by adding the `'category'` parameter.  
    55 The value passed to the `'category'` parameter can be either the `category` `slug`, or the `term_id`. 
    56  
    57 `[gallery category="my-category-slug"] 
    58 OR 
    59 [gallery category="12"]` 
    60  
    61 Its important to note that when passing the `'category'` parameter, the `[gallery]` shortcode will by default **ignore the current post 
    62 and simply try to include all images from the category**. The syntax above will retrieve any images that are assigned  
    63 to `'my-category-slug'` a.k.a term id `#12`, regardless of whether or not those images are attached to the current post. 
    64  
    65 To query within a post (even the current post), you'll need to explicitly add the post id as such... 
    66  
    67 `[gallery category="my-category-slug" id="43"]` 
    68  
    69 This shortcode will retrieve any images attached to post `#43` that are categorized as `'my-slug-category'`. 
    70  
    71 Aside from this behavior, the [gallery] shortcode should behave exactly as it does by default with the built-in shortcode.  
    72 The `id` parameter will behave as normal when the `category` parameter is not invoked. 
    73 For more information on using the built-in [gallery shortcode checkout the codex page](http://codex.wordpress.org/Gallery_Shortcode). 
    74  
    75  
    76  
    77 = Other Taxonomy Shortcode Usage = 
    78  
    79 If a developer implementing this plugin has made use of the `mc_taxonomy` filter to modify which taxonomy 
    80 this plugin uses for attachments, then the name of that particular taxonomy will need to be used in place of `category`  
    81 as the shortcode parameter. For example, if you applied 'Post Tags' to your images then users should use the `post_tag` parameter 
    82 in the Gallery Shortcode. 
    83  
    84 `[gallery post_tag="my-tag-slug"] 
    85 OR 
    86 [gallery post_tag="12"]` 
    87  
    88 == Related Plugins == 
     120== Related Plugin == 
    89121 
    90122Checkout this great plugin for Searchable Categories by Jason Corradino, whose javascript I use in this plugin.  
    91123I believe this very simple functionality should be a part of the standard categories metabox in core.  
    92124While I do not employ the plugin directly, the javascript used for filtering/searching is in fact derived with  
    93 consent, and a few modifications from that plugin. To enable this feature on all you category metabox, the  
     125consent, and a few modifications from that plugin. To enable this feature on all your category metaboxes, install the  
    94126[Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin. 
    95127 
     
    104136== Installation == 
    105137 
    106 1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory 
     1381. Upload `/media-categories-2/` to the `/wp-content/plugins/` directory 
    1071391. Activate the plugin through the 'Plugins' menu in WordPress 
    108140 
     141== Frequently Asked Questions == 
     142 
     143= Can this plugin work with a custom taxonomy, or a built-in taxonomy other than Categories? = 
     144 
     145Yes, modify the taxonomy used by a metabox by making use of the `mc_taxonomy` filter. 
     146They can also create additional metaboxes for other taxonomies by creating new instances 
     147of the Media_Categories class. 
     148 
     149See the 'Multiple Taxonomy Metaboxes' section (a.k.a 'Other Notes') for more details on how 
     150this is done. 
     151 
     152= Can any of this customization explained above be done without writing any code? = 
     153 
     154No. Currently there is no way to change the taxonomy, or create additional taxonomy metaboxes 
     155in the Media Library without adding a little bit of PHP (preferably to you theme). 
     156 
     157Have no fear however, I do have intentions to add magical plugins options pages to allow 
     158as much as possible to be done without development - sorry but I have no timeline for when this 
     159might happen. 
     160 
     161= Is there any way to see all the attachment/media items associated to a category/taxonomy term, the way we can with Posts? = 
     162 
     163Not yet. The next major effort in this plugins development is going to be the addition of taxonomy listing pages.  
     164 
     165= I found a bug, or I would like to suggest/request a feature, can I submit it? = 
     166 
     167Of course, thats great! I love hearing how people want to use my plugins, and if you look though my blog or 
     168this plugins support forum, you'll see I have a tendency of fulfilling people's requests ( but no promises :p ) 
     169 
     170Bug reports are extremely helpful! Most of my plugins have been developed while at work, and publicly submitted bug reports help 
     171prove the point that Open Source is the way to go. It amounts to free public quality assurance testing. So please please please report 
     172any bugs to you see. Preferably on the WordPress plugin directory, but if you feel so inclined you may report them on my blog http:://eddiemoya.com 
     173 
    109174 
    110175== Changelog == 
    111176 
     177= 1.4 = 
     178* New feature! Add multiple metaboxes for media, one for any desired taxonomy by a developer. 
     179 
    112180= 1.3.1 = 
    113 * Workaround to conflicts caused by the way WordPress handles attachments with taxonomies enabled, causing terms with the same name of conflict. 
     181* Bug Fix: Workaround to conflicts caused by the way WordPress handles attachments with taxonomies enabled, causing terms with the same name of conflict. 
    114182* Relevant [Trac Ticket](http://core.trac.wordpress.org/ticket/20765) 
    115183 
     
    132200== Upgrade Notice == 
    133201 
     202= 1.4 =  
     203New Feature! Developers can now generate metaboxes for media for any number of desired taxonomies 
     204 
    134205= 1.3.1 = 
    135206Bug fix (workaround): Taxonomy terms with the same name were causing conflicts - see related [trac ticket](http://core.trac.wordpress.org/ticket/20765) 
  • media-categories-2/trunk/media-categories.php

    r549552 r553443  
    33Plugin URI: http://wordpress.org/extend/plugins/media-categories-2 
    44Description:  Allows users to assign categories to media with a clean and simplified, filterable category meta box and use shortcodes to display category galleries 
    5 Version: 1.3.1 
     5Version: 1.4 
    66Author: Eddie Moya 
    77Author URL: http://eddiemoya.com 
     
    1010class Media_Categories { 
    1111 
    12     /** 
    13      * Start your engines. 
    14      *  
    15      * @author Eddie Moya 
    16      */ 
    17     function init() { 
    18         add_action('init', array(__CLASS__, 'register_media_categories')); 
    19         add_action('init', array(__CLASS__, 'custom_gallery_shortcode')); 
     12    public static $instances; 
     13    public $taxonomy; 
     14     
     15    /** 
     16     * While normally run statically, this allows  
     17     * @param type $taxonomy  
     18     */ 
     19    public function __construct($taxonomy) { 
     20         
     21        // Store each instance of this class (for use when localizing scripts) 
     22        $this->taxonomy = $taxonomy; 
     23        self::$instances[] = $this; 
     24         
     25        add_action('init', array(&$this, 'register_media_categories')); 
     26        add_action('init', array(&$this, 'custom_gallery_shortcode')); 
     27        add_filter('attachment_fields_to_edit', array(&$this, 'add_media_categories_metabox'), null, 2); 
     28         
     29        /* These only need to occur once */ 
     30        add_filter('attachment_fields_to_edit', array(__CLASS__, 'get_attachment_fields_to_edit'), 11, 2); 
    2031        add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_media_categories_scripts')); 
    2132        add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_media_categories_styles') ); 
    22         add_filter('attachment_fields_to_edit', array(__CLASS__, 'add_media_categories_metabox'), null, 2); 
    23         add_filter('attachment_fields_to_edit', array(__CLASS__, 'get_attachment_fields_to_edit'), 11, 2); 
    24          
    25     } 
    26  
     33         
     34         
     35 
     36    } 
     37 
     38    /** 
     39     * Enqueue javascript 
     40     */ 
    2741    function enqueue_media_categories_scripts() { 
    2842        if (is_admin()) { 
    29  
    30             $tax_name = array('name' => apply_filters('mc_taxonomy', 'category')); 
    31              
     43             
     44            // Get each instance of this class, and pass each taxonomy in to javascript 
     45            foreach (self::$instances as $instance){ 
     46                $tax[] = apply_filters('mc_taxonomy', $instance->taxonomy); 
     47            } 
     48                 
     49         
    3250            wp_register_script('media_categories_metabox_script', plugins_url('media-categories-script.js', __FILE__)); 
    3351            wp_enqueue_script('media_categories_metabox_script'); 
    3452             
    35             wp_localize_script('media_categories_metabox_script', 'tax', $tax_name); 
     53            wp_localize_script('media_categories_metabox_script', 'taxonomy',  $tax); 
    3654        } 
    3755    } 
    3856     
     57    /** 
     58     *  
     59     */ 
    3960    function enqueue_media_categories_styles() { 
    4061        if (is_admin()) {  
     
    5172     */ 
    5273    function register_media_categories() { 
    53         $tax_name = apply_filters('mc_taxonomy', 'category'); 
     74        $tax_name = apply_filters('mc_taxonomy', $this->taxonomy); 
    5475         
    5576        register_taxonomy_for_object_type($tax_name, 'attachment'); 
     
    6485        require_once('./includes/meta-boxes.php'); 
    6586         
    66         $tax_name = apply_filters('mc_taxonomy', 'category'); 
     87        $tax_name = apply_filters('mc_taxonomy', $this->taxonomy); 
    6788        $taxonomy = get_taxonomy($tax_name); 
    6889 
    6990        ob_start(); 
    7091         
    71             self::media_categories_meta_box($post, array('args' => array ('taxonomy' => $tax_name, 'tax' => $taxonomy))); 
     92            $this->media_categories_meta_box($post, array('args' => array ('taxonomy' => $tax_name, 'tax' => $taxonomy))); 
    7293             
    7394        $metabox = ob_get_clean(); 
    74  
    75         $form_fields['category_metabox']['label'] = $taxonomy->labels->name; 
    76         $form_fields['category_metabox']['helps'] = sprintf(__('Select a %s, use the text fields above to filter'), strtolower($taxonomy->labels->singular_name)); 
    77         $form_fields['category_metabox']['input'] = 'html'; 
    78         $form_fields['category_metabox']['html'] = $metabox; 
     95         
     96        $form_slug = $this->taxonomy . '_metabox'; 
     97             
     98        $form_fields[$form_slug]['label'] = $taxonomy->labels->name; 
     99        $form_fields[$form_slug]['helps'] = sprintf(__('Select a %s, use the text fields above to filter'), strtolower($taxonomy->labels->singular_name)); 
     100        $form_fields[$form_slug]['input'] = 'html'; 
     101        $form_fields[$form_slug]['html'] = $metabox; 
     102         
    79103        return $form_fields; 
    80104    } 
     
    94118        require_once(plugin_dir_path(__FILE__) . 'attachment-walker-category-checklist-class.php'); 
    95119              
    96         $defaults = array('taxonomy' => apply_filters('mc_taxonomy','category')); 
     120        $defaults = array('taxonomy' => apply_filters('mc_taxonomy',$this->taxonomy)); 
    97121         
    98122        if (!isset($box['args']) || !is_array($box['args'])) 
     
    106130        <div> 
    107131            <label class='category-filter' for="category-filter">Search <?php echo $tax->labels->name; ?>:</label> 
    108             <input id='catsearch' name="category-filter" type='text' /></div> 
     132            <input id='<?php echo $taxonomy?>-search' name="category-filter" type='text' /></div> 
    109133            <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv"> 
    110134 
     
    115139 
    116140            <div id="<?php echo $taxonomy; ?>-pop" class="tabs-panel" style="display: none;"> 
    117                 <ul id="<?php echo $taxonomy; ?>checklist-pop" class="categorychecklist form-no-clear" > 
     141                <ul id="<?php echo $taxonomy; ?>checklist-pop" class="<?php echo $taxonomy; ?>checklist form-no-clear" > 
    118142                    <?php $popular_ids = wp_popular_terms_checklist($taxonomy); ?> 
    119143                </ul> 
     
    126150                ?> 
    127151                 
    128                 <ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy ?> categorychecklist form-no-clear"> 
     152                <ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy ?> <?php echo $taxonomy; ?>checklist form-no-clear"> 
    129153                    <?php $custom_walker = new Attachment_Walker_Category_Checklist ?> 
    130154                    <?php wp_terms_checklist($post->ID, array('taxonomy' => $taxonomy, 'popular_cats' => $popular_ids, 'walker' => $custom_walker)) ?> 
     
    165189    function custom_gallery_shortcode(){ 
    166190        remove_shortcode('gallery'); 
    167         add_shortcode('gallery', array(__CLASS__,'gallery_shortcode')); 
     191        add_shortcode('gallery', array(&$this,'gallery_shortcode')); 
    168192    } 
    169193     
     
    201225        } 
    202226 
    203         $mc_tax = apply_filters('mc_taxonomy', 'category'); 
     227        $mc_tax = apply_filters('mc_taxonomy', $this->taxonomy); 
    204228        extract(shortcode_atts(array( 
    205229            'order'      => 'ASC', 
     
    314338    } 
    315339     
     340    
    316341    /** 
    317342     * This function serves to work around the problem explained in trac ticket 20765 and reported 
     
    358383} 
    359384 
    360 Media_Categories::init(); 
     385$mc_category_metabox = new Media_Categories('category'); 
  • media-categories-2/trunk/readme.txt

    r549552 r553443  
    44Tags: media categories, media, category, categories, attachment categories, taxonomy, category metabox, metabox, admin, media library, media editor, attachment editor, attachment, images, gallery shortcode, gallery, shortcode, gallery category, filter, media taxonomy, post tags 
    55Requires at least: 3.0 
    6 Tested up to: 3.3.1 
    7 Stable tag: 1.3.1 
     6Tested up to: 3.3.2 
     7Stable tag: 1.4 
    88License: GPLv2 or later 
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html 
     
    1313== Description == 
    1414 
    15 Allows users to assign categories to items in their Media Library with a clean and simplified, searchable version of the standard category meta box.  
     15Allows users to assign categories (or other taxonomy terms) to items in their Media Library with a clean and simplified, searchable version of the standard category meta box.  
    1616The "Search Categories" field allows you to narrow your search for a category as you type - this functionality is not native to WordPress but is instead borrowed from Jason Corradino's  
    1717[Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin. If you would like to enable this feature for your posts 
     
    2020 
    2121= Updates = 
    22 * **NEW! Since version 1.3**: A **filter** has been added to allow developers to modify which taxonomy is being used. See 'Other Notes' > 'Taxonomy Filter Usage' for details 
     22* **NEW! Since version 1.4 : This plugin allows for **multiple metaboxes** to be created for any number of taxonomies. 
     23* Since version 1.3 : A **filter** has been added to allow developers to modify which taxonomy is being used. See 'Other Notes' > 'Taxonomy Filter Usage' for details 
    2324* Since version 1.2 : This plugin extends the native **[gallery] shortcode** of WordPress so that it has a 'category' parameter. See the "Shortcode Usage" under "Other Notes" for more details.  
    2425 
    2526 
     27== Shortcode Usage == 
     28 
     29= Normal Shortcode Usage = 
     30 
     31This plugin takes advantage of the existing `[gallery]` shortcode for showing images by adding the `'category'` parameter.  
     32The value passed to the `'category'` parameter can be either the `category` `slug`, or the `term_id`. 
     33 
     34`[gallery category="my-category-slug"] 
     35OR 
     36[gallery category="12"]` 
     37 
     38Its important to note that when passing the `'category'` parameter, the `[gallery]` shortcode will by default **ignore the current post 
     39and simply try to include all images from the category**. The syntax above will retrieve any images that are assigned  
     40to `'my-category-slug'` a.k.a term id `#12`, regardless of whether or not those images are attached to the current post. 
     41 
     42To query within a post (even the current post), you'll need to explicitly add the post id as such... 
     43 
     44`[gallery category="my-category-slug" id="43"]` 
     45 
     46This shortcode will retrieve any images attached to post `#43` that are categorized as `'my-slug-category'`. 
     47 
     48Aside from this behavior, the [gallery] shortcode should behave exactly as it does by default with the built-in shortcode.  
     49The `id` parameter will behave as normal when the `category` parameter is not invoked. 
     50For more information on using the built-in [gallery shortcode checkout the codex page](http://codex.wordpress.org/Gallery_Shortcode). 
     51 
     52 
     53 
     54= Other Taxonomy Shortcode Usage = 
     55 
     56If a developer implementing this plugin has made use of the `mc_taxonomy` filter to modify which taxonomy 
     57this plugin uses for attachments, then the name of that particular taxonomy will need to be used in place of `category`  
     58as the shortcode parameter. For example, if you applied 'Post Tags' to your images then users should use the `post_tag` parameter 
     59in the Gallery Shortcode. 
     60 
     61`[gallery post_tag="my-tag-slug"] 
     62OR 
     63[gallery post_tag="12"]` 
     64 
     65 
     66*[Warning: nerdy developer stuff ahead]* 
     67 
     68== Multiple Taxonomy Metaboxes  *NEW!* == 
     69 
     70Since 1.4 this plugin allows developers to create metaboxes for any number of taxonomies. While previous the previous version allowed  
     71developers to change the taxonomy being used, it still only allowed a single taxonomy metabox to be generated. With 1.4, that has changed. 
     72 
     73All a developer needs to do, is create a new instance of the Media_Categories class and pass their desired taxonomy as an argument. 
     74 
     75` 
     76$my_custom_media_metabox = new Media_Categories('my_custom_taxonomy'); 
     77` 
     78 
     79Thats it!, nothing else to it, the plugin will take care of the rest. You can create as many instances as you like - just make sure to be careful 
     80when doing this in conjunction with the `mc_taxonomy` filter - always check the current taxonomy. 
     81 
     82Obviously this works with any taxonomy, including built-in taxonomies such as 'post_tag', 'link_categories',  
     83and yes, even 'nav_menu'. I'll leave it to you developers out uses for that. 
     84 
     85 
    2686== Taxonomy Filter Usage: 'mc_taxonomy'  == 
     87 
     88**Note**: Since 1.4, this plugin allows developers to generate any number of metaboxes, for any number of different taxonomies. Because of this, 
     89it is important that when filtering the taxonomy, developers conditionally check the current taxonomy before returning a different - otherwise 
     90the filter would override *all* instances of the plugin's metaboxes with the same taxonomy. The examples below have been changes accordingly 
    2791 
    2892Since version 1.3, the Media Categories plugin includes a filter allowing developers to modify the taxonomy being used.  
     
    3498` 
    3599add_filter('mc_taxonomy', 'mc_filter_taxonomy'); 
    36 function mc_filter_taxonomy(){ 
    37     return 'post_tag'; 
     100 
     101function mc_filter_taxonomy($taxonomy){ 
     102 
     103    if($taxonomy == 'category'){ 
     104        $taxonomy = 'post_tag'; 
     105    } 
     106 
     107    return $taxonomy 
    38108} 
    39109` 
     
    48118 
    49119 
    50 == Shortcode Usage == 
    51  
    52 = Normal Shortcode Usage = 
    53  
    54 This plugin takes advantage of the existing `[gallery]` shortcode for showing images by adding the `'category'` parameter.  
    55 The value passed to the `'category'` parameter can be either the `category` `slug`, or the `term_id`. 
    56  
    57 `[gallery category="my-category-slug"] 
    58 OR 
    59 [gallery category="12"]` 
    60  
    61 Its important to note that when passing the `'category'` parameter, the `[gallery]` shortcode will by default **ignore the current post 
    62 and simply try to include all images from the category**. The syntax above will retrieve any images that are assigned  
    63 to `'my-category-slug'` a.k.a term id `#12`, regardless of whether or not those images are attached to the current post. 
    64  
    65 To query within a post (even the current post), you'll need to explicitly add the post id as such... 
    66  
    67 `[gallery category="my-category-slug" id="43"]` 
    68  
    69 This shortcode will retrieve any images attached to post `#43` that are categorized as `'my-slug-category'`. 
    70  
    71 Aside from this behavior, the [gallery] shortcode should behave exactly as it does by default with the built-in shortcode.  
    72 The `id` parameter will behave as normal when the `category` parameter is not invoked. 
    73 For more information on using the built-in [gallery shortcode checkout the codex page](http://codex.wordpress.org/Gallery_Shortcode). 
    74  
    75  
    76  
    77 = Other Taxonomy Shortcode Usage = 
    78  
    79 If a developer implementing this plugin has made use of the `mc_taxonomy` filter to modify which taxonomy 
    80 this plugin uses for attachments, then the name of that particular taxonomy will need to be used in place of `category`  
    81 as the shortcode parameter. For example, if you applied 'Post Tags' to your images then users should use the `post_tag` parameter 
    82 in the Gallery Shortcode. 
    83  
    84 `[gallery post_tag="my-tag-slug"] 
    85 OR 
    86 [gallery post_tag="12"]` 
    87  
    88 == Related Plugins == 
     120== Related Plugin == 
    89121 
    90122Checkout this great plugin for Searchable Categories by Jason Corradino, whose javascript I use in this plugin.  
    91123I believe this very simple functionality should be a part of the standard categories metabox in core.  
    92124While I do not employ the plugin directly, the javascript used for filtering/searching is in fact derived with  
    93 consent, and a few modifications from that plugin. To enable this feature on all you category metabox, the  
     125consent, and a few modifications from that plugin. To enable this feature on all your category metaboxes, install the  
    94126[Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin. 
    95127 
     
    104136== Installation == 
    105137 
    106 1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory 
     1381. Upload `/media-categories-2/` to the `/wp-content/plugins/` directory 
    1071391. Activate the plugin through the 'Plugins' menu in WordPress 
    108140 
     141== Frequently Asked Questions == 
     142 
     143= Can this plugin work with a custom taxonomy, or a built-in taxonomy other than Categories? = 
     144 
     145Yes, modify the taxonomy used by a metabox by making use of the `mc_taxonomy` filter. 
     146They can also create additional metaboxes for other taxonomies by creating new instances 
     147of the Media_Categories class. 
     148 
     149See the 'Multiple Taxonomy Metaboxes' section (a.k.a 'Other Notes') for more details on how 
     150this is done. 
     151 
     152= Can any of this customization explained above be done without writing any code? = 
     153 
     154No. Currently there is no way to change the taxonomy, or create additional taxonomy metaboxes 
     155in the Media Library without adding a little bit of PHP (preferably to you theme). 
     156 
     157Have no fear however, I do have intentions to add magical plugins options pages to allow 
     158as much as possible to be done without development - sorry but I have no timeline for when this 
     159might happen. 
     160 
     161= Is there any way to see all the attachment/media items associated to a category/taxonomy term, the way we can with Posts? = 
     162 
     163Not yet. The next major effort in this plugins development is going to be the addition of taxonomy listing pages.  
     164 
     165= I found a bug, or I would like to suggest/request a feature, can I submit it? = 
     166 
     167Of course, thats great! I love hearing how people want to use my plugins, and if you look though my blog or 
     168this plugins support forum, you'll see I have a tendency of fulfilling people's requests ( but no promises :p ) 
     169 
     170Bug reports are extremely helpful! Most of my plugins have been developed while at work, and publicly submitted bug reports help 
     171prove the point that Open Source is the way to go. It amounts to free public quality assurance testing. So please please please report 
     172any bugs to you see. Preferably on the WordPress plugin directory, but if you feel so inclined you may report them on my blog http:://eddiemoya.com 
     173 
    109174 
    110175== Changelog == 
    111176 
     177= 1.4 = 
     178* New feature! Add multiple metaboxes for media, one for any desired taxonomy by a developer. 
     179 
    112180= 1.3.1 = 
    113 * Workaround to conflicts caused by the way WordPress handles attachments with taxonomies enabled, causing terms with the same name of conflict. 
     181* Bug Fix: Workaround to conflicts caused by the way WordPress handles attachments with taxonomies enabled, causing terms with the same name of conflict. 
    114182* Relevant [Trac Ticket](http://core.trac.wordpress.org/ticket/20765) 
    115183 
     
    132200== Upgrade Notice == 
    133201 
     202= 1.4 =  
     203New Feature! Developers can now generate metaboxes for media for any number of desired taxonomies 
     204 
    134205= 1.3.1 = 
    135206Bug fix (workaround): Taxonomy terms with the same name were causing conflicts - see related [trac ticket](http://core.trac.wordpress.org/ticket/20765) 
Note: See TracChangeset for help on using the changeset viewer.