diff -r c7c34916027a -r 177826044cd9 wp/wp-admin/includes/class-wp-terms-list-table.php --- a/wp/wp-admin/includes/class-wp-terms-list-table.php Mon Oct 14 18:06:33 2019 +0200 +++ b/wp/wp-admin/includes/class-wp-terms-list-table.php Mon Oct 14 18:28:13 2019 +0200 @@ -38,32 +38,36 @@ public function __construct( $args = array() ) { global $post_type, $taxonomy, $action, $tax; - parent::__construct( array( - 'plural' => 'tags', - 'singular' => 'tag', - 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, - ) ); + parent::__construct( + array( + 'plural' => 'tags', + 'singular' => 'tag', + 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, + ) + ); $action = $this->screen->action; $post_type = $this->screen->post_type; $taxonomy = $this->screen->taxonomy; - if ( empty( $taxonomy ) ) + if ( empty( $taxonomy ) ) { $taxonomy = 'post_tag'; + } - if ( ! taxonomy_exists( $taxonomy ) ) + if ( ! taxonomy_exists( $taxonomy ) ) { wp_die( __( 'Invalid taxonomy.' ) ); + } $tax = get_taxonomy( $taxonomy ); // @todo Still needed? Maybe just the show_ui part. - if ( empty( $post_type ) || !in_array( $post_type, get_post_types( array( 'show_ui' => true ) ) ) ) + if ( empty( $post_type ) || ! in_array( $post_type, get_post_types( array( 'show_ui' => true ) ) ) ) { $post_type = 'post'; + } } /** - * * @return bool */ public function ajax_user_can() { @@ -105,30 +109,33 @@ $tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page ); } - $search = !empty( $_REQUEST['s'] ) ? trim( wp_unslash( $_REQUEST['s'] ) ) : ''; + $search = ! empty( $_REQUEST['s'] ) ? trim( wp_unslash( $_REQUEST['s'] ) ) : ''; $args = array( 'search' => $search, - 'page' => $this->get_pagenum(), + 'page' => $this->get_pagenum(), 'number' => $tags_per_page, ); - if ( !empty( $_REQUEST['orderby'] ) ) + if ( ! empty( $_REQUEST['orderby'] ) ) { $args['orderby'] = trim( wp_unslash( $_REQUEST['orderby'] ) ); + } - if ( !empty( $_REQUEST['order'] ) ) + if ( ! empty( $_REQUEST['order'] ) ) { $args['order'] = trim( wp_unslash( $_REQUEST['order'] ) ); + } $this->callback_args = $args; - $this->set_pagination_args( array( - 'total_items' => wp_count_terms( $this->screen->taxonomy, compact( 'search' ) ), - 'per_page' => $tags_per_page, - ) ); + $this->set_pagination_args( + array( + 'total_items' => wp_count_terms( $this->screen->taxonomy, compact( 'search' ) ), + 'per_page' => $tags_per_page, + ) + ); } /** - * * @return bool */ public function has_items() { @@ -143,7 +150,6 @@ } /** - * * @return array */ protected function get_bulk_actions() { @@ -157,18 +163,17 @@ } /** - * * @return string */ public function current_action() { - if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' === $_REQUEST['action'] || 'delete' === $_REQUEST['action2'] ) ) + if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' === $_REQUEST['action'] || 'delete' === $_REQUEST['action2'] ) ) { return 'bulk-delete'; + } return parent::current_action(); } /** - * * @return array */ public function get_columns() { @@ -189,7 +194,6 @@ } /** - * * @return array */ protected function get_sortable_columns() { @@ -198,7 +202,7 @@ 'description' => 'description', 'slug' => 'slug', 'posts' => 'count', - 'links' => 'count' + 'links' => 'count', ); } @@ -207,12 +211,15 @@ public function display_rows_or_placeholder() { $taxonomy = $this->screen->taxonomy; - $args = wp_parse_args( $this->callback_args, array( - 'page' => 1, - 'number' => 20, - 'search' => '', - 'hide_empty' => 0 - ) ); + $args = wp_parse_args( + $this->callback_args, + array( + 'page' => 1, + 'number' => 20, + 'search' => '', + 'hide_empty' => 0, + ) + ); $page = $args['page']; @@ -268,22 +275,25 @@ foreach ( $terms as $key => $term ) { - if ( $count >= $end ) + if ( $count >= $end ) { break; + } - if ( $term->parent != $parent && empty( $_REQUEST['s'] ) ) + if ( $term->parent != $parent && empty( $_REQUEST['s'] ) ) { continue; + } // If the page starts in a subtree, print the parents. if ( $count == $start && $term->parent > 0 && empty( $_REQUEST['s'] ) ) { $my_parents = $parent_ids = array(); - $p = $term->parent; + $p = $term->parent; while ( $p ) { - $my_parent = get_term( $p, $taxonomy ); + $my_parent = get_term( $p, $taxonomy ); $my_parents[] = $my_parent; - $p = $my_parent->parent; - if ( in_array( $p, $parent_ids ) ) // Prevent parent loops. + $p = $my_parent->parent; + if ( in_array( $p, $parent_ids ) ) { // Prevent parent loops. break; + } $parent_ids[] = $p; } unset( $parent_ids ); @@ -303,10 +313,11 @@ ++$count; - unset( $terms[$key] ); + unset( $terms[ $key ] ); - if ( isset( $children[$term->term_id] ) && empty( $_REQUEST['s'] ) ) + if ( isset( $children[ $term->term_id ] ) && empty( $_REQUEST['s'] ) ) { $this->_rows( $taxonomy, $terms, $children, $start, $per_page, $count, $term->term_id, $level + 1 ); + } } } @@ -317,11 +328,18 @@ */ public function single_row( $tag, $level = 0 ) { global $taxonomy; - $tag = sanitize_term( $tag, $taxonomy ); + $tag = sanitize_term( $tag, $taxonomy ); $this->level = $level; - echo ''; + if ( $tag->parent ) { + $count = count( get_ancestors( $tag->term_id, $taxonomy, 'taxonomy' ) ); + $level = 'level-' . $count; + } else { + $level = 'level-0'; + } + + echo ''; $this->single_row_columns( $tag ); echo ''; } @@ -367,17 +385,25 @@ $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI']; - $edit_link = add_query_arg( - 'wp_http_referer', - urlencode( wp_unslash( $uri ) ), - get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type ) - ); + $edit_link = get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type ); + + if ( $edit_link ) { + $edit_link = add_query_arg( + 'wp_http_referer', + urlencode( wp_unslash( $uri ) ), + $edit_link + ); + $name = sprintf( + '%s', + esc_url( $edit_link ), + /* translators: %s: taxonomy term name */ + esc_attr( sprintf( __( '“%s” (Edit)' ), $tag->name ) ), + $name + ); + } $out = sprintf( - '%s
', - esc_url( $edit_link ), - /* translators: %s: taxonomy term name */ - esc_attr( sprintf( __( '“%s” (Edit)' ), $tag->name ) ), + '%s
', $name ); @@ -418,8 +444,8 @@ } $taxonomy = $this->screen->taxonomy; - $tax = get_taxonomy( $taxonomy ); - $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI']; + $tax = get_taxonomy( $taxonomy ); + $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI']; $edit_link = add_query_arg( 'wp_http_referer', @@ -437,7 +463,7 @@ __( 'Edit' ) ); $actions['inline hide-if-no-js'] = sprintf( - '%s', + '', /* translators: %s: taxonomy term name */ esc_attr( sprintf( __( 'Quick edit “%s” inline' ), $tag->name ) ), __( 'Quick Edit' ) @@ -452,7 +478,7 @@ __( 'Delete' ) ); } - if ( $tax->public ) { + if ( is_taxonomy_viewable( $tax ) ) { $actions['view'] = sprintf( '%s', get_term_link( $tag ), @@ -468,9 +494,9 @@ * @since 2.8.0 * @deprecated 3.0.0 Use {$taxonomy}_row_actions instead. * - * @param array $actions An array of action links to be displayed. Default - * 'Edit', 'Quick Edit', 'Delete', and 'View'. - * @param WP_Term $tag Term object. + * @param string[] $actions An array of action links to be displayed. Default + * 'Edit', 'Quick Edit', 'Delete', and 'View'. + * @param WP_Term $tag Term object. */ $actions = apply_filters( 'tag_row_actions', $actions, $tag ); @@ -481,9 +507,9 @@ * * @since 3.0.0 * - * @param array $actions An array of action links to be displayed. Default - * 'Edit', 'Quick Edit', 'Delete', and 'View'. - * @param WP_Term $tag Term object. + * @param string[] $actions An array of action links to be displayed. Default + * 'Edit', 'Quick Edit', 'Delete', and 'View'. + * @param WP_Term $tag Term object. */ $actions = apply_filters( "{$taxonomy}_row_actions", $actions, $tag ); @@ -521,22 +547,28 @@ $tax = get_taxonomy( $this->screen->taxonomy ); $ptype_object = get_post_type_object( $this->screen->post_type ); - if ( ! $ptype_object->show_ui ) + if ( ! $ptype_object->show_ui ) { return $count; + } if ( $tax->query_var ) { $args = array( $tax->query_var => $tag->slug ); } else { - $args = array( 'taxonomy' => $tax->name, 'term' => $tag->slug ); + $args = array( + 'taxonomy' => $tax->name, + 'term' => $tag->slug, + ); } - if ( 'post' != $this->screen->post_type ) + if ( 'post' != $this->screen->post_type ) { $args['post_type'] = $this->screen->post_type; + } - if ( 'attachment' === $this->screen->post_type ) - return "$count"; + if ( 'attachment' === $this->screen->post_type ) { + return "$count"; + } - return "$count"; + return "$count"; } /** @@ -545,8 +577,9 @@ */ public function column_links( $tag ) { $count = number_format_i18n( $tag->count ); - if ( $count ) + if ( $count ) { $count = "$count"; + } return $count; } @@ -579,9 +612,10 @@ public function inline_edit() { $tax = get_taxonomy( $this->screen->taxonomy ); - if ( ! current_user_can( $tax->cap->edit_terms ) ) + if ( ! current_user_can( $tax->cap->edit_terms ) ) { return; -?> + } + ?>
-