WordPress.org

Plugin Directory

Changeset 574810


Ignore:
Timestamp:
07/19/12 19:11:32 (2 years ago)
Author:
Omicron7
Message:

Version 1.2

Location:
advanced-custom-fields-taxonomy-field-add-on/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • advanced-custom-fields-taxonomy-field-add-on/trunk/README.md

    r525455 r574810  
    1111and activated. 
    1212 
    13 The taxonomy field provides a dropdown (select or multi-select) of taxonomy terms (categories, tags, custom taxonomies...) 
     13The taxonomy field provides a select, multi-select or checkboxes of taxonomy terms (categories, tags, custom taxonomies...) 
    1414and the ability to map the selected terms to the post. The post type must support the taxonomy for the mapping to work. 
    15 The taxonomy field currently does not provide the ability to add new terms to a taxonomy. The `get_value()` api returns 
    16 a list of taxonomy links similar to WordPress `get_the_term_list()`. 
     15The taxonomy field currently does not provide the ability to add new terms to a taxonomy. The return type of the `get_value()` 
     16api can be changed in the field settings. 
    1717 
    1818### Source Repository on GitHub 
     
    4747---- 
    4848* Add ability to add new terms to a taxonomy 
    49 * Add more term selection methods (checkboxes, token input). 
     49* Add more term selection methods (token input). 
  • advanced-custom-fields-taxonomy-field-add-on/trunk/languages/acf-taxonomy-field.pot

    r502765 r574810  
    55"Project-Id-Version:  \n" 
    66"Report-Msgid-Bugs-To: http://wordpress.org/tag/acf-taxonomy-field\n" 
    7 "POT-Creation-Date: 2012-02-08 20:53:11+00:00\n" 
     7"POT-Creation-Date: 2012-07-19 18:48:27+00:00\n" 
    88"MIME-Version: 1.0\n" 
    99"Content-Type: text/plain; charset=UTF-8\n" 
     
    1313"Language-Team: LANGUAGE <LL@li.org>\n" 
    1414 
    15 #: taxonomy-field.php:109 taxonomy-field.php:207 
     15#: taxonomy-field.php:110 taxonomy-field.php:232 
    1616msgid "Taxonomy" 
    1717msgstr "" 
    1818 
    19 #: taxonomy-field.php:208 
     19#: taxonomy-field.php:233 
    2020msgid "Select the taxonomy to display." 
    2121msgstr "" 
    2222 
    23 #: taxonomy-field.php:223 
     23#: taxonomy-field.php:248 
    2424msgid "Input Method" 
    2525msgstr "" 
    2626 
    27 #: taxonomy-field.php:244 
     27#: taxonomy-field.php:259 
     28msgid "Select" 
     29msgstr "" 
     30 
     31#: taxonomy-field.php:260 
     32msgid "Multi-Select" 
     33msgstr "" 
     34 
     35#: taxonomy-field.php:261 
     36msgid "Hierarchical Checkboxes" 
     37msgstr "" 
     38 
     39#: taxonomy-field.php:270 
    2840msgid "Set Post Terms" 
    2941msgstr "" 
    3042 
    31 #: taxonomy-field.php:245 
     43#: taxonomy-field.php:271 
    3244msgid "" 
    3345"Add the selected term(s) to the post. The current post must support the " 
     
    3547msgstr "" 
    3648 
    37 #: taxonomy-field.php:260 
     49#: taxonomy-field.php:285 
     50msgid "Return Value" 
     51msgstr "" 
     52 
     53#: taxonomy-field.php:286 
     54msgid "Choose the field value type returned by API calls." 
     55msgstr "" 
     56 
     57#: taxonomy-field.php:296 
     58msgid "Links" 
     59msgstr "" 
     60 
     61#: taxonomy-field.php:297 
     62msgid "Objects" 
     63msgstr "" 
     64 
     65#: taxonomy-field.php:298 
     66msgid "Term IDs" 
     67msgstr "" 
     68 
     69#: taxonomy-field.php:307 
    3870msgid "Add New Terms" 
    3971msgstr "" 
    4072 
    41 #: taxonomy-field.php:261 
     73#: taxonomy-field.php:308 
    4274msgid "Add any new terms to the selected taxonomy." 
    4375msgstr "" 
    4476 
    45 #: taxonomy-field.php:276 
     77#: taxonomy-field.php:323 
    4678msgid "Multi-Select Size" 
    4779msgstr "" 
    4880 
    49 #: taxonomy-field.php:277 
     81#: taxonomy-field.php:324 
    5082msgid "The number of terms to show at once in a multi-select." 
    5183msgstr "" 
  • advanced-custom-fields-taxonomy-field-add-on/trunk/readme.txt

    r542943 r574810  
    33Tags: acf, acf add-on, taxonomy, custom field, taxonomy field 
    44Requires at least: 3.0 
    5 Tested up to: 3.3.2 
    6 Stable tag: 1.1.1 
     5Tested up to: 3.4.1 
     6Stable tag: 1.2 
    77 
    88Adds a Taxonomy Field to Advanced Custom Fields. Select one or more taxonomy terms and assign them to the post. 
     
    1414and activated. 
    1515 
    16 The taxonomy field provides a dropdown (select or multi-select) of taxonomy terms (categories, tags, custom taxonomies...) 
     16The taxonomy field provides a select, multi-select or checkboxes of taxonomy terms (categories, tags, custom taxonomies...) 
    1717and the ability to map the selected terms to the post. The post type must support the taxonomy for the mapping to work. 
    18 The taxonomy field currently does not provide the ability to add new terms to a taxonomy. The `get_value()` api returns 
    19 a list of taxonomy links similar to WordPress `get_the_term_list()`. 
     18The taxonomy field currently does not provide the ability to add new terms to a taxonomy. The return type of the `get_value()` 
     19api can be changed in the field settings. 
    2020 
    2121= Source Repository on GitHub = 
     
    5757== Changelog == 
    5858 
     59= 1.2 = 
     60* Fixed issue Taxonomy Field not working in a Repeater Field. Props markSal 
     61* Fixed a bug which caused wrong options to be shown in the metabox. Props FunkyM 
     62* Fixed an additional issue with URL generation on Windows hosts. 
     63* Added hierarchical checkboxes input type similar to builting WordPress taxonomy chooser. Props FunkyM 
     64* Added option to choose link, object or ID as return value for field API calls. Props FunkyM 
     65* Updated localizations 
     66 
    5967= 1.1.1 = 
    6068* Fixed issue with path and URI generation on Windows hosts. 
  • advanced-custom-fields-taxonomy-field-add-on/trunk/taxonomy-field.php

    r542943 r574810  
    66* Author:      Brian Zoetewey 
    77* Author URI:  https://github.com/GCX 
    8 * Version:     1.1.1 
     8* Version:     1.2 
    99* Text Domain: acf-taxonomy-field 
    1010* Domain Path: /languages/ 
     
    4949 *  
    5050 * @author Brian Zoetewey <brian.zoetewey@ccci.org> 
    51  * @version 1.1.1 
     51 * @version 1.2 
    5252 */ 
    5353class ACF_Taxonomy_Field extends acf_Field { 
     
    9696        //Build the base relative uri by searching backwards until we encounter the wordpress ABSPATH 
    9797        //This may not work if the $base_dir contains a symlink outside of the WordPress ABSPATH 
    98         $root = array_pop( explode( DIRECTORY_SEPARATOR, rtrim( realpath( ABSPATH ), DIRECTORY_SEPARATOR ) ) ); 
     98        $root = array_pop( explode( DIRECTORY_SEPARATOR, rtrim( realpath( ABSPATH ), '/' ) ) ); 
    9999        $path_parts = explode( DIRECTORY_SEPARATOR, $this->base_dir ); 
    100100        $parts = array(); 
     
    157157     */ 
    158158    private function set_field_defaults( &$field ) { 
    159         $field[ 'taxonomy' ]        = ( array_key_exists( 'taxonomy', $field ) && isset( $field[ 'taxonomy' ] ) ) ? $field[ 'taxonomy' ] : 'category'; 
    160         $field[ 'input_type' ]      = ( array_key_exists( 'input_type', $field ) && isset( $field[ 'input_type' ] ) ) ? $field[ 'input_type' ] : 'select'; 
    161         $field[ 'input_size' ]      = ( array_key_exists( 'input_size', $field ) && isset( $field[ 'input_size' ] ) ) ? (int) $field[ 'input_size' ] : 5; 
    162 //      $field[ 'allow_new_terms' ] = ( array_key_exists( 'allow_new_terms', $field ) && isset( $field[ 'allow_new_terms' ] ) ) ? (int) $field[ 'allow_new_terms' ] : 0; //false 
    163         $field[ 'set_post_terms' ]  = ( array_key_exists( 'set_post_terms', $field ) && isset( $field[ 'set_post_terms' ] ) ) ? (int) $field[ 'set_post_terms' ] : 1; //true 
     159        $field[ 'taxonomy' ]          = ( array_key_exists( 'taxonomy', $field ) && isset( $field[ 'taxonomy' ] ) ) ? $field[ 'taxonomy' ] : 'category'; 
     160        $field[ 'input_type' ]        = ( array_key_exists( 'input_type', $field ) && isset( $field[ 'input_type' ] ) ) ? $field[ 'input_type' ] : 'select'; 
     161        $field[ 'input_size' ]        = ( array_key_exists( 'input_size', $field ) && isset( $field[ 'input_size' ] ) ) ? (int) $field[ 'input_size' ] : 5; 
     162//      $field[ 'allow_new_terms' ]   = ( array_key_exists( 'allow_new_terms', $field ) && isset( $field[ 'allow_new_terms' ] ) ) ? (int) $field[ 'allow_new_terms' ] : 0; //false 
     163        $field[ 'set_post_terms' ]    = ( array_key_exists( 'set_post_terms', $field ) && isset( $field[ 'set_post_terms' ] ) ) ? (int) $field[ 'set_post_terms' ] : 1; //true 
     164        $field[ 'return_value_type' ] = isset( $field[ 'return_value_type' ] ) ? $field[ 'return_value_type' ] : 'link'; 
    164165        return $field; 
    165166    } 
     
    174175         
    175176        $terms = get_terms( $field['taxonomy'], array( 'hide_empty' => false ) ); 
    176         $value = $field[ 'value' ]; 
     177        $value = is_array( $field[ 'value' ] ) ? $field[ 'value' ] : array(); 
    177178 
    178179        if( in_array( $field[ 'input_type' ], array( 'select', 'multiselect' ) ) ) : 
     
    180181            <select name="<?php echo $field[ 'name' ]; ?>[]" id="<?php echo $field[ 'name' ]; ?>" class="<?php echo $field[ 'class' ]; ?>" <?php echo ( $field[ 'input_type' ] == 'multiselect' ) ? 'multiple="multiple" size="' . $field[ 'input_size' ] . '"' : ''; ?>> 
    181182                <?php foreach( $terms as $term ) : ?> 
    182                     <option value="<?php echo $term->term_id; ?>" <?php selected( in_array( (int) $term->term_taxonomy_id, $value ) ); ?>><?php echo $term->name; ?></option> 
     183                    <option value="<?php echo $term->term_id; ?>" <?php selected( in_array( (int) $term->term_id, $value ) ); ?>><?php echo $term->name; ?></option> 
    183184                <?php endforeach; ?> 
    184185            </select> 
     186        <?php 
     187        elseif ( in_array( $field[ 'input_type'], array( 'hierarchical' ) ) ): 
     188        $id = $field['name'] . '-' . $field['taxonomy']; 
     189        ?> 
     190            <div id="taxonomy-<?php echo $id; ?>" class="categorydiv"> 
     191                <div id="<?php echo $id; ?>-all" class="tabs-panel"> 
     192                    <?php 
     193                    $name = ( $field['taxonomy'] == 'category' ) ? 'post_category' : $field['name']; 
     194                    echo "<input type='hidden' name='{$name}' value='' />"; 
     195                    ?> 
     196                    <ul id="<?php echo $id; ?>checklist" class="list:<?php echo $field['taxonomy']; ?> categorychecklist form-no-clear"> 
     197                        <?php  
     198                            wp_terms_checklist( 0, array( 
     199                                'name'          => $name, 
     200                                'checked_ontop' => false, 
     201                                'selected_cats' => $value, 
     202                                'taxonomy'      => $field['taxonomy'], 
     203                                'walker'        => new ACF_Walker_Taxonomy_Field_Checklist($field) 
     204                            ) ); 
     205                        ?> 
     206                    </ul> 
     207                </div> 
     208            </div> 
    185209        <?php 
    186210        endif; 
     
    233257                            'class'   => 'taxonomy_input_type', 
    234258                            'choices' => array( 
    235                                 'select'      => 'Select', 
    236                                 'multiselect' => 'Multi-Select', 
     259                                'select'      => __( 'Select', $this->l10n_domain ), 
     260                                'multiselect' => __( 'Multi-Select', $this->l10n_domain ), 
     261                                'hierarchical' => __( 'Hierarchical Checkboxes', $this->l10n_domain ), 
    237262                                //'token'       => 'Input Tokenizer', 
    238263                            ), 
     
    253278                            'value' => $field[ 'set_post_terms' ], 
    254279                        ) ); 
     280                    ?> 
     281                </td> 
     282            </tr> 
     283            <tr class="field_option field_option_<?php echo $this->name; ?>"> 
     284                <td class="label"> 
     285                    <label><?php _e( 'Return Value', $this->l10n_domain ); ?></label> 
     286                    <p class="description"><?php _e( 'Choose the field value type returned by API calls.', $this->l10n_domain ); ?></p> 
     287                </td> 
     288                <td> 
     289                    <?php  
     290                    $this->parent->create_field(array( 
     291                        'type'    => 'radio', 
     292                        'name'    => 'fields['.$key.'][return_value_type]', 
     293                        'value'   => $field[ 'return_value_type' ], 
     294                        'layout'  => 'horizontal', 
     295                        'choices' => array( 
     296                            'link'   => __( 'Links', $this->l10n_domain), 
     297                            'object' => __( 'Objects', $this->l10n_domain ), 
     298                            'id'     => __( 'Term IDs', $this->l10n_domain ), 
     299                        ) 
     300                    ) ); 
    255301                    ?> 
    256302                </td> 
     
    336382    public function get_value_for_api( $post_id, $field ) { 
    337383        $this->set_field_defaults( $field ); 
     384         
     385        $terms = array(); 
     386         
    338387        //If terms are set on the post, we can let WordPress create the list 
    339388        if( $field[ 'set_post_terms' ] ) { 
    340             return get_the_term_list( $post_id, $field[ 'taxonomy' ] ); 
     389            switch ( $field[ 'return_value_type' ] ) { 
     390                case 'id': 
     391                    $the_terms = get_the_terms( $post_id, $field[ 'taxonomy' ] ); 
     392                    foreach ($the_terms as $term) { 
     393                        $terms[] = $term->term_id; 
     394                    } 
     395                    return $terms; 
     396                case 'object': 
     397                    return get_the_terms( $post_id, $field[ 'taxonomy' ] ); 
     398                case 'link': 
     399                default: 
     400                    return get_the_term_list( $post_id, $field[ 'taxonomy' ] ); 
     401            } 
    341402        } 
    342403         
     
    346407            return false; 
    347408         
    348         $term_links = array(); 
    349409        foreach( $value as $term_id ) { 
    350410            $term_id = intval( $term_id ); 
     
    352412            $link = get_term_link( $term, $field[ 'taxonomy' ] ); 
    353413            if( !is_wp_error( $link ) ) 
    354                 $term_links[] = '<a href="' . $link . '" rel="tag">' . $term->name . '</a>'; 
    355         } 
    356         if( empty( $term_links ) ) 
     414                switch ( $field[ 'return_value_type' ] ) { 
     415                    case 'id': 
     416                        $terms[] = $term_id; 
     417                    case 'object': 
     418                        $terms[] = $term; 
     419                        break; 
     420                    case 'link': 
     421                    default: 
     422                        $terms[] = '<a href="' . $link . '" rel="tag">' . $term->name . '</a>'; 
     423                        break; 
     424                } 
     425                 
     426        } 
     427        if( empty( $terms ) ) 
    357428            return false; 
    358429         
    359         //Allow plugins to modify 
    360         $term_links = apply_filters( "term_links-{$field[ 'taxonomy' ]}", $term_links ); 
    361          
    362         return join( '', $term_links ); 
     430        switch ( $field[ 'return_value_type' ] ) { 
     431            case 'id': 
     432            case 'object': 
     433                return $terms; 
     434            case 'link': 
     435            default: 
     436                //Allow plugins to modify 
     437                $terms = apply_filters( "term_links-{$field[ 'taxonomy' ]}", $terms ); 
     438                return join( '', $terms ); 
     439        } 
    363440    } 
    364441} 
    365442 
    366443endif; //class_exists 'ACF_Taxonomy_Field' 
     444 
     445if( !class_exists( 'ACF_Walker_Taxonomy_Field_Checklist' ) ) : 
     446 
     447class ACF_Walker_Taxonomy_Field_Checklist extends Walker { 
     448    var $tree_type = 'category'; 
     449    var $db_fields = array ( 'parent' => 'parent', 'id' => 'term_id' ); 
     450 
     451    function __construct( $field ) { 
     452        $this->field = $field; 
     453    } 
     454 
     455    function start_lvl( &$output, $depth = 0, $args = array() ) { 
     456        $indent = str_repeat("\t", $depth); 
     457        $output .= "$indent<ul class='children'>\n"; 
     458    } 
     459 
     460    function end_lvl( &$output, $depth = 0, $args = array() ) { 
     461        $indent = str_repeat("\t", $depth); 
     462        $output .= "$indent</ul>\n"; 
     463    } 
     464 
     465    function start_el( &$output, $category, $depth, $args, $id = 0 ) { 
     466        extract($args); 
     467 
     468        if ( empty( $taxonomy ) ) 
     469            $taxonomy = 'category'; 
     470 
     471        if ( $taxonomy == 'category' ) 
     472            $name = 'post_category'; 
     473        else 
     474            $name = $this->field['name']; 
     475 
     476        $class = in_array( $category->term_id, $popular_cats ) ? ' class="popular-category"' : ''; 
     477        $output .= "\n<li id='{$taxonomy}-{$category->term_id}-{$name}'$class>" . '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '-' . $name . '"' . checked( in_array( $category->term_id, $selected_cats ), true, false ) . disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . esc_html( apply_filters( 'the_category', $category->name ) ) . '</label>'; 
     478    } 
     479 
     480    function end_el( &$output, $category, $depth = 0, $args = array() ) { 
     481        $output .= "</li>\n"; 
     482    } 
     483} 
     484 
     485endif; //class_exists 'ACF_Walker_Taxonomy_Field_Checklist' 
    367486 
    368487if( !class_exists( 'ACF_Taxonomy_Field_Helper' ) ) : 
Note: See TracChangeset for help on using the changeset viewer.