WordPress.org

Make WordPress Core

Changeset 12818


Ignore:
Timestamp:
01/24/10 11:00:27 (4 years ago)
Author:
dd32
Message:

Merge Categories/Hierarchical taxonomies into edit-tags.php. See #11838

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r12798 r12818  
    611611    } 
    612612 
    613     echo _tag_row( $tag, '', $taxonomy ); 
     613    $level = 0; 
     614    $tag_full_name = false; 
     615    if ( is_taxonomy_hierarchical($taxonomy) ) { 
     616        $tag_full_name = $tag->name; 
     617        $_tag = $tag; 
     618        while ( $_tag->parent ) { 
     619            $_tag = get_term( $_tag->parent, $taxonomy ); 
     620            $tag_full_name = $_tag->name . ' — ' . $tag_full_name; 
     621            $level++; 
     622        } 
     623        $tag_full_name = esc_attr($tag_full_name);   
     624    } 
     625    echo _tag_row( $tag, $level, $tag_full_name, $taxonomy ); 
    614626    exit; 
    615627    break; 
     
    12111223                    die( __('Tag not updated.') ); 
    12121224 
    1213                 echo _tag_row($tag, '', $taxonomy); 
     1225                echo _tag_row($tag, 0, '', $taxonomy); 
    12141226            } else { 
    12151227                die( __('Tag not updated.') ); 
  • trunk/wp-admin/edit-link-categories.php

    r12736 r12818  
    227227</div><!-- /wrap --> 
    228228 
    229 <?php inline_edit_term_row('edit-link-categories'); ?> 
     229<?php inline_edit_term_row('edit-link-categories', 'link_category'); ?> 
    230230<?php include('admin-footer.php'); ?> 
  • trunk/wp-admin/edit-tag-form.php

    r12712 r12818  
    4040            <th scope="row" valign="top"><label for="slug"><?php _e('Tag slug') ?></label></th> 
    4141            <td><input name="slug" id="slug" type="text" value="<?php if ( isset( $tag->slug ) ) echo esc_attr(apply_filters('editable_slug', $tag->slug)); ?>" size="40" /> 
    42             <p class="description"><?php _e('The &#8220;slug&#8221; is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.'); ?></p></td> 
     42            <p class="description"><?php _e('The &#8220;slug&#8221; is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.'); ?></p></td> 
     43        </tr> 
     44<?php } ?> 
     45<?php if ( is_taxonomy_hierarchical($taxonomy) ) { ?> 
     46        <tr class="form-field"> 
     47            <th scope="row" valign="top"><label for="parent"><?php _e('Category Parent') ?></label></th> 
     48            <td> 
     49                <?php wp_dropdown_categories(array('hide_empty' => 0, 'hide_if_empty' => false, 'name' => 'parent', 'orderby' => 'name', 'taxonomy' => $taxonomy, 'selected' => $tag->parent, 'exclude' => $tag->term_id, 'hierarchical' => true, 'show_option_none' => __('None'))); ?><br /> 
     50                <span class="description"><?php _e('Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.'); ?></span> 
     51            </td> 
    4352        </tr> 
    4453<?php } ?> 
     
    4655            <th scope="row" valign="top"><label for="description"><?php _e('Description') ?></label></th> 
    4756            <td><textarea name="description" id="description" rows="5" cols="50" style="width: 97%;"><?php echo esc_html($tag->description); ?></textarea><br /> 
    48             <span class="description"><?php _e('The description is not prominent by default, however some themes may show it.'); ?></span></td> 
     57            <span class="description"><?php _e('The description is not prominent by default, however some themes may show it.'); ?></span></td> 
    4958        </tr> 
    5059        <?php do_action('edit_tag_form_fields', $tag); ?> 
  • trunk/wp-admin/edit-tags.php

    r12816 r12818  
    4545    $ret = wp_insert_term($_POST['tag-name'], $taxonomy, $_POST); 
    4646    if ( $ret && !is_wp_error( $ret ) ) { 
    47         wp_redirect('edit-tags.php?message=1#addtag'); 
     47        wp_redirect("edit-tags.php?taxonomy=$taxonomy&amp;message=1#addtag"); 
    4848    } else { 
    49         wp_redirect('edit-tags.php?message=4#addtag'); 
     49        wp_redirect("edit-tags.php?taxonomy=$taxonomy&amp;message=4#addtag"); 
    5050    } 
    5151    exit; 
     
    6666    wp_delete_term( $tag_ID, $taxonomy); 
    6767 
    68     $location = 'edit-tags.php'; 
     68    $location = 'edit-tags.php?taxonomy=' . $taxonomy; 
    6969    if ( $referer = wp_get_referer() ) { 
    7070        if ( false !== strpos($referer, 'edit-tags.php') ) 
     
    8989    } 
    9090 
    91     $location = 'edit-tags.php'; 
     91    $location = 'edit-tags.php?taxonomy=' . $taxonomy; 
    9292    if ( $referer = wp_get_referer() ) { 
    9393        if ( false !== strpos($referer, 'edit-tags.php') ) 
     
    121121    $ret = wp_update_term($tag_ID, $taxonomy, $_POST); 
    122122 
    123     $location = 'edit-tags.php'; 
     123    $location = 'edit-tags.php?taxonomy=' . $taxonomy; 
    124124    if ( $referer = wp_get_original_referer() ) { 
    125125        if ( false !== strpos($referer, 'edit-tags.php') ) 
     
    201201$tags_per_page = apply_filters( 'tagsperpage', $tags_per_page ); // Old filter 
    202202 
    203 if ( !empty($_GET['s']) ) 
    204     $total_terms = count( get_terms( $taxonomy, array( 'search' => trim(stripslashes($_GET['s'])), 'number' => 0, 'hide_empty' => 0 ) ) ); 
    205 else 
     203if ( !empty($_GET['s']) ) { 
     204    $searchterms = trim(stripslashes($_GET['s'])); 
     205    $total_terms = count( get_terms( $taxonomy, array( 'search' => $searchterms, 'number' => 0, 'hide_empty' => 0 ) ) ); 
     206} else { 
     207    $searchterms = ''; 
    206208    $total_terms = wp_count_terms($taxonomy); 
     209} 
    207210 
    208211$page_links = paginate_links( array( 
     
    249252<?php 
    250253 
    251 $searchterms = isset( $_GET['s'] ) ? trim( $_GET['s'] ) : ''; 
    252  
    253254$count = tag_rows( $pagenum, $tags_per_page, $searchterms, $taxonomy ); 
    254255?> 
     
    313314</div> 
    314315<?php } ?> 
     316<?php if ( is_taxonomy_hierarchical($taxonomy) ) { ?> 
     317<div class="form-field"> 
     318    <label for="category_parent"><?php _e('Category Parent') ?></label> 
     319    <?php wp_dropdown_categories(array('hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None'))); ?> 
     320    <p><?php _e('Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.'); ?></p> 
     321</div> 
     322<?php } ?> 
    315323<div class="form-field"> 
    316324    <label for="description"><?php _e('Description') ?></label> 
     
    330338</div><!-- /wrap --> 
    331339 
    332 <?php inline_edit_term_row('edit-tags'); ?> 
     340<?php inline_edit_term_row('edit-tags', $taxonomy); ?> 
    333341 
    334342<?php 
  • trunk/wp-admin/includes/taxonomy.php

    r12694 r12818  
    7474    } 
    7575 
    76     if ($post_id) 
     76    if ( $post_id ) 
    7777        wp_set_post_categories($post_id, $cat_ids); 
    7878 
  • trunk/wp-admin/includes/template.php

    r12812 r12818  
    206206 * Outputs the HTML for the hidden table rows used in Categories, Link Caregories and Tags quick edit. 
    207207 * 
    208  * @param string $type "tag", "category" or "link-category" 
     208 * @param string $type "edit-tags", "categoried" or "edit-link-categories" 
     209 * @param string $taxonomy The taxonomy of the row. 
    209210 * @return 
    210211 */ 
    211 function inline_edit_term_row($type) { 
     212function inline_edit_term_row($type, $taxonomy) { 
    212213 
    213214    if ( ! current_user_can( 'manage_categories' ) ) 
    214215        return; 
    215216 
    216     $is_tag = $type == 'edit-tags'; 
    217217    $columns = get_column_headers($type); 
    218218    $hidden = array_intersect( array_keys( $columns ), array_filter( get_hidden_columns($type) ) ); 
     
    237237<?php } ?> 
    238238 
    239 <?php if ( 'category' == $type ) : ?> 
    240  
     239<?php if ( is_taxonomy_hierarchical($taxonomy) ) : ?> 
    241240            <label> 
    242241                <span class="title"><?php _e( 'Parent' ); ?></span> 
    243                 <?php wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => __('None'))); ?> 
     242                <?php wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => 1, 'taxonomy' => $taxonomy, 'show_option_none' => __('None'))); ?> 
    244243            </label> 
    245244 
    246 <?php endif; // $type ?> 
     245<?php endif; // $hierarchical ?> 
    247246 
    248247        </div></fieldset> 
     
    255254        if ( isset( $core_columns[$column_name] ) ) 
    256255            continue; 
    257         do_action( 'quick_edit_custom_box', $column_name, $type ); 
     256        do_action( 'quick_edit_custom_box', $column_name, $type, $taxonomy ); 
    258257    } 
    259258 
     
    262261    <p class="inline-edit-save submit"> 
    263262        <a accesskey="c" href="#inline-edit" title="<?php _e('Cancel'); ?>" class="cancel button-secondary alignleft"><?php _e('Cancel'); ?></a> 
    264         <?php $update_text = ( $is_tag ) ? __( 'Update Tag' ) : __( 'Update Category' ); ?> 
     263        <?php $update_text = ( 'post_tag' == $taxonomy ) ? __( 'Update Tag' ) : __( 'Update Category' ); ?> 
    265264        <a accesskey="s" href="#inline-edit" title="<?php echo esc_attr( $update_text ); ?>" class="save button-primary alignright"><?php echo $update_text; ?></a> 
    266265        <img class="waiting" style="display:none;" src="images/wpspin_light.gif" alt="" /> 
     
    672671 * @return unknown 
    673672 */ 
    674 function _tag_row( $tag, $class = '', $taxonomy = 'post_tag' ) { 
     673function _tag_row( $tag, $level, $class = '', $taxonomy = 'post_tag' ) { 
    675674        $count = number_format_i18n( $tag->count ); 
    676         $tagsel = ($taxonomy == 'post_tag' ? 'tag' : $taxonomy); 
     675        if ( 'post_tag' == $taxonomy )  
     676            $tagsel = 'tag'; 
     677        elseif ( 'category' == $taxonomy ) 
     678            $tagsel = 'category_name'; 
     679        else 
     680            $tagsel = $taxonomy; 
    677681        $count = ( $count > 0 ) ? "<a href='edit.php?$tagsel=$tag->slug'>$count</a>" : $count; 
    678682 
    679         $name = apply_filters( 'term_name', $tag->name ); 
     683        $pad = str_repeat( '&#8212; ', max(0, $level) ); 
     684        $name = apply_filters( 'term_name', $pad . ' ' . $tag->name ); 
    680685        $qe_data = get_term($tag->term_id, $taxonomy, object, 'edit'); 
    681686        $edit_link = "edit-tags.php?action=edit&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id"; 
     
    695700            switch ($column_name) { 
    696701                case 'cb': 
    697                     $out .= '<th scope="row" class="check-column"> <input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" /></th>'; 
     702                    if ( $tag->term_id != get_option('default_' . $taxonomy) ) 
     703                        $out .= '<th scope="row" class="check-column"> <input type="checkbox" name="delete_tags[]" value="' . $tag->term_id . '" /></th>'; 
     704                    else 
     705                        $out .= '<th scope="row" class="check-column">&nbsp;</th>'; 
    698706                    break; 
    699707                case 'name': 
     
    702710                    $actions['edit'] = '<a href="' . $edit_link . '">' . __('Edit') . '</a>'; 
    703711                    $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __('Quick&nbsp;Edit') . '</a>'; 
    704                     $actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url("edit-tags.php?action=delete&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id) . "'>" . __('Delete') . "</a>"; 
     712                    if ( $tag->term_id != get_option('default_' . $taxonomy) ) 
     713                        $actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url("edit-tags.php?action=delete&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id) . "'>" . __('Delete') . "</a>"; 
     714 
    705715                    $actions = apply_filters('tag_row_actions', $actions, $tag); 
     716                    $actions = apply_filters("${taxonomy}_row_actions", $actions, $tag); 
     717 
    706718                    $action_count = count($actions); 
    707719                    $i = 0; 
     
    715727                    $out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">'; 
    716728                    $out .= '<div class="name">' . $qe_data->name . '</div>'; 
    717                     $out .= '<div class="slug">' . apply_filters('editable_slug', $qe_data->slug) . '</div></div></td>'; 
     729                    $out .= '<div class="slug">' . apply_filters('editable_slug', $qe_data->slug) . '</div>'; 
     730                    $out .= '<div class="parent">' . $qe_data->parent . '</div></div></td>'; 
    718731                    break; 
    719732                case 'description': 
     
    759772    $args = array('offset' => $start, 'number' => $pagesize, 'hide_empty' => 0); 
    760773 
    761     if ( !empty( $searchterms ) ) { 
     774    if ( !empty( $searchterms ) ) 
    762775        $args['search'] = $searchterms; 
    763     } 
    764  
    765     $tags = get_terms( $taxonomy, $args ); 
    766776 
    767777    // convert it to table rows 
    768778    $out = ''; 
    769779    $count = 0; 
    770     foreach( $tags as $tag ) 
    771         $out .= _tag_row( $tag, ++$count % 2 ? ' class="alternate"' : '', $taxonomy ); 
     780    if ( is_taxonomy_hierarchical($taxonomy) ) { 
     781        // We'll need the full set of terms then. 
     782        $args['number'] = $args['offset'] = 0; 
     783 
     784        $terms = get_terms( $taxonomy, $args ); 
     785        if ( !empty( $searchterms ) ) // Ignore children on searches. 
     786            $children = array(); 
     787        else 
     788            $children = _get_term_hierarchy($taxonomy); 
     789 
     790        // Some funky recursion to get the job done is contained within, Skip it for non-hierarchical taxonomies for performance sake 
     791        $out .= _term_rows($taxonomy, $terms, $children, $page, $pagesize, $count); 
     792    } else { 
     793        $terms = get_terms( $taxonomy, $args ); 
     794        foreach( $terms as $term ) 
     795            $out .= _tag_row( $term, 0, ++$count % 2 ? ' class="alternate"' : '', $taxonomy ); 
     796    } 
    772797 
    773798    // filter and send to screen 
    774799    echo $out; 
    775800    return $count; 
     801} 
     802 
     803function _term_rows( $taxonomy, $terms, &$children, $page = 1, $per_page = 20, &$count, $parent = 0, $level = 0 ) { 
     804 
     805    $start = ($page - 1) * $per_page; 
     806    $end = $start + $per_page; 
     807 
     808    $output = ''; 
     809    foreach ( $terms as $key => $term ) { 
     810 
     811        if ( $count >= $end ) 
     812            break; 
     813 
     814        if ( $term->parent != $parent && empty($_GET['s']) ) 
     815            continue; 
     816 
     817        // If the page starts in a subtree, print the parents. 
     818        if ( $count == $start && $term->parent > 0 && empty($_GET['s']) ) { 
     819            $my_parents = $parent_ids = array(); 
     820            $p = $term->parent; 
     821            while ( $p ) { 
     822                $my_parent = get_term( $p, $taxonomy ); 
     823                $my_parents[] = $my_parent; 
     824                $p = $my_parent->parent; 
     825                if ( in_array($p, $parent_ids) ) // Prevent parent loops. 
     826                    break; 
     827                $parent_ids[] = $p; 
     828            } 
     829            unset($parent_ids); 
     830 
     831            $num_parents = count($my_parents); 
     832            $count -= $num_parents; // Do not include parents in the per-page count, This is due to paging issues with unknown numbers of rows. 
     833            while ( $my_parent = array_pop($my_parents) ) { 
     834                $output .=  "\t" . _tag_row( $my_parent, $level - $num_parents, ++$count % 2 ? ' class="alternate"' : '', $taxonomy ); 
     835                $num_parents--; 
     836            } 
     837        } 
     838 
     839        if ( $count >= $start ) 
     840            $output .= "\t" . _tag_row( $term, $level, ++$count % 2 ? ' class="alternate"' : '', $taxonomy ); 
     841        else 
     842            ++$count; 
     843 
     844        unset($terms[$key]); 
     845 
     846        if ( isset($children[$term->term_id]) ) 
     847            $output .= _term_rows( $taxonomy, $terms, $children, $page, $per_page, $count, $term->term_id, $level + 1 ); 
     848    } 
     849 
     850    return $output; 
    776851} 
    777852 
  • trunk/wp-admin/js/tags.dev.js

    r11676 r12818  
    3535            } else { 
    3636                $('#ajax-response').empty(); 
    37                 $('#the-list').prepend(r); 
     37                var parent = form.find('select#parent').val(); 
     38                if ( parent > 0 && $('#tag-' + parent ).length > 0 ) // If the parent exists on this page, insert it below. Else insert it at the top of the list. 
     39                    $('#the-list #tag-' + parent).after(r); 
     40                else 
     41                    $('#the-list').prepend(r); 
    3842                $('input[type="text"]:visible, textarea:visible', form).val(''); 
    3943            } 
  • trunk/wp-admin/js/tags.js

    r11676 r12818  
    1 jQuery(document).ready(function(a){a(".delete-tag").live("click",function(g){var b=a(this),f=b.parents("tr"),c=true,d;if("undefined"!=showNotice){c=showNotice.warn()}if(c){d=b.attr("href").replace(/[^?]*\?/,"").replace(/action=delete/,"action=delete-tag");a.post(ajaxurl,d,function(e){if("1"==e){a("#ajax-response").empty();f.fadeOut("normal",function(){f.remove()})}else{if("-1"==e){a("#ajax-response").empty().append('<div class="error"><p>'+tagsl10n.noPerm+"</p></div>");f.children().css("backgroundColor","")}else{a("#ajax-response").empty().append('<div class="error"><p>'+tagsl10n.broken+"</p></div>");f.children().css("backgroundColor","")}}});f.children().css("backgroundColor","#f33")}return false});a("#submit").click(function(){var b=a(this).parents("form");if(!validateForm(b)){return false}a.post(ajaxurl,a("#addtag").serialize(),function(c){if(c.indexOf('<div class="error"')===0){a("#ajax-response").append(c)}else{a("#ajax-response").empty();a("#the-list").prepend(c);a('input[type="text"]:visible, textarea:visible',b).val("")}});return false})}); 
     1jQuery(document).ready(function($){$(".delete-tag").live("click",function(e){var t=$(this),tr=t.parents("tr"),r=true,data;if("undefined"!=showNotice){r=showNotice.warn()}if(r){data=t.attr("href").replace(/[^?]*\?/,"").replace(/action=delete/,"action=delete-tag");$.post(ajaxurl,data,function(r){if("1"==r){$("#ajax-response").empty();tr.fadeOut("normal",function(){tr.remove()})}else{if("-1"==r){$("#ajax-response").empty().append('<div class="error"><p>'+tagsl10n.noPerm+"</p></div>");tr.children().css("backgroundColor","")}else{$("#ajax-response").empty().append('<div class="error"><p>'+tagsl10n.broken+"</p></div>");tr.children().css("backgroundColor","")}}});tr.children().css("backgroundColor","#f33")}return false});$("#submit").click(function(){var form=$(this).parents("form");if(!validateForm(form)){return false}$.post(ajaxurl,$("#addtag").serialize(),function(r){if(r.indexOf('<div class="error"')===0){$("#ajax-response").append(r)}else{$("#ajax-response").empty();var parent=form.find("select#parent").val();if(parent>0&&$("#tag-"+parent).length>0){$("#the-list #tag-"+parent).after(r)}else{$("#the-list").prepend(r)}$('input[type="text"]:visible, textarea:visible',form).val("")}});return false})}); 
  • trunk/wp-admin/menu.php

    r12789 r12818  
    5151            continue; 
    5252 
    53         if ( $tax->hierarchical ) 
    54             $submenu['edit.php'][$i] = array( esc_attr($tax->label), 'manage_categories', 'categories.php?taxonomy=' . $tax->name ); 
    55         else 
    56             $submenu['edit.php'][$i] = array( esc_attr($tax->label), 'manage_categories', 'edit-tags.php?taxonomy=' . $tax->name ); 
    57         ++$i; 
     53        $submenu['edit.php'][$i++] = array( esc_attr($tax->label), 'manage_categories', 'edit-tags.php?taxonomy=' . $tax->name ); 
    5854    } 
    5955 
     
    9187            continue; 
    9288 
    93         if ( $tax->hierarchical ) 
    94             $submenu["edit.php?post_type=$ptype"][$i] = array( esc_attr($tax->label), 'manage_categories', "categories.php?taxonomy=$tax->name&amp;post_type=$ptype" ); 
    95         else 
    96             $submenu["edit.php?post_type=$ptype"][$i] = array( esc_attr($tax->label), 'manage_categories', "edit-tags.php?taxonomy=$tax->name&amp;post_type=$ptype" ); 
    97         ++$i; 
     89        $submenu["edit.php?post_type=$ptype"][$i++] = array( esc_attr($tax->label), 'manage_categories', "edit-tags.php?taxonomy=$tax->name&amp;post_type=$ptype" ); 
    9890    } 
    9991} 
  • trunk/wp-includes/taxonomy.php

    r12798 r12818  
    787787    // don't limit the query results when we have to descend the family tree 
    788788    if ( ! empty($number) && ! $hierarchical && empty( $child_of ) && '' === $parent ) { 
    789         if( $offset ) 
     789        if ( $offset ) 
    790790            $limit = 'LIMIT ' . $offset . ',' . $number; 
    791791        else 
    792792            $limit = 'LIMIT ' . $number; 
    793  
    794     } else 
     793    } else { 
    795794        $limit = ''; 
     795    } 
    796796 
    797797    if ( !empty($search) ) { 
     
    24472447} 
    24482448 
     2449 
    24492450?> 
Note: See TracChangeset for help on using the changeset viewer.