Make WordPress Core


Ignore:
Timestamp:
01/24/2010 11:00:27 AM (16 years ago)
Author:
dd32
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.