diff --git a/src/wp-admin/includes/class-wp-terms-list-table.php b/src/wp-admin/includes/class-wp-terms-list-table.php index 7537a499974d5..ff39c648d0991 100644 --- a/src/wp-admin/includes/class-wp-terms-list-table.php +++ b/src/wp-admin/includes/class-wp-terms-list-table.php @@ -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 ); + } + } + /* * 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 ); } } @@ -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 ) { @@ -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(); @@ -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 = ' — ' . __( 'Default' ) . ''; + } + $pad = str_repeat( '— ', max( 0, $this->level ) ); /** @@ -422,8 +460,9 @@ public function column_name( $tag ) { } $output = sprintf( - '%s
', - $name + '%s%s
', + $name, + $default_term_label ); /** This filter is documented in wp-admin/includes/class-wp-terms-list-table.php */