Skip to content
Open
Changes from 1 commit
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
42 changes: 40 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 @@ -242,20 +242,40 @@ public function display_rows_or_placeholder() {
return;
}

// Handle custom display of default category by showing it first in the list.
$default_category = false;
if ( 'category' === $taxonomy ) {
$default_category = get_term( get_option( 'default_category' ), 'category' );
if ( ! $default_category || is_wp_error( $default_category ) ) {
$default_category = false;
}
}

if ( is_taxonomy_hierarchical( $taxonomy ) && ! isset( $this->callback_args['orderby'] ) ) {
if ( ! empty( $this->callback_args['search'] ) ) {// Ignore children on searches.
$children = array();
} else {
$children = _get_term_hierarchy( $taxonomy );
}

if ( $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 {
if ( $default_category ) {
$this->single_row( $default_category );
}

foreach ( $this->items as $term ) {
if ( $default_category && $default_category->term_id === $term->term_id ) {
continue;
}
$this->single_row( $term );
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

Prepending the default category with $this->single_row( $default_category ); here without updating $count or otherwise integrating it into the paging logic means the "per page" limit is effectively exceeded: hierarchical lists will show number rows from _rows() plus this extra row, and in the non‑hierarchical branch the default term can appear on every page even when it is not part of the current slice of $this->items. This changes the semantics of pagination (screen options say N items per page but the table often renders N+1), and duplicates the default term across pages. If the goal is just to surface the default category at the top, consider only rendering it when $offset is 0 (first page) and/or adjusting the paging counters so the extra row is accounted for instead of being "outside" the pagination logic.

Copilot uses AI. Check for mistakes.
}
}
Expand All @@ -275,6 +295,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 +311,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 +414,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>';
}
Comment on lines 386 to 390
Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

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

Using get_option( 'default_' . $taxonomy ) here will work for core taxonomies like category and link_category, but it will not pick up default terms registered via register_taxonomy( ... 'default_term' => ... ), which are stored under default_term_{$taxonomy} (see taxonomy.php:537-557 and post.php:5333-5337). If the intent is for the "Default" label to apply to all taxonomies that support default terms (not only categories/link categories), consider mirroring the pattern in map_meta_cap() by checking both default_{$taxonomy} and default_term_{$taxonomy} so the UI stays consistent with how default terms are modeled elsewhere.

Copilot uses AI. Check for mistakes.

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

/**
Expand Down Expand Up @@ -422,8 +459,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