Ticket #21240: 21240.6.diff

File 21240.6.diff, 6.3 KB (added by SergeyBiryukov, 10 months ago)
  • wp-admin/includes/class-wp-posts-list-table.php

     
    269269                if ( post_type_supports( $post_type, 'author' ) ) 
    270270                        $posts_columns['author'] = __( 'Author' ); 
    271271 
    272                 if ( empty( $post_type ) || is_object_in_taxonomy( $post_type, 'category' ) ) 
     272                $this->taxonomy_columns = array(); 
     273 
     274                if ( empty( $post_type ) || is_object_in_taxonomy( $post_type, 'category' ) ) { 
    273275                        $posts_columns['categories'] = __( 'Categories' ); 
     276                        $this->taxonomy_columns[] = 'categories'; 
     277                } 
    274278 
    275                 if ( empty( $post_type ) || is_object_in_taxonomy( $post_type, 'post_tag' ) ) 
     279                if ( empty( $post_type ) || is_object_in_taxonomy( $post_type, 'post_tag' ) ) { 
    276280                        $posts_columns['tags'] = __( 'Tags' ); 
     281                        $this->taxonomy_columns[] = 'tags'; 
     282                } 
    277283 
     284                $post_type_object = get_post_type_object( $post_type ); 
     285                $registered_taxonomies = get_object_taxonomies( $post_type ); 
     286 
     287                if ( $post_type_object->show_taxonomy_columns && is_array( $post_type_object->show_taxonomy_columns ) ) 
     288                        $taxonomies = $post_type_object->show_taxonomy_columns; 
     289                elseif ( $post_type_object->show_taxonomy_columns ) 
     290                        $taxonomies = $registered_taxonomies; 
     291                else 
     292                        $taxonomies = array(); 
     293 
     294                $custom_taxonomies = array_diff( $taxonomies, array( 'category', 'post_tag' ) ); 
     295                $this->taxonomy_columns = array_merge( $this->taxonomy_columns, $custom_taxonomies ); 
     296                $this->taxonomy_columns = apply_filters( 'show_taxonomy_columns', $this->taxonomy_columns, $post_type ); 
     297 
     298                foreach ( $this->taxonomy_columns as $taxonomy ) { 
     299                        if ( ! in_array( $taxonomy, $registered_taxonomies ) ) 
     300                                continue; 
     301 
     302                        $taxonomy_object = get_taxonomy( $taxonomy ); 
     303                        $posts_columns[ $taxonomy ] = $taxonomy_object->labels->name; 
     304                } 
     305 
    278306                $post_status = !empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all'; 
    279307                if ( post_type_supports( $post_type, 'comments' ) && !in_array( $post_status, array( 'pending', 'draft', 'future' ) ) ) 
    280308                        $posts_columns['comments'] = '<span class="vers"><img alt="' . esc_attr__( 'Comments' ) . '" src="' . esc_url( admin_url( 'images/comment-grey-bubble.png' ) ) . '" /></span>'; 
     
    529557                                } 
    530558                                else { 
    531559                                        $attributes = 'class="post-title page-title column-title"' . $style; 
    532                                          
     560 
    533561                                        $pad = str_repeat( '&#8212; ', $level ); 
    534562?> 
    535563                        <td <?php echo $attributes ?>><strong><?php if ( $can_edit_post && $post->post_status != 'trash' ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ); ?>"><?php echo $pad; echo $title ?></a><?php } else { echo $pad; echo $title; }; _post_states( $post ); ?></strong> 
     
    603631                                echo '</td>'; 
    604632                        break; 
    605633 
    606                         case 'categories': 
    607                         ?> 
    608                         <td <?php echo $attributes ?>><?php 
    609                                 $categories = get_the_category(); 
    610                                 if ( !empty( $categories ) ) { 
    611                                         $out = array(); 
    612                                         foreach ( $categories as $c ) { 
    613                                                 $out[] = sprintf( '<a href="%s">%s</a>', 
    614                                                         esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'category_name' => $c->slug ), 'edit.php' ) ), 
    615                                                         esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'category', 'display' ) ) 
    616                                                 ); 
    617                                         } 
    618                                         /* translators: used between list items, there is a space after the comma */ 
    619                                         echo join( __( ', ' ), $out ); 
    620                                 } else { 
    621                                         _e( 'Uncategorized' ); 
    622                                 } 
    623                         ?></td> 
    624                         <?php 
    625                         break; 
     634                        case ( in_array( $column_name, $this->taxonomy_columns ) ) : 
     635                                $taxonomy = $column_name; 
     636                                if ( 'categories' == $column_name ) 
     637                                        $taxonomy = 'category'; 
     638                                elseif ( 'tags' == $column_name ) 
     639                                        $taxonomy = 'post_tag'; 
    626640 
    627                         case 'tags': 
     641                                $taxonomy_object = get_taxonomy( $taxonomy ); 
    628642                        ?> 
    629643                        <td <?php echo $attributes ?>><?php 
    630                                 $tags = get_the_tags( $post->ID ); 
    631                                 if ( !empty( $tags ) ) { 
     644                                $terms = get_the_terms( $post->ID, $taxonomy ); 
     645                                if ( !empty( $terms ) ) { 
    632646                                        $out = array(); 
    633                                         foreach ( $tags as $c ) { 
     647                                        foreach ( $terms as $t ) { 
    634648                                                $out[] = sprintf( '<a href="%s">%s</a>', 
    635                                                         esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'tag' => $c->slug ), 'edit.php' ) ), 
    636                                                         esc_html( sanitize_term_field( 'name', $c->name, $c->term_id, 'tag', 'display' ) ) 
     649                                                        esc_url( add_query_arg( array( 'post_type' => $post->post_type, $taxonomy_object->query_var => $t->slug ), 'edit.php' ) ), 
     650                                                        esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) ) 
    637651                                                ); 
    638652                                        } 
    639653                                        /* translators: used between list items, there is a space after the comma */ 
    640654                                        echo join( __( ', ' ), $out ); 
    641655                                } else { 
    642                                         _e( 'No Tags' ); 
     656                                        echo $taxonomy_object->labels->no_items; 
    643657                                } 
    644658                        ?></td> 
    645659                        <?php 
     
    679693                        ?></td> 
    680694                        <?php 
    681695                        break; 
     696                        } 
    682697                } 
    683         } 
    684698        ?> 
    685699                </tr> 
    686700        <?php 
  • wp-includes/post.php

     
    980980                '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'hierarchical' => false, 
    981981                'public' => false, 'rewrite' => true, 'has_archive' => false, 'query_var' => true, 
    982982                'supports' => array(), 'register_meta_box_cb' => null, 
    983                 'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null, 
     983                'taxonomies' => array(), 'show_taxonomy_columns' => false, 
     984                'show_ui' => null, 'menu_position' => null, 'menu_icon' => null, 
    984985                'can_export' => true, 
    985986                'show_in_nav_menus' => null, 'show_in_menu' => null, 'show_in_admin_bar' => null, 
    986987                'delete_with_user' => null, 
  • wp-includes/taxonomy.php

     
    416416                'search_items' => array( __( 'Search Tags' ), __( 'Search Categories' ) ), 
    417417                'popular_items' => array( __( 'Popular Tags' ), null ), 
    418418                'all_items' => array( __( 'All Tags' ), __( 'All Categories' ) ), 
     419                'no_items' => array( __( 'No Tags' ), __( 'No Categories' ) ), 
    419420                'parent_item' => array( null, __( 'Parent Category' ) ), 
    420421                'parent_item_colon' => array( null, __( 'Parent Category:' ) ), 
    421422                'edit_item' => array( __( 'Edit Tag' ), __( 'Edit Category' ) ),