WordPress.org

Make WordPress Core

Changeset 15653


Ignore:
Timestamp:
09/24/2010 01:35:06 PM (8 years ago)
Author:
scribu
Message:

Column headers revamp:

  • undeprecate get_column_headers()
  • undeprecate get_hidden_columns()
  • in WP_List_Table, rename get_column_headers() to get_column_info()
  • remove $taxonomy argument from single_row()
  • merge manage_columns_prefs() into screen_meta()

Fixes #14952. Fixes #14776.

Location:
trunk/wp-admin/includes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/default-list-tables.php

    r15644 r15653  
    455455    <?php
    456456
    457         list( $columns, $hidden ) = $this->get_column_headers();
     457        list( $columns, $hidden ) = $this->get_column_info();
    458458
    459459        foreach ( $columns as $column_name => $column_display_name ) {
     
    677677        }
    678678
    679         list( $columns, $hidden ) = $this->get_column_headers();
     679        list( $columns, $hidden ) = $this->get_column_info();
    680680
    681681        $col_count = count( $columns ) - count( $hidden );
     
    11631163<?php
    11641164
    1165 list( $columns, $hidden ) = $this->get_column_headers();
     1165list( $columns, $hidden ) = $this->get_column_info();
    11661166foreach ( $columns as $column_name => $column_display_name ) {
    11671167    $class = "class='$column_name column-$column_name'";
     
    17281728            return;
    17291729
    1730         list( $columns, $hidden ) = $this->get_column_headers();
     1730        list( $columns, $hidden ) = $this->get_column_info();
    17311731
    17321732        $col_count = count( $columns ) - count( $hidden );
     
    19971997        $avatar = get_avatar( $user_object->ID, 32 );
    19981998
    1999         list( $columns, $hidden ) = $this->get_column_headers();
     1999        list( $columns, $hidden ) = $this->get_column_info();
    20002000
    20012001        foreach ( $columns as $column_name => $column_display_name ) {
     
    26492649<?php
    26502650
    2651             list( $columns, $hidden ) = $this->get_column_headers();
     2651            list( $columns, $hidden ) = $this->get_column_info();
    26522652
    26532653            foreach ( $columns as $column_name => $column_display_name ) {
     
    28702870            $blogname = ( is_subdomain_install() ) ? str_replace( '.'.$current_site->domain, '', $blog['domain'] ) : $blog['path'];
    28712871
    2872             list( $columns, $hidden ) = $this->get_column_headers();
     2872            list( $columns, $hidden ) = $this->get_column_info();
    28732873
    28742874            foreach ( $columns as $column_name => $column_display_name ) {
     
    31183118            <?php
    31193119
    3120             list( $columns, $hidden ) = $this->get_column_headers();
     3120            list( $columns, $hidden ) = $this->get_column_info();
    31213121
    31223122            foreach ( $columns as $column_name => $column_display_name ) :
  • trunk/wp-admin/includes/deprecated.php

    r15542 r15653  
    371371
    372372/**
    373  * Get the column headers for a screen
     373 * Prints column headers for a particular screen.
    374374 *
    375375 * @since 2.7.0
    376376 * @deprecated 3.1.0
    377377 * @deprecated Use WP_List_Table
    378  *
    379  * @param string|object $screen The screen you want the headers for
    380  * @return array Containing the headers in the format id => UI String
    381  */
    382 function get_column_headers($screen) {
     378 */
     379function print_column_headers($screen, $id = true) {
    383380    _deprecated_function( __FUNCTION__, '3.1', 'WP_List_Table' );
    384381
     
    387384        $wp_list_table = new _WP_List_Table_Compat($screen);
    388385
    389     list( $columns ) = $wp_list_table->get_column_headers();
    390 
    391     return $columns;
    392 }
    393 
    394 /**
    395  * Prints column headers for a particular screen.
    396  *
    397  * @since 2.7.0
    398  * @deprecated 3.1.0
    399  * @deprecated Use WP_List_Table
    400  */
    401 function print_column_headers($screen, $id = true) {
    402     _deprecated_function( __FUNCTION__, '3.1', 'WP_List_Table' );
    403 
    404     global $wp_list_table;
    405     if ( !is_a($wp_list_table, 'WP_List_Table') )
    406         $wp_list_table = new _WP_List_Table_Compat($screen);
    407 
    408386    $wp_list_table->print_column_headers($id);
    409 }
    410 
    411 /**
    412  * Gets hidden column names for a particular screen.
    413  *
    414  * @since 2.7.0
    415  * @deprecated 3.1.0
    416  * @deprecated Use WP_List_Table
    417  *
    418  * @param string $screen
    419  * @return array
    420  */
    421 function get_hidden_columns($screen) {
    422     _deprecated_function( __FUNCTION__, '3.1', 'WP_List_Table' );
    423 
    424     global $wp_list_table;
    425     if ( !is_a($wp_list_table, 'WP_List_Table') )
    426         $wp_list_table = new _WP_List_Table_Compat($screen);
    427 
    428     return $wp_list_table->get_hidden_columns();
    429387}
    430388
  • trunk/wp-admin/includes/list-table.php

    r15642 r15653  
    7070     */
    7171    function WP_List_Table( $args ) {
     72        global $_wp_column_headers;
     73
     74        $_wp_column_headers = $this->get_columns();
    7275
    7376        $args = wp_parse_args( $args, array(
     
    8285        if ( is_string( $this->_screen ) )
    8386            $this->_screen = convert_to_screen( $this->_screen );
     87
     88        add_filter( 'manage_' . $this->_screen->id . '_columns', array( $this, 'get_columns' ) );
    8489
    8590        if ( !$args['plural'] )
     
    515520
    516521    /**
    517      * Get a list of hidden columns.
    518      *
    519      * @since 3.1.0
    520      * @access private
     522     * Get a list of all, hidden and sortable columns, with filter applied
     523     *
     524     * @since 3.1.0
     525     * @access protected
    521526     *
    522527     * @return array
    523528     */
    524     function get_hidden_columns() {
    525         return (array) get_user_option( 'manage' . $this->_screen->id. 'columnshidden' );
    526     }
    527 
    528     /**
    529      * Get a list of all, hidden and sortable columns, with filter applied
    530      *
    531      * @since 3.1.0
    532      * @access protected
    533      *
    534      * @return array
    535      */
    536     function get_column_headers() {
     529    function get_column_info() {
    537530        if ( !isset( $this->_column_headers ) ) {
    538             $columns = apply_filters( 'manage_' . $this->_screen->id . '_columns', $this->get_columns() );
     531            $columns = get_column_headers( $this->_screen );
     532            $hidden = get_hidden_columns( $this->_screen );
    539533            $sortable = apply_filters( 'manage_' . $this->_screen->id . '_sortable_columns', $this->get_sortable_columns() );
    540             $hidden = $this->get_hidden_columns();
    541534
    542535            $this->_column_headers = array( $columns, $hidden, $sortable );
     
    557550        $screen = $this->_screen;
    558551
    559         list( $columns, $hidden, $sortable ) = $this->get_column_headers();
     552        list( $columns, $hidden, $sortable ) = $this->get_column_info();
    560553
    561554        $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     
    747740     */
    748741    function single_row_columns( $item ) {
    749         list( $columns, $hidden ) = $this->get_column_headers();
     742        list( $columns, $hidden ) = $this->get_column_info();
    750743
    751744        foreach ( $columns as $column_name => $column_display_name ) {
  • trunk/wp-admin/includes/template.php

    r15590 r15653  
    218218        echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', $checked, '/> ', $name, "</label></li>";
    219219    }
     220}
     221
     222/**
     223 * Get the column headers for a screen
     224 *
     225 * @since 2.7.0
     226 *
     227 * @param string|object $screen The screen you want the headers for
     228 * @return array Containing the headers in the format id => UI String
     229 */
     230function get_column_headers( $screen ) {
     231    if ( is_string( $screen ) )
     232        $screen = convert_to_screen( $screen );
     233
     234    global $_wp_column_headers;
     235
     236    if ( !isset( $_wp_column_headers[ $screen->id ] ) ) {
     237        $_wp_column_headers[ $screen->id ] = apply_filters( 'manage_' . $screen->id . '_columns', $_wp_column_headers );
     238    }
     239
     240    return $_wp_column_headers[ $screen->id ];
     241}
     242
     243/**
     244 * Get a list of hidden columns.
     245 *
     246 * @since 2.7.0
     247 *
     248 * @param string|object $screen The screen you want the hidden columns for
     249 * @return array
     250 */
     251function get_hidden_columns( $screen ) {
     252    if ( is_string( $screen ) )
     253        $screen = convert_to_screen( $screen );
     254
     255    return (array) get_user_option( 'manage' . $screen->id . 'columnshidden' );
    220256}
    221257
     
    296332    $wp_list_table = get_list_table('comments');
    297333
    298     $columns = $wp_list_table->get_column_headers();
    299     $hidden = array_intersect( array_keys( $columns ), array_filter( $wp_list_table->get_hidden_columns() ) );
     334    list ( $columns, $hidden ) = $wp_list_table->get_column_info();
     335    $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
    300336    $col_count = count($columns) - count($hidden);
    301337
     
    12841320    }
    12851321    echo $output;
    1286 }
    1287 
    1288 /**
    1289  * {@internal Missing Short Description}}
    1290  *
    1291  * @since unknown
    1292  *
    1293  * @param unknown_type $page
    1294  */
    1295 function manage_columns_prefs( $page ) {
    1296     global $wp_list_table;
    1297 
    1298     list( $columns, $hidden ) = $wp_list_table->get_column_headers();
    1299 
    1300     $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username');
    1301 
    1302     foreach ( $columns as $column => $title ) {
    1303         // Can't hide these for they are special
    1304         if ( in_array( $column, $special ) )
    1305             continue;
    1306         if ( empty( $title ) )
    1307             continue;
    1308 
    1309         if ( 'comments' == $column )
    1310             $title = __( 'Comments' );
    1311         $id = "$column-hide";
    1312         echo '<label for="' . $id . '">';
    1313         echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . (! in_array($column, $hidden) ? ' checked="checked"' : '') . ' />';
    1314         echo "$title</label>\n";
    1315     }
    13161322}
    13171323
     
    16351641        $screen = convert_to_screen($screen);
    16361642
    1637     if ( is_a($wp_list_table, 'WP_List_Table') )
    1638         list( $screen_columns ) = $wp_list_table->get_column_headers();
     1643    $columns = get_column_headers( $screen );
     1644    $hidden = get_hidden_columns( $screen );
     1645
    16391646    $meta_screens = array('index' => 'dashboard');
    16401647
     
    16451652
    16461653    $show_screen = false;
    1647     if ( !empty($wp_meta_boxes[$screen->id]) || !empty($screen_columns) )
     1654    if ( !empty($wp_meta_boxes[$screen->id]) || !empty($columns) )
    16481655        $show_screen = true;
    16491656
     
    16781685        </div>
    16791686        <?php endif;
    1680         if ( ! empty($screen_columns) ) : ?>
    1681         <h5><?php echo ( isset( $screen_columns['_title'] ) ?  $screen_columns['_title'] :  _x('Show on screen', 'Columns') ) ?></h5>
     1687        if ( ! empty($columns) ) : ?>
     1688        <h5><?php echo ( isset( $columns['_title'] ) ?  $columns['_title'] :  _x('Show on screen', 'Columns') ) ?></h5>
    16821689        <div class="metabox-prefs">
    1683             <?php manage_columns_prefs($screen); ?>
     1690<?php
     1691    $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username');
     1692
     1693    foreach ( $columns as $column => $title ) {
     1694        // Can't hide these for they are special
     1695        if ( in_array( $column, $special ) )
     1696            continue;
     1697        if ( empty( $title ) )
     1698            continue;
     1699
     1700        if ( 'comments' == $column )
     1701            $title = __( 'Comments' );
     1702        $id = "$column-hide";
     1703        echo '<label for="' . $id . '">';
     1704        echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( !in_array($column, $hidden), true, false ) . ' />';
     1705        echo "$title</label>\n";
     1706    }
     1707?>
    16841708            <br class="clear" />
    16851709        </div>
Note: See TracChangeset for help on using the changeset viewer.