Make WordPress Core

Ticket #21240: 21240.diff

File 21240.diff, 7.2 KB (added by jtsternberg, 13 years ago)

Incorporating 'show_taxonomy_columns' in the register_post_type function as well as setting up the columns

  • wp-includes/post.php

     
    977977        $defaults = array(
    978978                'labels' => array(), 'description' => '', 'publicly_queryable' => null, 'exclude_from_search' => null,
    979979                'capability_type' => 'post', 'capabilities' => array(), 'map_meta_cap' => null,
    980                 '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'hierarchical' => false,
     980                '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'hierarchical' => false, 'show_taxonomy_columns' => false,
    981981                'public' => false, 'rewrite' => true, 'has_archive' => false, 'query_var' => true,
    982982                'supports' => array(), 'register_meta_box_cb' => null,
    983983                'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null,
  • wp-admin/includes/screen.php

     
    2323        if ( ! isset( $column_headers[ $screen->id ] ) )
    2424                $column_headers[ $screen->id ] = apply_filters( 'manage_' . $screen->id . '_columns', array() );
    2525
    26         return $column_headers[ $screen->id ];
     26        $tax_columns = ( $screen->post_type ) ? get_taxonomy_column_headers( $screen ) : array();
     27
     28        return array_merge( $column_headers[ $screen->id ], $tax_columns );
    2729}
    2830
    2931/**
     32 * Get a list of registered taxonomy column headers.
     33 *
     34 * @since 3.5.0
     35 *
     36 * @param object|WP_Screen $screen The screen you want the headers for
     37 * @return array Containing the headers in the format id => UI String
     38 */
     39function get_taxonomy_column_headers( $screen ) {
     40        $columns = array();
     41
     42        $post_type_object = get_post_type_object( $screen->post_type );
     43
     44        if ( $post_type_object->show_taxonomy_columns ) {
     45
     46                if ( is_array( $post_type_object->show_taxonomy_columns ) )
     47                        $taxonomies = $post_type_object->show_taxonomy_columns;
     48                else
     49                        $taxonomies = get_object_taxonomies( $screen->post_type );
     50
     51                if ( empty( $taxonomies ) )
     52                        return $columns;
     53
     54                foreach ( $taxonomies as $registered_taxonomy ) {
     55
     56                        $taxonomy_object = get_taxonomy( $registered_taxonomy );
     57                        $columns[$registered_taxonomy.'_taxonomy_column'] = apply_filters( 'taxonomy_column_header', $taxonomy_object->label, $post_type_object, $taxonomy_object );
     58
     59                }
     60        }
     61        return $columns;
     62}
     63
     64/**
    3065 * Get a list of hidden columns.
    3166 *
    3267 * @since 2.7.0
  • wp-admin/includes/class-wp-posts-list-table.php

     
    469469                $edit_link = get_edit_post_link( $post->ID );
    470470                $title = _draft_or_post_title();
    471471                $post_type_object = get_post_type_object( $post->post_type );
     472                if ( $post_type_object->show_taxonomy_columns ) {
     473                        if ( is_array( $post_type_object->show_taxonomy_columns ) )
     474                                        $taxonomies_columns = $post_type_object->show_taxonomy_columns;
     475                        else
     476                                $taxonomies_columns = get_object_taxonomies( $post_type_object->name );
     477                }
    472478                $can_edit_post = current_user_can( $post_type_object->cap->edit_post, $post->ID );
    473479
    474480                $alternate = 'alternate' == $alternate ? '' : 'alternate';
     
    529535                                }
    530536                                else {
    531537                                        $attributes = 'class="post-title page-title column-title"' . $style;
    532 
     538
    533539                                        $pad = str_repeat( '— ', $level );
    534540?>
    535541                        <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>
     
    604610                        break;
    605611
    606612                        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
     613                        $this->taxonomy_column( array( 'attributes' => $attributes, 'empty' => __( 'Uncategorized' )    ) );
    625614                        break;
    626615
    627616                        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
     617                        $this->taxonomy_column( array( 'taxonomy' => 'post_tag', 'attributes' => $attributes    ) );
    646618                        break;
    647619
     620                        case ( is_array( $taxonomies_columns ) && in_array( $registered_taxonomy = str_replace( '_taxonomy_column', '', $column_name ), $taxonomies_columns ) ) :
     621
     622                        $defaults = array(
     623                                'taxonomy' => $registered_taxonomy,
     624                                'attributes' => $attributes,
     625                        );
     626                        $args = apply_filters( 'taxonomy_column_args', $defaults, $post_type_object, $registered_taxonomy  );
     627
     628                        $this->taxonomy_column( $args );
     629                        break;
     630
    648631                        case 'comments':
    649632                        ?>
    650633                        <td <?php echo $attributes ?>><div class="post-com-count-wrapper">
     
    679662                        ?></td>
    680663                        <?php
    681664                        break;
     665                        }
    682666                }
    683         }
    684667        ?>
    685668                </tr>
    686669        <?php
     
    688671        }
    689672
    690673        /**
     674         * Creates internal taxonomy columns as well as registered taxonomies
     675         *
     676         * @since 3.5.0
     677         */
     678        function taxonomy_column( $atts = array() ) {
     679                global $post;
     680
     681                $defaults = array(
     682                        'taxonomy' => 'category',
     683                        'attributes' => '',
     684                        'empty' => '',
     685                );
     686                $args = wp_parse_args( (array) $atts, $defaults );
     687                extract( $args, EXTR_SKIP );
     688
     689                $attributes = !empty( $attributes ) ? $attributes : 'class="column-'. $taxonomy .'"';
     690                $taxonomy_object = get_taxonomy( $taxonomy );
     691                $empty = !empty( $empty ) ? $empty : __( 'No '. $taxonomy_object->label );
     692
     693                ?>
     694                <td <?php echo $attributes ?>><?php
     695                        $terms = get_the_terms( $post->ID, $taxonomy );
     696                        if ( !empty( $terms ) ) {
     697                                $out = array();
     698                                foreach ( $terms as $t ) {
     699                                        $out[] = sprintf( '<a href="%s">%s</a>',
     700                                                esc_url( add_query_arg( array( 'post_type' => $post->post_type, $taxonomy_object->query_var => $t->slug ), 'edit.php' ) ),
     701                                                esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) )
     702                                        );
     703                                }
     704                                /* translators: used between list items, there is a space after the comma */
     705                                echo join( __( ', ' ), $out );
     706                        } else {
     707                                echo $empty;
     708                        }
     709                ?></td>
     710                <?php
     711        }
     712
     713        /**
    691714         * Outputs the hidden row displayed when inline editing
    692715         *
    693716         * @since 3.1.0