Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions src/wp-admin/includes/class-wp-terms-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,34 @@ public function display_rows_or_placeholder() {
$children = _get_term_hierarchy( $taxonomy );
}

// Handle custom display of default category by showing it first in the list.
if ( 'category' === $taxonomy ) {
$default_category = get_term( get_option( 'default_category' ), 'category' );
if ( $default_category && ! is_wp_error( $default_category ) ) {
$this->single_row( $default_category );
}
Comment on lines +254 to +257
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The $default_category assignment seems like it could maybe be moved up outside of the if statement to be reused here and below in the else.

}

/*
* Some funky recursion to get the job done (paging & parents mainly) is contained within.
* Skip it for non-hierarchical taxonomies for performance sake.
*/
$this->_rows( $taxonomy, $this->items, $children, $offset, $number, $count );
} else {
// Handle custom display of default category by showing it first in the list.
$default_category_id = false;
if ( 'category' === $taxonomy ) {
$default_category = get_term( get_option( 'default_category' ), 'category' );
if ( $default_category && ! is_wp_error( $default_category ) ) {
$this->single_row( $default_category );
$default_category_id = $default_category->term_id;
}
}

foreach ( $this->items as $term ) {
if ( $default_category_id && $default_category_id === $term->term_id ) {
continue;
}
$this->single_row( $term );
}
}
Expand All @@ -275,6 +296,12 @@ private function _rows( $taxonomy, $terms, &$children, $start, $per_page, &$coun

$end = $start + $per_page;

// Handle display of default category by showing it first in the list, capture default category id.
$default_category_id = false;
if ( 'category' === $taxonomy ) {
$default_category_id = (int) get_option( 'default_category' );
}

foreach ( $terms as $key => $term ) {

if ( $count >= $end ) {
Expand All @@ -285,6 +312,11 @@ private function _rows( $taxonomy, $terms, &$children, $start, $per_page, &$coun
continue;
}

// Skip duplicating display of default category.
if ( $default_category_id && $default_category_id === $term->term_id ) {
continue;
}

// If the page starts in a subtree, print the parents.
if ( $count === $start && $term->parent > 0 && empty( $_REQUEST['s'] ) ) {
$my_parents = array();
Expand Down Expand Up @@ -383,6 +415,12 @@ public function column_cb( $item ) {
public function column_name( $tag ) {
$taxonomy = $this->screen->taxonomy;

$default_term = get_option( 'default_' . $taxonomy );
$default_term_label = '';
if ( $tag->term_id == $default_term ) {
$default_term_label = ' &mdash; <span class="taxonomy-default-label">' . __( 'Default' ) . '</span>';
}

$pad = str_repeat( '&#8212; ', max( 0, $this->level ) );

/**
Expand Down Expand Up @@ -422,8 +460,9 @@ public function column_name( $tag ) {
}

$output = sprintf(
'<strong>%s</strong><br />',
$name
'<strong>%s%s</strong><br />',
$name,
$default_term_label
);

/** This filter is documented in wp-admin/includes/class-wp-terms-list-table.php */
Expand Down
Loading