Make WordPress Core

Ticket #32942: 32942.2.diff

File 32942.2.diff, 6.9 KB (added by mikinc860, 3 years ago)

Updated Diff with post type name

  • src/wp-admin/includes/class-wp-terms-list-table.php

    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 3c277d6a61..1e6a50df90 100644
    a b class WP_Terms_List_Table extends WP_List_Table { 
    195195                        'slug'        => __( 'Slug' ),
    196196                );
    197197
     198                // Check if current taxonomy assigned in multiple post type
     199                if ( 'attachment' != $this->screen->post_type ) {
     200                        $taxonomy_object = get_taxonomy( $this->screen->taxonomy );
     201                        if ($taxonomy_object) {
     202                                $assigned_post_types = $taxonomy_object->object_type;
     203
     204                                if (is_array($assigned_post_types) && count($assigned_post_types) > 1) {
     205                                        // If assigned multiple post type then only below column will add.
     206                                        $current_count = ucfirst( $this->screen->post_type ) . ' Count';
     207                                        $columns['otherposts'] = _x( $current_count, 'Number/count of items' );
     208                                }
     209                        }
     210                }
     211
    198212                if ( 'link_category' === $this->screen->taxonomy ) {
    199213                        $columns['links'] = __( 'Links' );
    200214                } else {
    class WP_Terms_List_Table extends WP_List_Table { 
    220234                        'name'        => array( 'name', false, _x( 'Name', 'term name' ), $name_orderby_text, 'asc' ),
    221235                        'description' => array( 'description', false, __( 'Description' ), __( 'Table ordered by Description.' ) ),
    222236                        'slug'        => array( 'slug', false, __( 'Slug' ), __( 'Table ordered by Slug.' ) ),
     237                        'otherposts'       => array( 'count', false, _x( 'Count', 'Number/count of items' ), __( 'Table ordered by Current Posts Count.' ) ),
    223238                        'posts'       => array( 'count', false, _x( 'Count', 'Number/count of items' ), __( 'Table ordered by Posts Count.' ) ),
    224239                        'links'       => array( 'count', false, __( 'Links' ), __( 'Table ordered by Links.' ) ),
    225240                );
    class WP_Terms_List_Table extends WP_List_Table { 
    571586                return apply_filters( 'editable_slug', $tag->slug, $tag );
    572587        }
    573588
     589        /**
     590         * @param WP_Term $tag Term object.
     591         * @return string
     592         */
     593        public function column_otherposts( $tag ) {
     594                $count = number_format_i18n( $tag->count );
     595
     596                $tax = get_taxonomy( $this->screen->taxonomy );
     597
     598                $ptype_object = get_post_type_object( $this->screen->post_type );
     599                if ( ! $ptype_object->show_ui ) {
     600                        return $count;
     601                }
     602
     603                if ( $tax->query_var ) {
     604                        $args = array( $tax->query_var => $tag->slug );
     605                } else {
     606                        $args = array(
     607                                'taxonomy' => $tax->name,
     608                                'term'     => $tag->slug,
     609                        );
     610                }
     611
     612                if ( 'post' !== $this->screen->post_type ) {
     613                        $args['post_type'] = $this->screen->post_type;
     614                }
     615
     616                $query_args = array(
     617                        'post_type' => $this->screen->post_type,
     618                        'post_status' => 'publish',
     619                        'tax_query' => array(
     620                                array(
     621                                        'taxonomy' => $this->screen->taxonomy,
     622                                        'field' => 'id',
     623                                        'terms' => array( $tag->term_id ),
     624                                ),
     625                        ),
     626                );
     627                $the_query = new WP_Query( $query_args );
     628               
     629                if ( isset( $the_query->found_posts ) ) {
     630                       
     631                        return "<a href='" . esc_url( add_query_arg( $args, 'edit.php' ) ) . "'>$the_query->found_posts</a>";
     632                }
     633
     634                return "<a href='" . esc_url( add_query_arg( $args, 'edit.php' ) ) . "'>$count</a>";
     635        }
     636
    574637        /**
    575638         * @param WP_Term $tag Term object.
    576639         * @return string
    class WP_Terms_List_Table extends WP_List_Table { 
    688751                                'description' => true,
    689752                                'name'        => true,
    690753                                'slug'        => true,
     754                                'otherposts'  => true,
    691755                                'posts'       => true,
    692756                        );
    693757