-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Taxonomy: Add UI to Category page to indicate default category #10831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from 1 commit
102b5bc
f0421a5
4dc573e
b7e0e1a
eadf8ac
c985c34
52e5831
fa26a3a
1ec2f96
ef7c23a
7b3573f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 ); | ||
|
||
| } | ||
| } | ||
|
|
@@ -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' ); | ||
westonruter marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| foreach ( $terms as $key => $term ) { | ||
|
|
||
| if ( $count >= $end ) { | ||
|
|
@@ -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(); | ||
|
|
@@ -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 = ' — <span class="taxonomy-default-label">' . __( 'Default' ) . '</span>'; | ||
| } | ||
|
Comment on lines
386
to
390
|
||
|
|
||
| $pad = str_repeat( '— ', max( 0, $this->level ) ); | ||
|
|
||
| /** | ||
|
|
@@ -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 */ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.