Ticket #21240: 21240.5.diff

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

     
    275275                if ( empty( $post_type ) || is_object_in_taxonomy( $post_type, 'post_tag' ) ) 
    276276                        $posts_columns['tags'] = __( 'Tags' ); 
    277277 
     278                $post_type_object = get_post_type_object( $post_type ); 
     279                $registered_taxonomies = get_object_taxonomies( $post_type ); 
     280 
     281                if ( $post_type_object->show_taxonomy_columns && is_array( $post_type_object->show_taxonomy_columns ) ) 
     282                        $taxonomies = $post_type_object->show_taxonomy_columns; 
     283                elseif ( $post_type_object->show_taxonomy_columns ) 
     284                        $taxonomies = $registered_taxonomies; 
     285                else 
     286                        $taxonomies = array(); 
     287 
     288                $taxonomies = array_diff( $taxonomies, array( 'category', 'post_tag' ) ); 
     289                $this->taxonomy_columns = array_merge( array( 'categories', 'tags' ), $taxonomies ); 
     290                $this->taxonomy_columns = apply_filters( 'show_taxonomy_columns', $this->taxonomy_columns, $post_type ); 
     291 
     292                foreach ( $this->taxonomy_columns as $taxonomy ) { 
     293                        if ( ! in_array( $taxonomy, $registered_taxonomies ) ) 
     294                                continue; 
     295 
     296                        $taxonomy_object = get_taxonomy( $taxonomy ); 
     297                        $posts_columns[ $taxonomy ] = $taxonomy_object->labels->name; 
     298                } 
     299 
    278300                $post_status = !empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all'; 
    279301                if ( post_type_supports( $post_type, 'comments' ) && !in_array( $post_status, array( 'pending', 'draft', 'future' ) ) ) 
    280302                        $posts_columns['comments'] = '<span class="vers"><img alt="' . esc_attr__( 'Comments' ) . '" src="' . esc_url( admin_url( 'images/comment-grey-bubble.png' ) ) . '" /></span>'; 
     
    529551                                } 
    530552                                else { 
    531553                                        $attributes = 'class="post-title page-title column-title"' . $style; 
    532                                          
     554 
    533555                                        $pad = str_repeat( '&#8212; ', $level ); 
    534556?> 
    535557                        <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> 
     
    603625                                echo '</td>'; 
    604626                        break; 
    605627 
    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; 
     628                        case ( in_array( $column_name, $this->taxonomy_columns ) ) : 
     629                                $taxonomy = $column_name; 
     630                                if ( 'categories' == $column_name ) 
     631                                        $taxonomy = 'category'; 
     632                                elseif ( 'tags' == $column_name ) 
     633                                        $taxonomy = 'post_tag'; 
    626634 
    627                         case 'tags': 
     635                                $taxonomy_object = get_taxonomy( $taxonomy ); 
    628636                        ?> 
    629637                        <td <?php echo $attributes ?>><?php 
    630                                 $tags = get_the_tags( $post->ID ); 
    631                                 if ( !empty( $tags ) ) { 
     638                                $terms = get_the_terms( $post->ID, $taxonomy ); 
     639                                if ( !empty( $terms ) ) { 
    632640                                        $out = array(); 
    633                                         foreach ( $tags as $c ) { 
     641                                        foreach ( $terms as $t ) { 
    634642                                                $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' ) ) 
     643                                                        esc_url( add_query_arg( array( 'post_type' => $post->post_type, $taxonomy_object->query_var => $t->slug ), 'edit.php' ) ), 
     644                                                        esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) ) 
    637645                                                ); 
    638646                                        } 
    639647                                        /* translators: used between list items, there is a space after the comma */ 
    640648                                        echo join( __( ', ' ), $out ); 
    641649                                } else { 
    642                                         _e( 'No Tags' ); 
     650                                        echo $taxonomy_object->labels->no_items; 
    643651                                } 
    644652                        ?></td> 
    645653                        <?php 
     
    679687                        ?></td> 
    680688                        <?php 
    681689                        break; 
     690                        } 
    682691                } 
    683         } 
    684692        ?> 
    685693                </tr> 
    686694        <?php 
  • wp-includes/post.php

     
    2727                'capability_type' => 'post', 
    2828                'map_meta_cap' => true, 
    2929                'hierarchical' => false, 
     30                'show_taxonomy_columns' => array( 'category', 'post_tag' ), 
    3031                'rewrite' => false, 
    3132                'query_var' => false, 
    3233                'delete_with_user' => true, 
     
    980981                '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'hierarchical' => false, 
    981982                'public' => false, 'rewrite' => true, 'has_archive' => false, 'query_var' => true, 
    982983                'supports' => array(), 'register_meta_box_cb' => null, 
    983                 'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null, 
     984                'taxonomies' => array(), 'show_taxonomy_columns' => false, 
     985                'show_ui' => null, 'menu_position' => null, 'menu_icon' => null, 
    984986                'can_export' => true, 
    985987                'show_in_nav_menus' => null, 'show_in_menu' => null, 'show_in_admin_bar' => null, 
    986988                'delete_with_user' => null, 
  • wp-includes/taxonomy.php

     
    4343 
    4444        register_taxonomy( 'category', 'post', array( 
    4545                'hierarchical' => true, 
     46                'labels' => array( 
     47                        'no_items' => __( 'Uncategorized' ), 
     48                ), 
    4649                'query_var' => 'category_name', 
    4750                'rewrite' => $rewrite['category'], 
    4851                'public' => true, 
     
    416419                'search_items' => array( __( 'Search Tags' ), __( 'Search Categories' ) ), 
    417420                'popular_items' => array( __( 'Popular Tags' ), null ), 
    418421                'all_items' => array( __( 'All Tags' ), __( 'All Categories' ) ), 
     422                'no_items' => array( __( 'No Tags' ), __( 'No Categories' ) ), 
    419423                'parent_item' => array( null, __( 'Parent Category' ) ), 
    420424                'parent_item_colon' => array( null, __( 'Parent Category:' ) ), 
    421425                'edit_item' => array( __( 'Edit Tag' ), __( 'Edit Category' ) ),