WordPress.org

Plugin Directory

Changeset 549552


Ignore:
Timestamp:
05/27/12 17:27:43 (2 years ago)
Author:
eddiemoya
Message:

workaround for http://core.trac.wordpress.org/ticket/20765

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

Legend:

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

    r541444 r549552  
    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 
     5Version: 1.3.1 
    66Author: Eddie Moya 
    77Author URL: http://eddiemoya.com 
     
    2121        add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_media_categories_styles') ); 
    2222        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); 
    2324         
    2425    } 
     
    7172             
    7273        $metabox = ob_get_clean(); 
    73          
     74 
    7475        $form_fields['category_metabox']['label'] = $taxonomy->labels->name; 
    7576        $form_fields['category_metabox']['helps'] = sprintf(__('Select a %s, use the text fields above to filter'), strtolower($taxonomy->labels->singular_name)); 
     
    312313        return $output; 
    313314    } 
     315     
     316    /** 
     317     * This function serves to work around the problem explained in trac ticket 20765 and reported 
     318     * to me in the plugin directory support forum on WordPress.org. 
     319     *  
     320     * It is an exact duplication of code the `get_attachment_fields_to_edit()` function, 
     321     * and its only purpose is to change the output of terms in attachments so that they used term slugs 
     322     * rather than names. 
     323     *  
     324     * @linkhttp://core.trac.wordpress.org/ticket/20765 
     325     * @link http://wordpress.org/support/topic/media-categories-2-not-saving-correctly-when-two-categories-with-same-name 
     326     * @see /wp-admin/includes/media.php:get_attachemt_fields_to_edit() 
     327     *  
     328     * @param type $form_fields 
     329     * @param type $post 
     330     * @return type  
     331     */ 
     332    function get_attachment_fields_to_edit($form_fields, $post) { 
     333 
     334        foreach (get_attachment_taxonomies($post) as $taxonomy) { 
     335            $t = (array) get_taxonomy($taxonomy); 
     336            if (!$t['public']) 
     337                continue; 
     338            if (empty($t['label'])) 
     339                $t['label'] = $taxonomy; 
     340            if (empty($t['args'])) 
     341                $t['args'] = array(); 
     342 
     343            $terms = get_object_term_cache($post->ID, $taxonomy); 
     344            if (empty($terms)) 
     345                $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']); 
     346 
     347            $values = array(); 
     348 
     349            foreach ($terms as $term) 
     350                $values[] = $term->slug; 
     351            $t['value'] = join(', ', $values); 
     352 
     353            $form_fields[$taxonomy] = $t; 
     354        } 
     355 
     356        return $form_fields; 
     357    } 
    314358} 
    315359 
  • media-categories-2/tags/1.3.1/readme.txt

    r541444 r549552  
    55Requires at least: 3.0 
    66Tested up to: 3.3.1 
    7 Stable tag: 1.3 
     7Stable tag: 1.3.1 
    88License: GPLv2 or later 
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html 
     
    110110== Changelog == 
    111111 
     112= 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. 
     114* Relevant [Trac Ticket](http://core.trac.wordpress.org/ticket/20765) 
     115 
    112116= 1.3 = 
    113117* Added a filter to allow developers to change the taxonomy being used for their media. 
     
    127131 
    128132== Upgrade Notice == 
    129 * For compatibility with WordPress versions earlier than 3.3, upgrade to version 1.1 of this plugin or later.  
     133 
     134= 1.3.1 = 
     135Bug fix (workaround): Taxonomy terms with the same name were causing conflicts - see related [trac ticket](http://core.trac.wordpress.org/ticket/20765) 
     136 
     137= 1.1 = 
     138For compatibility with WordPress versions earlier than 3.3, upgrade to version 1.1 of this plugin or later.  
  • media-categories-2/trunk/media-categories.php

    r541444 r549552  
    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 
     5Version: 1.3.1 
    66Author: Eddie Moya 
    77Author URL: http://eddiemoya.com 
     
    2121        add_action('admin_enqueue_scripts', array(__CLASS__, 'enqueue_media_categories_styles') ); 
    2222        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); 
    2324         
    2425    } 
     
    7172             
    7273        $metabox = ob_get_clean(); 
    73          
     74 
    7475        $form_fields['category_metabox']['label'] = $taxonomy->labels->name; 
    7576        $form_fields['category_metabox']['helps'] = sprintf(__('Select a %s, use the text fields above to filter'), strtolower($taxonomy->labels->singular_name)); 
     
    312313        return $output; 
    313314    } 
     315     
     316    /** 
     317     * This function serves to work around the problem explained in trac ticket 20765 and reported 
     318     * to me in the plugin directory support forum on WordPress.org. 
     319     *  
     320     * It is an exact duplication of code the `get_attachment_fields_to_edit()` function, 
     321     * and its only purpose is to change the output of terms in attachments so that they used term slugs 
     322     * rather than names. 
     323     *  
     324     * @linkhttp://core.trac.wordpress.org/ticket/20765 
     325     * @link http://wordpress.org/support/topic/media-categories-2-not-saving-correctly-when-two-categories-with-same-name 
     326     * @see /wp-admin/includes/media.php:get_attachemt_fields_to_edit() 
     327     *  
     328     * @param type $form_fields 
     329     * @param type $post 
     330     * @return type  
     331     */ 
     332    function get_attachment_fields_to_edit($form_fields, $post) { 
     333 
     334        foreach (get_attachment_taxonomies($post) as $taxonomy) { 
     335            $t = (array) get_taxonomy($taxonomy); 
     336            if (!$t['public']) 
     337                continue; 
     338            if (empty($t['label'])) 
     339                $t['label'] = $taxonomy; 
     340            if (empty($t['args'])) 
     341                $t['args'] = array(); 
     342 
     343            $terms = get_object_term_cache($post->ID, $taxonomy); 
     344            if (empty($terms)) 
     345                $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']); 
     346 
     347            $values = array(); 
     348 
     349            foreach ($terms as $term) 
     350                $values[] = $term->slug; 
     351            $t['value'] = join(', ', $values); 
     352 
     353            $form_fields[$taxonomy] = $t; 
     354        } 
     355 
     356        return $form_fields; 
     357    } 
    314358} 
    315359 
  • media-categories-2/trunk/readme.txt

    r541444 r549552  
    55Requires at least: 3.0 
    66Tested up to: 3.3.1 
    7 Stable tag: 1.3 
     7Stable tag: 1.3.1 
    88License: GPLv2 or later 
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html 
     
    110110== Changelog == 
    111111 
     112= 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. 
     114* Relevant [Trac Ticket](http://core.trac.wordpress.org/ticket/20765) 
     115 
    112116= 1.3 = 
    113117* Added a filter to allow developers to change the taxonomy being used for their media. 
     
    127131 
    128132== Upgrade Notice == 
    129 * For compatibility with WordPress versions earlier than 3.3, upgrade to version 1.1 of this plugin or later.  
     133 
     134= 1.3.1 = 
     135Bug fix (workaround): Taxonomy terms with the same name were causing conflicts - see related [trac ticket](http://core.trac.wordpress.org/ticket/20765) 
     136 
     137= 1.1 = 
     138For compatibility with WordPress versions earlier than 3.3, upgrade to version 1.1 of this plugin or later.  
Note: See TracChangeset for help on using the changeset viewer.