Make WordPress Core

Ticket #21240: 21240.2.diff

File 21240.2.diff, 9.0 KB (added by jtsternberg, 13 years ago)

Ok I've incorporated tags and categories into the new API and moved the column header array creation to WP_Post_List_Table

  • 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,
     
    977978        $defaults = array(
    978979                'labels' => array(), 'description' => '', 'publicly_queryable' => null, 'exclude_from_search' => null,
    979980                'capability_type' => 'post', 'capabilities' => array(), 'map_meta_cap' => null,
    980                 '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'hierarchical' => false,
     981                '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'hierarchical' => false, 'show_taxonomy_columns' => false,
    981982                'public' => false, 'rewrite' => true, 'has_archive' => false, 'query_var' => true,
    982983                'supports' => array(), 'register_meta_box_cb' => null,
    983984                'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null,
     
    12851286        if ( !isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) )
    12861287                $object->labels['all_items'] = $object->labels['menu_name'];
    12871288
     1289        if ( !isset( $object->labels['no_items'] ) && isset( $object->labels['menu_name'] ) )
     1290                $object->labels['no_items'] = 'No ' . $object->labels['menu_name'];
     1291
    12881292        foreach ( $nohier_vs_hier_defaults as $key => $value )
    12891293                        $defaults[$key] = $object->hierarchical ? $value[1] : $value[0];
    12901294
  • 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' ) ),
  • wp-admin/includes/class-wp-posts-list-table.php

     
    270270                        $posts_columns['author'] = __( 'Author' );
    271271
    272272                if ( empty( $post_type ) || is_object_in_taxonomy( $post_type, 'category' ) )
    273                         $posts_columns['categories'] = __( 'Categories' );
     273                        $posts_columns['category'] = __( 'Categories' );
    274274
    275275                if ( empty( $post_type ) || is_object_in_taxonomy( $post_type, 'post_tag' ) )
    276                         $posts_columns['tags'] = __( 'Tags' );
     276                        $posts_columns['post_tag'] = __( 'Tags' );
    277277
    278278                $post_status = !empty( $_REQUEST['post_status'] ) ? $_REQUEST['post_status'] : 'all';
    279279                if ( post_type_supports( $post_type, 'comments' ) && !in_array( $post_status, array( 'pending', 'draft', 'future' ) ) )
     
    287287                        $posts_columns = apply_filters( 'manage_posts_columns', $posts_columns, $post_type );
    288288                $posts_columns = apply_filters( "manage_{$post_type}_posts_columns", $posts_columns );
    289289
     290                if ( !empty( $post_type ) ) {
     291                        $post_type_object = get_post_type_object( $post_type );
     292
     293                        if ( $post_type_object->show_taxonomy_columns ) {
     294
     295                                if ( is_array( $post_type_object->show_taxonomy_columns ) )
     296                                                $taxonomies = $post_type_object->show_taxonomy_columns;
     297                                else
     298                                        $taxonomies = get_object_taxonomies( $screen->post_type );
     299
     300                                if ( empty( $taxonomies ) )
     301                                        return $posts_columns;
     302
     303                                foreach ( $taxonomies as $registered_taxonomy ) {
     304
     305                                        if ( $registered_taxonomy == 'post_tag' || $registered_taxonomy == 'category' ) continue;
     306
     307                                        $taxonomy_object = get_taxonomy( $registered_taxonomy );
     308                                        $posts_columns[$registered_taxonomy] = apply_filters( 'taxonomy_column_header', __( $taxonomy_object->label ), $post_type_object, $taxonomy_object );
     309
     310                                }
     311                        }
     312                }
     313
    290314                return $posts_columns;
    291315        }
    292316
     
    469493                $edit_link = get_edit_post_link( $post->ID );
    470494                $title = _draft_or_post_title();
    471495                $post_type_object = get_post_type_object( $post->post_type );
     496                if ( $post_type_object->show_taxonomy_columns ) {
     497                        if ( is_array( $post_type_object->show_taxonomy_columns ) )
     498                                $taxonomies_columns = $post_type_object->show_taxonomy_columns;
     499                        else
     500                                $taxonomies_columns = get_object_taxonomies( $post_type_object->name );
     501                }
    472502                $can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
    473503
    474504                $alternate = 'alternate' == $alternate ? '' : 'alternate';
     
    529559                                }
    530560                                else {
    531561                                        $attributes = 'class="post-title page-title column-title"' . $style;
    532                                        
    533562                                        $pad = str_repeat( '— ', $level );
    534563?>
    535564                        <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>
     
    603632                                echo '</td>';
    604633                        break;
    605634
    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;
     635                        case ( is_array( $taxonomies_columns ) && in_array( $registered_taxonomy = $column_name, $taxonomies_columns ) ) :
    626636
    627                         case 'tags':
    628                         ?>
    629                         <td <?php echo $attributes ?>><?php
    630                                 $tags = get_the_tags( $post->ID );
    631                                 if ( !empty( $tags ) ) {
    632                                         $out = array();
    633                                         foreach ( $tags as $c ) {
    634                                                 $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' ) )
    637                                                 );
    638                                         }
    639                                         /* translators: used between list items, there is a space after the comma */
    640                                         echo join( __( ', ' ), $out );
    641                                 } else {
    642                                         _e( 'No Tags' );
    643                                 }
    644                         ?></td>
    645                         <?php
     637                        $defaults = array(
     638                                'taxonomy' => $registered_taxonomy,
     639                                'attributes' => $attributes,
     640                        );
     641                        $args = apply_filters( 'taxonomy_column_args', $defaults, $post_type_object, $registered_taxonomy  );
     642
     643                        $this->taxonomy_column( $args );
    646644                        break;
    647645
    648646                        case 'comments':
     
    679677                        ?></td>
    680678                        <?php
    681679                        break;
     680                        }
    682681                }
    683         }
    684682        ?>
    685683                </tr>
    686684        <?php
     
    688686        }
    689687
    690688        /**
     689         * Creates internal taxonomy columns as well as registered taxonomies
     690         *
     691         * @since 3.5.0
     692         */
     693        function taxonomy_column( $atts = array() ) {
     694                global $post;
     695
     696                $defaults = array(
     697                        'taxonomy' => 'category',
     698                        'attributes' => '',
     699                        'empty' => '',
     700                );
     701                $args = wp_parse_args( (array) $atts, $defaults );
     702                extract( $args, EXTR_SKIP );
     703
     704                $attributes = !empty( $attributes ) ? $attributes : 'class="column-'. $taxonomy .'"';
     705                $taxonomy_object = get_taxonomy( $taxonomy );
     706
     707                ?>
     708                <td <?php echo $attributes ?>><?php
     709                        $terms = get_the_terms( $post->ID, $taxonomy );
     710                        if ( !empty( $terms ) ) {
     711                                $out = array();
     712                                foreach ( $terms as $t ) {
     713                                        $out[] = sprintf( '<a href="%s">%s</a>',
     714                                                esc_url( add_query_arg( array( 'post_type' => $post->post_type, $taxonomy_object->query_var => $t->slug ), 'edit.php' ) ),
     715                                                esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
     716                                        );
     717                                }
     718                                /* translators: used between list items, there is a space after the comma */
     719                                echo join( __( ', ' ), $out );
     720                        } else {
     721                                echo $taxonomy_object->labels->no_items;
     722                        }
     723                ?></td>
     724                <?php
     725        }
     726
     727        /**
    691728         * Outputs the hidden row displayed when inline editing
    692729         *
    693730         * @since 3.1.0
  • wp-admin/css/wp-admin.dev.css

     
    23502350
    23512351.fixed .column-response,
    23522352.fixed .column-author,
    2353 .fixed .column-categories,
    2354 .fixed .column-tags,
     2353.fixed .column-category,
     2354.fixed .column-post_tag,
    23552355.fixed .column-rel,
    23562356.fixed .column-role {
    23572357        width: 15%;