WordPress.org

Plugin Directory

Changeset 541444


Ignore:
Timestamp:
05/08/12 14:49:09 (2 years ago)
Author:
eddiemoya
Message:

version 1.3

Location:
media-categories-2
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • media-categories-2/tags/1.3/media-categories-script.js

    r538292 r541444  
    1  
    2  
     1/** 
     2 * jQuery for Media Categories plugin 
     3 *  
     4 * @author Eddie Moya 
     5 * @since 1.1 
     6 *  
     7 */ 
    38 
    49jQuery(document).ready(function($){ 
    5      
    6     $('tr.category_metabox input').live('click', function(){ 
     10    $('.media-upload-form tr.post_tag').hide(); 
     11    $('.media-upload-form tr.category_metabox input').live('click', function(){ 
    712         
    813        var form_fields = $(this).closest("tbody"); 
     
    1924        }); 
    2025         
    21         form_fields.find("tr.category > td.field > input.text").val(slug_list); 
     26        form_fields.find("tr."+tax.name+" > td.field > input.text").val(slug_list); 
    2227    }) 
    2328     
     
    2833    }); 
    2934    /** 
    30      * The following javascript is borrowed from Jason Corradino's 'Searchable Categories' plugin. 
    31      * It allows the category metabox to be filtered as the user types. To do this with your 
    32      * category meta boxes on pages and posts, download his plugin. 
     35     * The following javascript is borrowed (with few modifications) from Jason Corradino's  
     36     * 'Searchable Categories' plugin. It allows the category metabox to be filtered  
     37     * as the user types. To do this with your category meta boxes on pages and posts,  
     38     * download his plugin. 
    3339     *  
    3440     * http://wordpress.org/extend/plugins/searchable-categories/ 
     
    3642     
    3743    $('#catsearch').keyup(function() { 
    38         var val = $('#catsearch').val(), lis = $("#categorychecklist li"); 
    39  
     44        var val = $('#catsearch').val(), lis = $("#"+tax.name+"checklist li"); 
    4045        lis.hide(); 
    4146         
    4247        // find li labels's containing term, then back to parent li 
    43         var containingLabels = $("#categorychecklist label:icontains('" + val + "')"); 
     48        var containingLabels = $("#"+tax.name+"checklist label:icontains('" + val + "')"); 
    4449        containingLabels.closest('li').find('li').andSelf().show(); 
    45         containingLabels.parents('#categorychecklist li').show(); 
     50        containingLabels.parents('#'+tax.name+'checklist li').show(); 
    4651    }); 
    4752     
  • media-categories-2/tags/1.3/media-categories-style.css

    r490865 r541444  
    11.media-upload-form .category-tabs,  
    22.media-upload-form tr.category, 
    3 .media-upload-form #category-adder{ 
     3.media-upload-form #category-adder, 
     4.media-upload-form .wp-hidden-children{ 
    45    display:none; 
    56} 
  • media-categories-2/tags/1.3/media-categories.php

    r539258 r541444  
    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.2 
     5Version: 1.3 
    66Author: Eddie Moya 
    77Author URL: http://eddiemoya.com 
     
    2424    } 
    2525 
    26  
    2726    function enqueue_media_categories_scripts() { 
    2827        if (is_admin()) { 
    2928 
    30             wp_register_script('media_categories_metabox_script', WP_PLUGIN_URL . '/media-categories-2/media-categories-script.js'); 
     29            $tax_name = array('name' => apply_filters('mc_taxonomy', 'category')); 
     30             
     31            wp_register_script('media_categories_metabox_script', plugins_url('media-categories-script.js', __FILE__)); 
    3132            wp_enqueue_script('media_categories_metabox_script'); 
     33             
     34            wp_localize_script('media_categories_metabox_script', 'tax', $tax_name); 
    3235        } 
    3336    } 
     
    3639        if (is_admin()) {  
    3740             
    38             wp_register_style('media_categories_metabox_style', WP_PLUGIN_URL . '/media-categories-2/media-categories-style.css'); 
     41            wp_register_style('media_categories_metabox_style', plugins_url('media-categories-style.css', __FILE__)); 
    3942            wp_enqueue_style( 'media_categories_metabox_style'); 
    4043        } 
     
    4750     */ 
    4851    function register_media_categories() { 
    49         register_taxonomy_for_object_type('category', 'attachment'); 
    50         add_post_type_support('attachment', 'category'); 
     52        $tax_name = apply_filters('mc_taxonomy', 'category'); 
     53         
     54        register_taxonomy_for_object_type($tax_name, 'attachment'); 
    5155    } 
    5256 
     
    5862 
    5963        require_once('./includes/meta-boxes.php'); 
     64         
     65        $tax_name = apply_filters('mc_taxonomy', 'category'); 
     66        $taxonomy = get_taxonomy($tax_name); 
    6067 
    6168        ob_start(); 
    62  
    63         self::media_categories_meta_box($post, array('taxonomy' => 'category')); 
    64  
     69         
     70            self::media_categories_meta_box($post, array('args' => array ('taxonomy' => $tax_name, 'tax' => $taxonomy))); 
     71             
    6572        $metabox = ob_get_clean(); 
    6673         
    67         $form_fields['category_metabox']['label'] = __('Categories'); 
    68         $form_fields['category_metabox']['helps'] = 'Select a catgegory, use the text fields above to filter'; 
     74        $form_fields['category_metabox']['label'] = $taxonomy->labels->name; 
     75        $form_fields['category_metabox']['helps'] = sprintf(__('Select a %s, use the text fields above to filter'), strtolower($taxonomy->labels->singular_name)); 
    6976        $form_fields['category_metabox']['input'] = 'html'; 
    7077        $form_fields['category_metabox']['html'] = $metabox; 
     
    8592         
    8693        require_once(plugin_dir_path(__FILE__) . 'attachment-walker-category-checklist-class.php'); 
    87            
    88         $defaults = array('taxonomy' => 'category'); 
     94              
     95        $defaults = array('taxonomy' => apply_filters('mc_taxonomy','category')); 
     96         
    8997        if (!isset($box['args']) || !is_array($box['args'])) 
    9098            $args = array(); 
     
    94102        $tax = get_taxonomy($taxonomy); 
    95103        ?> 
     104 
    96105        <div> 
    97             <label class='category-filter' for="category-filter">Search Categories:</label> 
     106            <label class='category-filter' for="category-filter">Search <?php echo $tax->labels->name; ?>:</label> 
    98107            <input id='catsearch' name="category-filter" type='text' /></div> 
    99         <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv"> 
     108            <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv"> 
     109 
    100110            <ul id="<?php echo $taxonomy; ?>-tabs" class="category-tabs"> 
    101111                <li class="tabs"><a href="#<?php echo $taxonomy; ?>-all" tabindex="3"><?php echo $tax->labels->all_items; ?></a></li> 
     
    105115            <div id="<?php echo $taxonomy; ?>-pop" class="tabs-panel" style="display: none;"> 
    106116                <ul id="<?php echo $taxonomy; ?>checklist-pop" class="categorychecklist form-no-clear" > 
    107         <?php $popular_ids = wp_popular_terms_checklist($taxonomy); ?> 
     117                    <?php $popular_ids = wp_popular_terms_checklist($taxonomy); ?> 
    108118                </ul> 
    109119            </div> 
    110120 
    111121            <div id="<?php echo $taxonomy; ?>-all" class="tabs-panel"> 
    112         <?php 
    113         $name = ( $taxonomy == 'category' ) ? 'post_category' : 'tax_input[' . $taxonomy . ']'; 
    114         echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. 
    115         ?> 
     122                <?php 
     123                $name = ( $taxonomy == 'category' ) ? 'post_category' : 'tax_input[' . $taxonomy . ']'; 
     124                echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. 
     125                ?> 
     126                 
    116127                <ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy ?> categorychecklist form-no-clear"> 
    117                 <?php $custom_walker = new Attachment_Walker_Category_Checklist ?> 
     128                    <?php $custom_walker = new Attachment_Walker_Category_Checklist ?> 
    118129                    <?php wp_terms_checklist($post->ID, array('taxonomy' => $taxonomy, 'popular_cats' => $popular_ids, 'walker' => $custom_walker)) ?> 
    119130                </ul> 
     
    123134        <?php if (current_user_can($tax->cap->edit_terms)) : ?> 
    124135             
    125                 <div id="<?php echo $taxonomy; ?>-adder" class="wp-hidden-children"> 
    126                     <h4> 
    127                         <a id="<?php echo $taxonomy; ?>-add-toggle" href="#<?php echo $taxonomy; ?>-add" class="hide-if-no-js" tabindex="3"> 
    128             <?php 
    129             /* translators: %s: add new taxonomy label */ 
    130             printf(__('+ %s'), $tax->labels->add_new_item); 
    131             ?> 
    132                         </a> 
    133                     </h4> 
    134                     <p id="<?php echo $taxonomy; ?>-add" class="category-add wp-hidden-child"> 
    135                         <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>"><?php echo $tax->labels->add_new_item; ?></label> 
    136                         <input type="text" name="new<?php echo $taxonomy; ?>" id="new<?php echo $taxonomy; ?>" class="form-required form-input-tip" value="<?php echo esc_attr($tax->labels->new_item_name); ?>" tabindex="3" aria-required="true"/> 
    137                         <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>_parent"> 
    138             <?php echo $tax->labels->parent_item_colon; ?> 
    139                         </label> 
    140                             <?php wp_dropdown_categories(array('taxonomy' => $taxonomy, 'hide_empty' => 0, 'name' => 'new' . $taxonomy . '_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '&mdash; ' . $tax->labels->parent_item . ' &mdash;', 'tab_index' => 3)); ?> 
    141                         <input type="button" id="<?php echo $taxonomy; ?>-add-submit" class="add:<?php echo $taxonomy ?>checklist:<?php echo $taxonomy ?>-add button category-add-sumbit" value="<?php echo esc_attr($tax->labels->add_new_item); ?>" tabindex="3" /> 
    142                         <?php wp_nonce_field('add-' . $taxonomy, '_ajax_nonce-add-' . $taxonomy, false); ?> 
    143                         <span id="<?php echo $taxonomy; ?>-ajax-response"></span> 
    144                     </p> 
    145                 </div> 
     136             <div id="<?php echo $taxonomy; ?>-adder" class="wp-hidden-children"> 
     137                <h4> 
     138                    <a id="<?php echo $taxonomy; ?>-add-toggle" href="#<?php echo $taxonomy; ?>-add" class="hide-if-no-js" tabindex="3"> 
     139                        <?php printf(__('+ %s'), $tax->labels->add_new_item);/* translators: %s: add new taxonomy label */ ?>  
     140                    </a> 
     141                </h4> 
     142                 
     143                <p id="<?php echo $taxonomy; ?>-add" class="category-add wp-hidden-child"> 
     144                     
     145                    <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>"><?php echo $tax->labels->add_new_item; ?></label> 
     146                    <input type="text" name="new<?php echo $taxonomy; ?>" id="new<?php echo $taxonomy; ?>" class="form-required form-input-tip" value="<?php echo esc_attr($tax->labels->new_item_name); ?>" tabindex="3" aria-required="true"/> 
     147 
     148                    <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>_parent"> 
     149                        <?php echo $tax->labels->parent_item_colon; ?> 
     150                    </label> 
     151 
     152                    <?php wp_dropdown_categories(array('taxonomy' => $taxonomy, 'hide_empty' => 0, 'name' => 'new' . $taxonomy . '_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '&mdash; ' . $tax->labels->parent_item . ' &mdash;', 'tab_index' => 3)); ?> 
     153                    <input type="button" id="<?php echo $taxonomy; ?>-add-submit" class="add:<?php echo $taxonomy ?>checklist:<?php echo $taxonomy ?>-add button category-add-sumbit" value="<?php echo esc_attr($tax->labels->add_new_item); ?>" tabindex="3" /> 
     154 
     155                    <?php wp_nonce_field('add-' . $taxonomy, '_ajax_nonce-add-' . $taxonomy, false); ?> 
     156                    <span id="<?php echo $taxonomy; ?>-ajax-response"></span> 
     157                </p> 
     158            </div> 
    146159        <?php endif; ?> 
    147160        </div> 
     
    187200        } 
    188201 
     202        $mc_tax = apply_filters('mc_taxonomy', 'category'); 
    189203        extract(shortcode_atts(array( 
    190204            'order'      => 'ASC', 
     
    198212            'include'    => '', 
    199213            'exclude'    => '', 
    200             'category'   => '' 
     214            $mc_tax      => ''    
    201215        ), $attr)); 
    202216         
     
    204218        if ( 'RAND' == $order ) 
    205219            $orderby = 'none'; 
    206  
    207         if( !empty($category) ){  
    208             if(!is_numeric($category)) 
    209                 $category = get_category_by_slug($category)->term_id; 
    210  
     220                 
     221        if( !empty($$mc_tax) ){  
     222    
     223            $term = ${$mc_tax}; 
     224            $term_field = (is_numeric($term)) ? 'id' : 'slug'; 
     225               
    211226            if(!isset($attr['id'])) 
    212227                $id = ''; 
     
    215230        if ( !empty($include) ) { 
    216231            $include = preg_replace( '/[^0-9,]+/', '', $include ); 
    217             $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'category' => $category) ); 
     232            $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'tax_query' => array(array('taxonomy' => $mc_tax, 'field' => $term_field, 'terms' => $term))) ); 
    218233 
    219234            $attachments = array(); 
     
    223238        } elseif ( !empty($exclude) ) { 
    224239            $exclude = preg_replace( '/[^0-9,]+/', '', $exclude ); 
    225             $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'category' => $category) ); 
     240            $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'tax_query' => array(array('taxonomy' => $mc_tax, 'field' => $term_field, 'terms' => $term))) ); 
    226241        } else { 
    227             $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'category' => $category) ); 
     242            $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'tax_query' => array(array('taxonomy' => $mc_tax, 'field' => $term_field, 'terms' => $term))) ); 
    228243        } 
    229244 
  • media-categories-2/tags/1.3/readme.txt

    r538292 r541444  
    22Contributors: eddiemoya 
    33Donate link: http://eddiemoya.com 
    4 Tags: 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 
     4Tags: 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 
    66Tested up to: 3.3.1 
    7 Stable tag: 1.2 
     7Stable tag: 1.3 
     8License: GPLv2 or later 
     9License URI: http://www.gnu.org/licenses/gpl-2.0.html 
    810 
    911Easily assign categories to media with a clean, simple, and searchable category meta box. Then use the gallery shortcode to display category galleries 
     
    1618[download his plugin here](http://wordpress.org/extend/plugins/searchable-categories/) 
    1719 
    18 NEW! 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. 
     20 
     21= 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 
     23* 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.  
     24 
     25 
     26== Taxonomy Filter Usage: 'mc_taxonomy'  == 
     27 
     28Since version 1.3, the Media Categories plugin includes a filter allowing developers to modify the taxonomy being used.  
     29Changing the taxonomy will automatically change all the labels used around the metabox, and change the way the Gallery Shortcode 
     30works so that it accommodates whatever taxonomy has been chosen. 
     31 
     32The tag for this filter is `'mc_taxonomy'`, and usage could not be simpler. 
     33 
     34` 
     35add_filter('mc_taxonomy', 'mc_filter_taxonomy'); 
     36function mc_filter_taxonomy(){ 
     37    return 'post_tag'; 
     38} 
     39` 
     40The above code will swap out all references to 'category' with appropriate (properly pluralized) references to the 'post_tag' taxonomy. 
     41 
     42It will also change the way the Gallery Shortcode works to use your chosen taxonomy. 
     43 
     44= Important (potential gotchas) = 
     45* The `category` parameter for the Gallery Shortcode will be changed by using this filter, so that instead of `category` is will by `your_taxonomy`. In the case above with tags, 
     46you would write a shortcode as such. `[gallery post_tag="my-tag"]` OR `[gallery post_tag="43"]`. 
     47* If using a Custom Taxonomy with this plugin, be sure to assign values to the labels for proper pluralization and context 
    1948 
    2049 
    2150== Shortcode Usage == 
     51 
     52= Normal Shortcode Usage = 
    2253 
    2354This plugin takes advantage of the existing `[gallery]` shortcode for showing images by adding the `'category'` parameter.  
     
    4273For more information on using the built-in [gallery shortcode checkout the codex page](http://codex.wordpress.org/Gallery_Shortcode). 
    4374 
     75 
     76 
     77= Other Taxonomy Shortcode Usage = 
     78 
     79If a developer implementing this plugin has made use of the `mc_taxonomy` filter to modify which taxonomy 
     80this plugin uses for attachments, then the name of that particular taxonomy will need to be used in place of `category`  
     81as the shortcode parameter. For example, if you applied 'Post Tags' to your images then users should use the `post_tag` parameter 
     82in the Gallery Shortcode. 
     83 
     84`[gallery post_tag="my-tag-slug"] 
     85OR 
     86[gallery post_tag="12"]` 
     87 
    4488== Related Plugins == 
    4589 
    46 As stated in the description, the search functionality in this plugin is taken from Jason Corradino's  
    47 [Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin. While I do 
    48 not employ the plugin directly, the javascript used for filtering is in fact derived with consent from  
    49 that plugin. To enable this feature on all you category metabox, the  
    50 [Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin 
    51  
    52 = TL;DR = 
    5390Checkout this great plugin for Searchable Categories by Jason Corradino, whose javascript I use in this plugin.  
    54 I believe this very simple functionality should be a part of the standard categories metabox in core. 
     91I believe this very simple functionality should be a part of the standard categories metabox in core.  
     92While I do not employ the plugin directly, the javascript used for filtering/searching is in fact derived with  
     93consent, and a few modifications from that plugin. To enable this feature on all you category metabox, the  
     94[Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin. 
    5595 
    5696* [Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) by Jason Corradino 
     
    70110== Changelog == 
    71111 
     112= 1.3 = 
     113* Added a filter to allow developers to change the taxonomy being used for their media. 
     114* Modified the Gallery Shortcode functionality to work with any chosen taxonomy. 
     115 
    72116= 1.2 = 
    73 * Added 'category' parameter to [gallery] shortcode. 
     117* Added `'category'` parameter to `[gallery]` shortcode. 
    74118* Modified the Searchable Categories script to make the search field case insensitive. 
    75119* Fixed styling problem on Media Library modal windows - the filter and styling were not working. 
    76120 
    77121= 1.1 =  
    78 * Changed jQuery to use .live() rather than .on() for compatability with WordPress earlier than 3.3 - jQuery 1.7 was only added in v3.3 
     122* Changed jQuery to use `.live()` rather than `.on()` for compatability with WordPress earlier than 3.3 - jQuery 1.7 was only added in v3.3 
    79123* Removed superfluous file which was accidentally included from a different plugin of mine. Would cause fatal errors if both plugins were turned on at the same time. 
    80124 
  • media-categories-2/trunk/media-categories-script.js

    r538292 r541444  
    1  
    2  
     1/** 
     2 * jQuery for Media Categories plugin 
     3 *  
     4 * @author Eddie Moya 
     5 * @since 1.1 
     6 *  
     7 */ 
    38 
    49jQuery(document).ready(function($){ 
    5      
    6     $('tr.category_metabox input').live('click', function(){ 
     10    $('.media-upload-form tr.post_tag').hide(); 
     11    $('.media-upload-form tr.category_metabox input').live('click', function(){ 
    712         
    813        var form_fields = $(this).closest("tbody"); 
     
    1924        }); 
    2025         
    21         form_fields.find("tr.category > td.field > input.text").val(slug_list); 
     26        form_fields.find("tr."+tax.name+" > td.field > input.text").val(slug_list); 
    2227    }) 
    2328     
     
    2833    }); 
    2934    /** 
    30      * The following javascript is borrowed from Jason Corradino's 'Searchable Categories' plugin. 
    31      * It allows the category metabox to be filtered as the user types. To do this with your 
    32      * category meta boxes on pages and posts, download his plugin. 
     35     * The following javascript is borrowed (with few modifications) from Jason Corradino's  
     36     * 'Searchable Categories' plugin. It allows the category metabox to be filtered  
     37     * as the user types. To do this with your category meta boxes on pages and posts,  
     38     * download his plugin. 
    3339     *  
    3440     * http://wordpress.org/extend/plugins/searchable-categories/ 
     
    3642     
    3743    $('#catsearch').keyup(function() { 
    38         var val = $('#catsearch').val(), lis = $("#categorychecklist li"); 
    39  
     44        var val = $('#catsearch').val(), lis = $("#"+tax.name+"checklist li"); 
    4045        lis.hide(); 
    4146         
    4247        // find li labels's containing term, then back to parent li 
    43         var containingLabels = $("#categorychecklist label:icontains('" + val + "')"); 
     48        var containingLabels = $("#"+tax.name+"checklist label:icontains('" + val + "')"); 
    4449        containingLabels.closest('li').find('li').andSelf().show(); 
    45         containingLabels.parents('#categorychecklist li').show(); 
     50        containingLabels.parents('#'+tax.name+'checklist li').show(); 
    4651    }); 
    4752     
  • media-categories-2/trunk/media-categories-style.css

    r490865 r541444  
    11.media-upload-form .category-tabs,  
    22.media-upload-form tr.category, 
    3 .media-upload-form #category-adder{ 
     3.media-upload-form #category-adder, 
     4.media-upload-form .wp-hidden-children{ 
    45    display:none; 
    56} 
  • media-categories-2/trunk/media-categories.php

    r539258 r541444  
    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.2 
     5Version: 1.3 
    66Author: Eddie Moya 
    77Author URL: http://eddiemoya.com 
     
    2424    } 
    2525 
    26  
    2726    function enqueue_media_categories_scripts() { 
    2827        if (is_admin()) { 
    2928 
    30             wp_register_script('media_categories_metabox_script', WP_PLUGIN_URL . '/media-categories-2/media-categories-script.js'); 
     29            $tax_name = array('name' => apply_filters('mc_taxonomy', 'category')); 
     30             
     31            wp_register_script('media_categories_metabox_script', plugins_url('media-categories-script.js', __FILE__)); 
    3132            wp_enqueue_script('media_categories_metabox_script'); 
     33             
     34            wp_localize_script('media_categories_metabox_script', 'tax', $tax_name); 
    3235        } 
    3336    } 
     
    3639        if (is_admin()) {  
    3740             
    38             wp_register_style('media_categories_metabox_style', WP_PLUGIN_URL . '/media-categories-2/media-categories-style.css'); 
     41            wp_register_style('media_categories_metabox_style', plugins_url('media-categories-style.css', __FILE__)); 
    3942            wp_enqueue_style( 'media_categories_metabox_style'); 
    4043        } 
     
    4750     */ 
    4851    function register_media_categories() { 
    49         register_taxonomy_for_object_type('category', 'attachment'); 
    50         add_post_type_support('attachment', 'category'); 
     52        $tax_name = apply_filters('mc_taxonomy', 'category'); 
     53         
     54        register_taxonomy_for_object_type($tax_name, 'attachment'); 
    5155    } 
    5256 
     
    5862 
    5963        require_once('./includes/meta-boxes.php'); 
     64         
     65        $tax_name = apply_filters('mc_taxonomy', 'category'); 
     66        $taxonomy = get_taxonomy($tax_name); 
    6067 
    6168        ob_start(); 
    62  
    63         self::media_categories_meta_box($post, array('taxonomy' => 'category')); 
    64  
     69         
     70            self::media_categories_meta_box($post, array('args' => array ('taxonomy' => $tax_name, 'tax' => $taxonomy))); 
     71             
    6572        $metabox = ob_get_clean(); 
    6673         
    67         $form_fields['category_metabox']['label'] = __('Categories'); 
    68         $form_fields['category_metabox']['helps'] = 'Select a catgegory, use the text fields above to filter'; 
     74        $form_fields['category_metabox']['label'] = $taxonomy->labels->name; 
     75        $form_fields['category_metabox']['helps'] = sprintf(__('Select a %s, use the text fields above to filter'), strtolower($taxonomy->labels->singular_name)); 
    6976        $form_fields['category_metabox']['input'] = 'html'; 
    7077        $form_fields['category_metabox']['html'] = $metabox; 
     
    8592         
    8693        require_once(plugin_dir_path(__FILE__) . 'attachment-walker-category-checklist-class.php'); 
    87            
    88         $defaults = array('taxonomy' => 'category'); 
     94              
     95        $defaults = array('taxonomy' => apply_filters('mc_taxonomy','category')); 
     96         
    8997        if (!isset($box['args']) || !is_array($box['args'])) 
    9098            $args = array(); 
     
    94102        $tax = get_taxonomy($taxonomy); 
    95103        ?> 
     104 
    96105        <div> 
    97             <label class='category-filter' for="category-filter">Search Categories:</label> 
     106            <label class='category-filter' for="category-filter">Search <?php echo $tax->labels->name; ?>:</label> 
    98107            <input id='catsearch' name="category-filter" type='text' /></div> 
    99         <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv"> 
     108            <div id="taxonomy-<?php echo $taxonomy; ?>" class="categorydiv"> 
     109 
    100110            <ul id="<?php echo $taxonomy; ?>-tabs" class="category-tabs"> 
    101111                <li class="tabs"><a href="#<?php echo $taxonomy; ?>-all" tabindex="3"><?php echo $tax->labels->all_items; ?></a></li> 
     
    105115            <div id="<?php echo $taxonomy; ?>-pop" class="tabs-panel" style="display: none;"> 
    106116                <ul id="<?php echo $taxonomy; ?>checklist-pop" class="categorychecklist form-no-clear" > 
    107         <?php $popular_ids = wp_popular_terms_checklist($taxonomy); ?> 
     117                    <?php $popular_ids = wp_popular_terms_checklist($taxonomy); ?> 
    108118                </ul> 
    109119            </div> 
    110120 
    111121            <div id="<?php echo $taxonomy; ?>-all" class="tabs-panel"> 
    112         <?php 
    113         $name = ( $taxonomy == 'category' ) ? 'post_category' : 'tax_input[' . $taxonomy . ']'; 
    114         echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. 
    115         ?> 
     122                <?php 
     123                $name = ( $taxonomy == 'category' ) ? 'post_category' : 'tax_input[' . $taxonomy . ']'; 
     124                echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. 
     125                ?> 
     126                 
    116127                <ul id="<?php echo $taxonomy; ?>checklist" class="list:<?php echo $taxonomy ?> categorychecklist form-no-clear"> 
    117                 <?php $custom_walker = new Attachment_Walker_Category_Checklist ?> 
     128                    <?php $custom_walker = new Attachment_Walker_Category_Checklist ?> 
    118129                    <?php wp_terms_checklist($post->ID, array('taxonomy' => $taxonomy, 'popular_cats' => $popular_ids, 'walker' => $custom_walker)) ?> 
    119130                </ul> 
     
    123134        <?php if (current_user_can($tax->cap->edit_terms)) : ?> 
    124135             
    125                 <div id="<?php echo $taxonomy; ?>-adder" class="wp-hidden-children"> 
    126                     <h4> 
    127                         <a id="<?php echo $taxonomy; ?>-add-toggle" href="#<?php echo $taxonomy; ?>-add" class="hide-if-no-js" tabindex="3"> 
    128             <?php 
    129             /* translators: %s: add new taxonomy label */ 
    130             printf(__('+ %s'), $tax->labels->add_new_item); 
    131             ?> 
    132                         </a> 
    133                     </h4> 
    134                     <p id="<?php echo $taxonomy; ?>-add" class="category-add wp-hidden-child"> 
    135                         <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>"><?php echo $tax->labels->add_new_item; ?></label> 
    136                         <input type="text" name="new<?php echo $taxonomy; ?>" id="new<?php echo $taxonomy; ?>" class="form-required form-input-tip" value="<?php echo esc_attr($tax->labels->new_item_name); ?>" tabindex="3" aria-required="true"/> 
    137                         <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>_parent"> 
    138             <?php echo $tax->labels->parent_item_colon; ?> 
    139                         </label> 
    140                             <?php wp_dropdown_categories(array('taxonomy' => $taxonomy, 'hide_empty' => 0, 'name' => 'new' . $taxonomy . '_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '&mdash; ' . $tax->labels->parent_item . ' &mdash;', 'tab_index' => 3)); ?> 
    141                         <input type="button" id="<?php echo $taxonomy; ?>-add-submit" class="add:<?php echo $taxonomy ?>checklist:<?php echo $taxonomy ?>-add button category-add-sumbit" value="<?php echo esc_attr($tax->labels->add_new_item); ?>" tabindex="3" /> 
    142                         <?php wp_nonce_field('add-' . $taxonomy, '_ajax_nonce-add-' . $taxonomy, false); ?> 
    143                         <span id="<?php echo $taxonomy; ?>-ajax-response"></span> 
    144                     </p> 
    145                 </div> 
     136             <div id="<?php echo $taxonomy; ?>-adder" class="wp-hidden-children"> 
     137                <h4> 
     138                    <a id="<?php echo $taxonomy; ?>-add-toggle" href="#<?php echo $taxonomy; ?>-add" class="hide-if-no-js" tabindex="3"> 
     139                        <?php printf(__('+ %s'), $tax->labels->add_new_item);/* translators: %s: add new taxonomy label */ ?>  
     140                    </a> 
     141                </h4> 
     142                 
     143                <p id="<?php echo $taxonomy; ?>-add" class="category-add wp-hidden-child"> 
     144                     
     145                    <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>"><?php echo $tax->labels->add_new_item; ?></label> 
     146                    <input type="text" name="new<?php echo $taxonomy; ?>" id="new<?php echo $taxonomy; ?>" class="form-required form-input-tip" value="<?php echo esc_attr($tax->labels->new_item_name); ?>" tabindex="3" aria-required="true"/> 
     147 
     148                    <label class="screen-reader-text" for="new<?php echo $taxonomy; ?>_parent"> 
     149                        <?php echo $tax->labels->parent_item_colon; ?> 
     150                    </label> 
     151 
     152                    <?php wp_dropdown_categories(array('taxonomy' => $taxonomy, 'hide_empty' => 0, 'name' => 'new' . $taxonomy . '_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '&mdash; ' . $tax->labels->parent_item . ' &mdash;', 'tab_index' => 3)); ?> 
     153                    <input type="button" id="<?php echo $taxonomy; ?>-add-submit" class="add:<?php echo $taxonomy ?>checklist:<?php echo $taxonomy ?>-add button category-add-sumbit" value="<?php echo esc_attr($tax->labels->add_new_item); ?>" tabindex="3" /> 
     154 
     155                    <?php wp_nonce_field('add-' . $taxonomy, '_ajax_nonce-add-' . $taxonomy, false); ?> 
     156                    <span id="<?php echo $taxonomy; ?>-ajax-response"></span> 
     157                </p> 
     158            </div> 
    146159        <?php endif; ?> 
    147160        </div> 
     
    187200        } 
    188201 
     202        $mc_tax = apply_filters('mc_taxonomy', 'category'); 
    189203        extract(shortcode_atts(array( 
    190204            'order'      => 'ASC', 
     
    198212            'include'    => '', 
    199213            'exclude'    => '', 
    200             'category'   => '' 
     214            $mc_tax      => ''    
    201215        ), $attr)); 
    202216         
     
    204218        if ( 'RAND' == $order ) 
    205219            $orderby = 'none'; 
    206  
    207         if( !empty($category) ){  
    208             if(!is_numeric($category)) 
    209                 $category = get_category_by_slug($category)->term_id; 
    210  
     220                 
     221        if( !empty($$mc_tax) ){  
     222    
     223            $term = ${$mc_tax}; 
     224            $term_field = (is_numeric($term)) ? 'id' : 'slug'; 
     225               
    211226            if(!isset($attr['id'])) 
    212227                $id = ''; 
     
    215230        if ( !empty($include) ) { 
    216231            $include = preg_replace( '/[^0-9,]+/', '', $include ); 
    217             $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'category' => $category) ); 
     232            $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'tax_query' => array(array('taxonomy' => $mc_tax, 'field' => $term_field, 'terms' => $term))) ); 
    218233 
    219234            $attachments = array(); 
     
    223238        } elseif ( !empty($exclude) ) { 
    224239            $exclude = preg_replace( '/[^0-9,]+/', '', $exclude ); 
    225             $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'category' => $category) ); 
     240            $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'tax_query' => array(array('taxonomy' => $mc_tax, 'field' => $term_field, 'terms' => $term))) ); 
    226241        } else { 
    227             $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'category' => $category) ); 
     242            $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'tax_query' => array(array('taxonomy' => $mc_tax, 'field' => $term_field, 'terms' => $term))) ); 
    228243        } 
    229244 
  • media-categories-2/trunk/readme.txt

    r538292 r541444  
    22Contributors: eddiemoya 
    33Donate link: http://eddiemoya.com 
    4 Tags: 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 
     4Tags: 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 
    66Tested up to: 3.3.1 
    7 Stable tag: 1.2 
     7Stable tag: 1.3 
     8License: GPLv2 or later 
     9License URI: http://www.gnu.org/licenses/gpl-2.0.html 
    810 
    911Easily assign categories to media with a clean, simple, and searchable category meta box. Then use the gallery shortcode to display category galleries 
     
    1618[download his plugin here](http://wordpress.org/extend/plugins/searchable-categories/) 
    1719 
    18 NEW! 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. 
     20 
     21= 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 
     23* 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.  
     24 
     25 
     26== Taxonomy Filter Usage: 'mc_taxonomy'  == 
     27 
     28Since version 1.3, the Media Categories plugin includes a filter allowing developers to modify the taxonomy being used.  
     29Changing the taxonomy will automatically change all the labels used around the metabox, and change the way the Gallery Shortcode 
     30works so that it accommodates whatever taxonomy has been chosen. 
     31 
     32The tag for this filter is `'mc_taxonomy'`, and usage could not be simpler. 
     33 
     34` 
     35add_filter('mc_taxonomy', 'mc_filter_taxonomy'); 
     36function mc_filter_taxonomy(){ 
     37    return 'post_tag'; 
     38} 
     39` 
     40The above code will swap out all references to 'category' with appropriate (properly pluralized) references to the 'post_tag' taxonomy. 
     41 
     42It will also change the way the Gallery Shortcode works to use your chosen taxonomy. 
     43 
     44= Important (potential gotchas) = 
     45* The `category` parameter for the Gallery Shortcode will be changed by using this filter, so that instead of `category` is will by `your_taxonomy`. In the case above with tags, 
     46you would write a shortcode as such. `[gallery post_tag="my-tag"]` OR `[gallery post_tag="43"]`. 
     47* If using a Custom Taxonomy with this plugin, be sure to assign values to the labels for proper pluralization and context 
    1948 
    2049 
    2150== Shortcode Usage == 
     51 
     52= Normal Shortcode Usage = 
    2253 
    2354This plugin takes advantage of the existing `[gallery]` shortcode for showing images by adding the `'category'` parameter.  
     
    4273For more information on using the built-in [gallery shortcode checkout the codex page](http://codex.wordpress.org/Gallery_Shortcode). 
    4374 
     75 
     76 
     77= Other Taxonomy Shortcode Usage = 
     78 
     79If a developer implementing this plugin has made use of the `mc_taxonomy` filter to modify which taxonomy 
     80this plugin uses for attachments, then the name of that particular taxonomy will need to be used in place of `category`  
     81as the shortcode parameter. For example, if you applied 'Post Tags' to your images then users should use the `post_tag` parameter 
     82in the Gallery Shortcode. 
     83 
     84`[gallery post_tag="my-tag-slug"] 
     85OR 
     86[gallery post_tag="12"]` 
     87 
    4488== Related Plugins == 
    4589 
    46 As stated in the description, the search functionality in this plugin is taken from Jason Corradino's  
    47 [Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin. While I do 
    48 not employ the plugin directly, the javascript used for filtering is in fact derived with consent from  
    49 that plugin. To enable this feature on all you category metabox, the  
    50 [Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin 
    51  
    52 = TL;DR = 
    5390Checkout this great plugin for Searchable Categories by Jason Corradino, whose javascript I use in this plugin.  
    54 I believe this very simple functionality should be a part of the standard categories metabox in core. 
     91I believe this very simple functionality should be a part of the standard categories metabox in core.  
     92While I do not employ the plugin directly, the javascript used for filtering/searching is in fact derived with  
     93consent, and a few modifications from that plugin. To enable this feature on all you category metabox, the  
     94[Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) plugin. 
    5595 
    5696* [Searchable Categories](http://wordpress.org/extend/plugins/searchable-categories/) by Jason Corradino 
     
    70110== Changelog == 
    71111 
     112= 1.3 = 
     113* Added a filter to allow developers to change the taxonomy being used for their media. 
     114* Modified the Gallery Shortcode functionality to work with any chosen taxonomy. 
     115 
    72116= 1.2 = 
    73 * Added 'category' parameter to [gallery] shortcode. 
     117* Added `'category'` parameter to `[gallery]` shortcode. 
    74118* Modified the Searchable Categories script to make the search field case insensitive. 
    75119* Fixed styling problem on Media Library modal windows - the filter and styling were not working. 
    76120 
    77121= 1.1 =  
    78 * Changed jQuery to use .live() rather than .on() for compatability with WordPress earlier than 3.3 - jQuery 1.7 was only added in v3.3 
     122* Changed jQuery to use `.live()` rather than `.on()` for compatability with WordPress earlier than 3.3 - jQuery 1.7 was only added in v3.3 
    79123* Removed superfluous file which was accidentally included from a different plugin of mine. Would cause fatal errors if both plugins were turned on at the same time. 
    80124 
Note: See TracChangeset for help on using the changeset viewer.