Make WordPress Core


Ignore:
Timestamp:
09/24/2010 01:35:06 PM (14 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.