diff -r be944660c56a -r 3d72ae0968f4 wp/wp-admin/includes/class-wp-terms-list-table.php --- a/wp/wp-admin/includes/class-wp-terms-list-table.php Wed Sep 21 18:19:35 2022 +0200 +++ b/wp/wp-admin/includes/class-wp-terms-list-table.php Tue Sep 27 16:37:53 2022 +0200 @@ -77,9 +77,11 @@ /** */ public function prepare_items() { - $tags_per_page = $this->get_items_per_page( 'edit_' . $this->screen->taxonomy . '_per_page' ); + $taxonomy = $this->screen->taxonomy; - if ( 'post_tag' === $this->screen->taxonomy ) { + $tags_per_page = $this->get_items_per_page( "edit_{$taxonomy}_per_page" ); + + if ( 'post_tag' === $taxonomy ) { /** * Filters the number of terms displayed per page for the Tags list table. * @@ -98,7 +100,7 @@ * @param int $tags_per_page Number of tags to be displayed. Default 20. */ $tags_per_page = apply_filters_deprecated( 'tagsperpage', array( $tags_per_page ), '2.8.0', 'edit_tags_per_page' ); - } elseif ( 'category' === $this->screen->taxonomy ) { + } elseif ( 'category' === $taxonomy ) { /** * Filters the number of terms displayed per page for the Categories list table. * @@ -112,9 +114,11 @@ $search = ! empty( $_REQUEST['s'] ) ? trim( wp_unslash( $_REQUEST['s'] ) ) : ''; $args = array( - 'search' => $search, - 'page' => $this->get_pagenum(), - 'number' => $tags_per_page, + 'taxonomy' => $taxonomy, + 'search' => $search, + 'page' => $this->get_pagenum(), + 'number' => $tags_per_page, + 'hide_empty' => 0, ); if ( ! empty( $_REQUEST['orderby'] ) ) { @@ -125,13 +129,24 @@ $args['order'] = trim( wp_unslash( $_REQUEST['order'] ) ); } + $args['offset'] = ( $args['page'] - 1 ) * $args['number']; + + // Save the values because 'number' and 'offset' can be subsequently overridden. $this->callback_args = $args; + if ( is_taxonomy_hierarchical( $taxonomy ) && ! isset( $args['orderby'] ) ) { + // We'll need the full set of terms then. + $args['number'] = 0; + $args['offset'] = $args['number']; + } + + $this->items = get_terms( $args ); + $this->set_pagination_args( array( 'total_items' => wp_count_terms( array( - 'taxonomy' => $this->screen->taxonomy, + 'taxonomy' => $taxonomy, 'search' => $search, ) ), @@ -141,14 +156,6 @@ } /** - * @return bool - */ - public function has_items() { - // @todo Populate $this->items in prepare_items(). - return true; - } - - /** */ public function no_items() { echo get_taxonomy( $this->screen->taxonomy )->labels->not_found; @@ -216,45 +223,21 @@ public function display_rows_or_placeholder() { $taxonomy = $this->screen->taxonomy; - $args = wp_parse_args( - $this->callback_args, - array( - 'taxonomy' => $taxonomy, - 'page' => 1, - 'number' => 20, - 'search' => '', - 'hide_empty' => 0, - ) - ); - - $page = $args['page']; - - // Set variable because $args['number'] can be subsequently overridden. - $number = $args['number']; - - $offset = ( $page - 1 ) * $number; - $args['offset'] = $offset; + $number = $this->callback_args['number']; + $offset = $this->callback_args['offset']; // Convert it to table rows. $count = 0; - if ( is_taxonomy_hierarchical( $taxonomy ) && ! isset( $args['orderby'] ) ) { - // We'll need the full set of terms then. - $args['number'] = 0; - $args['offset'] = $args['number']; - } - - $terms = get_terms( $args ); - - if ( empty( $terms ) || ! is_array( $terms ) ) { + if ( empty( $this->items ) || ! is_array( $this->items ) ) { echo ''; $this->no_items(); echo ''; return; } - if ( is_taxonomy_hierarchical( $taxonomy ) && ! isset( $args['orderby'] ) ) { - if ( ! empty( $args['search'] ) ) {// Ignore children on searches. + 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 ); @@ -264,9 +247,9 @@ * 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, $terms, $children, $offset, $number, $count ); + $this->_rows( $taxonomy, $this->items, $children, $offset, $number, $count ); } else { - foreach ( $terms as $term ) { + foreach ( $this->items as $term ) { $this->single_row( $term ); } } @@ -279,10 +262,10 @@ * @param int $start * @param int $per_page * @param int $count - * @param int $parent + * @param int $parent_term * @param int $level */ - private function _rows( $taxonomy, $terms, &$children, $start, $per_page, &$count, $parent = 0, $level = 0 ) { + private function _rows( $taxonomy, $terms, &$children, $start, $per_page, &$count, $parent_term = 0, $level = 0 ) { $end = $start + $per_page; @@ -292,7 +275,7 @@ break; } - if ( $term->parent !== $parent && empty( $_REQUEST['s'] ) ) { + if ( $term->parent !== $parent_term && empty( $_REQUEST['s'] ) ) { continue; } @@ -364,10 +347,15 @@ } /** - * @param WP_Term $tag Term object. + * @since 5.9.0 Renamed `$tag` to `$item` to match parent class for PHP 8 named parameter support. + * + * @param WP_Term $item Term object. * @return string */ - public function column_cb( $tag ) { + public function column_cb( $item ) { + // Restores the more descriptive, specific name for use within this method. + $tag = $item; + if ( current_user_can( 'delete_term', $tag->term_id ) ) { return sprintf( '' . @@ -409,7 +397,7 @@ $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI']; - $edit_link = get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type ); + $edit_link = get_edit_term_link( $tag, $taxonomy, $this->screen->post_type ); if ( $edit_link ) { $edit_link = add_query_arg( @@ -456,18 +444,21 @@ * Generates and displays row action links. * * @since 4.3.0 + * @since 5.9.0 Renamed `$tag` to `$item` to match parent class for PHP 8 named parameter support. * - * @param WP_Term $tag Tag being acted upon. + * @param WP_Term $item Tag being acted upon. * @param string $column_name Current column name. * @param string $primary Primary column name. * @return string Row actions output for terms, or an empty string * if the current column is not the primary column. */ - protected function handle_row_actions( $tag, $column_name, $primary ) { + protected function handle_row_actions( $item, $column_name, $primary ) { if ( $primary !== $column_name ) { return ''; } + // Restores the more descriptive, specific name for use within this method. + $tag = $item; $taxonomy = $this->screen->taxonomy; $tax = get_taxonomy( $taxonomy ); $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI']; @@ -475,7 +466,7 @@ $edit_link = add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $uri ) ), - get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type ) + get_edit_term_link( $tag, $taxonomy, $this->screen->post_type ) ); $actions = array(); @@ -620,11 +611,13 @@ } /** - * @param WP_Term $tag Term object. + * @since 5.9.0 Renamed `$tag` to `$item` to match parent class for PHP 8 named parameter support. + * + * @param WP_Term $item Term object. * @param string $column_name Name of the column. * @return string */ - public function column_default( $tag, $column_name ) { + public function column_default( $item, $column_name ) { /** * Filters the displayed columns in the terms list table. * @@ -638,11 +631,11 @@ * * @since 2.8.0 * - * @param string $string Blank string. + * @param string $string Custom column output. Default empty. * @param string $column_name Name of the column. * @param int $term_id Term ID. */ - return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $tag->term_id ); + return apply_filters( "manage_{$this->screen->taxonomy}_custom_column", '', $column_name, $item->term_id ); } /** @@ -663,6 +656,7 @@ +
@@ -703,19 +697,19 @@ ?>
- - + + -
+