Make WordPress Core

Changeset 8858


Ignore:
Timestamp:
09/11/2008 01:46:30 AM (18 years ago)
Author:
ryan
Message:

Column hiding for manage posts. see #7725

Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r8857 r8858  
    705705                update_usermeta($current_user->ID, 'meta-box-hidden_'.$page, $hidden);
    706706break;
     707case 'hidden-columns' :
     708        check_ajax_referer( 'hiddencolumns', 'hiddencolumnsnonce' );
     709        $hidden = isset( $_POST['hidden'] )? $_POST['hidden'] : '';
     710        $hidden = explode( ',', $_POST['hidden'] );
     711        $page = isset( $_POST['page'] )? $_POST['page'] : '';
     712        if ( !preg_match( '/^[a-z-]+$/', $page ) ) {
     713                die(-1);
     714        }
     715        $current_user = wp_get_current_user();
     716        if ( is_array($hidden) )
     717                update_usermeta($current_user->ID, "manage-$page-columns-hidden", $hidden);
    707718case 'get-permalink':
    708719        check_ajax_referer( 'getpermalink', 'getpermalinknonce' );
  • trunk/wp-admin/edit-post-rows.php

    r8857 r8858  
    1313        <tr>
    1414
    15 <?php $posts_columns = wp_manage_posts_columns(); ?>
    16 <?php foreach($posts_columns as $post_column_key => $column_display_name) {
     15<?php
     16$posts_columns = wp_manage_posts_columns();
     17$hidden = (array) get_user_option( 'manage-post-columns-hidden' );
     18foreach ( $posts_columns as $post_column_key => $column_display_name ) {
    1719        if ( 'cb' === $post_column_key )
    1820                $class = ' class="check-column"';
    1921        elseif ( 'comments' === $post_column_key )
    20                 $class = ' class="num"';
     22                $class = ' class="manage-column column-comments num"';
     23        elseif ( 'modified' === $post_column_key )
     24                $class = ' class="manage-column column-date"';
    2125        else
    22                 $class = '';
     26                $class = " class=\"manage-column column-$post_column_key\"";
     27
     28        $style = '';
     29        if ( in_array($post_column_key, $hidden) )
     30                $style = ' style="display:none;"';
    2331?>
    24         <th scope="col"<?php echo $class; ?>><?php echo $column_display_name; ?></th>
     32        <th scope="col"<?php echo "id=\"$post_column_key\""; echo $class; echo $style?>><?php echo $column_display_name; ?></th>
    2533<?php } ?>
    2634
  • trunk/wp-admin/edit.php

    r8857 r8858  
    5252wp_enqueue_script('admin-forms');
    5353wp_enqueue_script('inline-edit');
    54 
     54wp_enqueue_script('posts');
    5555
    5656list($post_stati, $avail_post_stati) = wp_edit_posts_query();
    … …  
    7575
    7676<form id="posts-filter" action="" method="get">
     77
     78<div id="show-settings"><a href="#edit_settings" id="show-settings-link" class="hide-if-no-js"><?php _e('Show Settings') ?></a>
     79<a href="#edit_settings" id="hide-settings-link" class="hide-if-js hide-if-no-js"><?php _e('Hide Settings') ?></a></div>
     80
     81<div id="edit-settings" class="hide-if-js hide-if-no-js">
     82<div id="edit-settings-wrap">
     83<h5><?php _e('Show on screen') ?></h5>
     84<div class="metabox-prefs">
     85<?php manage_columns_prefs('post') ?>
     86<br class="clear" />
     87</div></div>
     88</div>
     89
    7790<h2><?php
    7891if ( is_single() ) {
    … …  
    227240<?php include( 'edit-post-rows.php' ); ?>
    228241
     242<?php wp_nonce_field( 'hiddencolumns', 'hiddencolumnsnonce', false ); ?>
     243
    229244</form>
    230245
  • trunk/wp-admin/includes/template.php

    r8857 r8858  
    417417        echo '<tr id="inline-edit" style="display: none">';
    418418        $columns = $type == 'post' ? wp_manage_posts_columns() : wp_manage_pages_columns();
     419        $hidden = (array) get_user_option( "manage-$type-columns-hidden" );
    419420        foreach($columns as $column_name=>$column_display_name) {
     421                $class = "class=\"$column_name column-$column_name\"";
     422
     423                $style = '';
     424                if ( in_array($column_name, $hidden) )
     425                        $style = ' style="display:none;"';
     426
     427                $attributes = "$class$style";
    420428
    421429                switch($column_name) {
    … …  
    427435
    428436                        case 'modified':
    429                         case 'date': ?>
    430                                 <td class="date">
     437                        case 'date':
     438                                $attributes = 'class="date column-date"' . $style;
     439                        ?>
     440                                <td class="date"<?php echo $style ?>>
    431441                                        <?php touch_time(1, 1, 4, 1); ?>
    432442                                </td>
    … …  
    434444                                break;
    435445
    436                         case 'title': ?>
    437                                 <td class="<?php echo $type ?>-title">
     446                        case 'title':
     447                                $attributes = "class=\"$type-title column-title\"" . $style;
     448                        ?>
     449                                <td <?php echo $attributes ?>>
    438450                                        <div class="title">
    439451                                                <input type="text" name="post_title" class="title" value="" /><br />
    440452                                                <label><?php _e('Slug'); ?></label><input type="text" name="post_name" value="" class="slug" />
    441453                                        </div>
    442                                         <?php if($type == 'page'): ?>
     454                                        <?php if ($type == 'page'): ?>
    443455                                        <div class="other">
    444456                                                <label><?php _e('Parent'); ?></label>
    … …  
    476488
    477489                        case 'categories': ?>
    478                                 <td class="categories">
     490                                <td <?php echo $attributes ?>>
    479491                                        <ul class="categories">
    480492                                                <?php wp_category_checklist() ?>
    … …  
    485497
    486498                        case 'tags': ?>
    487                                 <td class="tags">
     499                                <td <?php echo $attributes ?>>
    488500                                        <textarea name="tags_input"></textarea>
    489501                                </td>
    … …  
    491503                                break;
    492504
    493                         case 'comments': ?>
    494                                 <td class="comments num">
     505                        case 'comments':
     506                                $attributes = 'class="comments column-comments num"' . $style;
     507                         ?>
     508                                <td <?php echo $attributes ?>>
    495509                                        <input title="Allow Comments" type="checkbox" name="comment_status" value="open" /><br />
    496510                                        <input title="Allow Pings" type="checkbox" name="ping_status" value="open" />
    … …  
    500514
    501515                        case 'author': ?>
    502                                 <td class="author">
     516                                <td <?php echo $attributes ?>>
    503517                                        <?php
    504518                                        $authors = get_editable_user_ids( $current_user->id ); // TODO: ROLE SYSTEM
    … …  
    514528
    515529                        case 'status': ?>
    516                                 <td class="status">
     530                                <td <?php echo $attributes ?>>
    517531                                        <select name="post_status">
    518532                                                <?php if ( current_user_can('publish_posts') ) : // Contributors only get "Unpublished" and "Pending Review" ?>
    … …  
    675689<?php
    676690        $posts_columns = wp_manage_posts_columns();
    677         foreach($posts_columns as $column_name=>$column_display_name) {
    678 
    679                 switch($column_name) {
     691        $hidden = (array) get_user_option( 'manage-post-columns-hidden' );
     692        foreach ( $posts_columns as $column_name=>$column_display_name ) {
     693                $class = "class=\"$column_name column-$column_name\"";
     694
     695                $style = '';
     696                if ( in_array($column_name, $hidden) )
     697                        $style = ' style="display:none;"';
     698
     699                $attributes = "$class$style";
     700
     701                switch ($column_name) {
    680702
    681703                case 'cb':
    … …  
    687709                case 'modified':
    688710                case 'date':
     711                        $attributes = 'class="date column-date"' . $style;
    689712                        if ( '0000-00-00 00:00:00' == $post->post_date && 'date' == $column_name ) {
    690713                                $t_time = $h_time = __('Unpublished');
    … …  
    710733
    711734                        if ( 'excerpt' == $mode ) { ?>
    712                 <td class="date"><?php echo apply_filters('post_date_column_time', $t_time, $post, $column_name, $mode) ?></td>
     735                <td <?php echo $attributes ?>><?php echo apply_filters('post_date_column_time', $t_time, $post, $column_name, $mode) ?></td>
    713736                <?php } else { ?>
    714                 <td class="date"><abbr title="<?php echo $t_time ?>"><?php echo apply_filters('post_date_column_time', $h_time, $post, $column_name, $mode) ?></abbr></td>
     737                <td <?php echo $attributes ?>><abbr title="<?php echo $t_time ?>"><?php echo apply_filters('post_date_column_time', $h_time, $post, $column_name, $mode) ?></abbr></td>
    715738                <?php }
    716739                break;
    717740
    718741                case 'title':
    719                 ?>
    720                 <td class="post-title"><strong><?php if ( current_user_can( 'edit_post', $post->ID ) ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo attribute_escape(sprintf(__('Edit "%s"'), $title)); ?>"><?php echo $title ?></a><?php } else { echo $title; } ?></strong>
     742                        $attributes = 'class="post-title column-title"' . $style;
     743                ?>
     744                <td <?php echo $attributes ?>><strong><?php if ( current_user_can( 'edit_post', $post->ID ) ) { ?><a class="row-title" href="<?php echo $edit_link; ?>" title="<?php echo attribute_escape(sprintf(__('Edit "%s"'), $title)); ?>"><?php echo $title ?></a><?php } else { echo $title; } ?></strong>
    721745                <?php
    722746                        if ( !empty($post->post_password) ) { _e(' &#8212; <strong>Protected</strong>'); } elseif ('private' == $post->post_status) { _e(' &#8212; <strong>Private</strong>'); }
    … …  
    743767                case 'categories':
    744768                ?>
    745                 <td class="categories"><?php
     769                <td <?php echo $attributes ?>><?php
    746770                        $categories = get_the_category();
    747771                        if ( !empty( $categories ) ) {
    … …  
    759783                case 'tags':
    760784                ?>
    761                 <td class="tags"><?php
     785                <td <?php echo $attributes ?>><?php
    762786                        $tags = get_the_tags();
    763787                        if ( !empty( $tags ) ) {
    … …  
    774798
    775799                case 'comments':
    776                 ?>
    777                 <td class="comments num"><div class="post-com-count-wrapper">
     800                        $attributes = 'class="comments column-comments num"' . $style;
     801                ?>
     802                <td <?php echo $attributes ?>><div class="post-com-count-wrapper">
    778803                <?php
    779804                        $pending_phrase = sprintf( __('%s pending'), number_format( $pending_comments ) );
    … …  
    790815                case 'author':
    791816                ?>
    792                 <td class="author"><a href="edit.php?author=<?php the_author_ID(); ?>"><?php the_author() ?></a></td>
     817                <td <?php echo $attributes ?>><a href="edit.php?author=<?php the_author_ID(); ?>"><?php the_author() ?></a></td>
    793818                <?php
    794819                break;
    … …  
    796821                case 'status':
    797822                ?>
    798                 <td class="status">
     823                <td <?php echo $attributes ?>>
    799824                <a href="<?php the_permalink(); ?>" title="<?php echo attribute_escape(sprintf(__('View "%s"'), $title)); ?>" rel="permalink">
    800825                <?php
    … …  
    19181943}
    19191944
     1945function manage_columns_prefs($page) {
     1946        if ( 'post' == $page )
     1947                $columns = wp_manage_posts_columns();
     1948        elseif ( 'page' == $page )
     1949                $columns = wp_manage_pages_columns();
     1950        elseif ( 'media' == $page )
     1951                $columns = wp_manage_media_columns();
     1952        else return;
     1953
     1954        $hidden = (array) get_user_option( "manage-$page-columns-hidden" );
     1955
     1956        foreach ( $columns as $column => $title ) {
     1957                // Can't hide these
     1958                if ( 'cb' == $column || 'title' == $column )
     1959                        continue;
     1960                if ( 'comments' == $column )
     1961                        $title = __('Comments');
     1962                $id = "$column-hide";
     1963                echo '<label for="' . $id . '">';
     1964                echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . (! in_array($column, $hidden) ? ' checked="checked"' : '') . ' />';
     1965                echo "$title</label>\n";
     1966        }
     1967}
     1968
    19201969?>
  • trunk/wp-includes/script-loader.php

    r8857 r8858  
    258258                        'time' => time()
    259259                ) );
     260
     261                $scripts->add( 'posts', '/wp-admin/js/posts.js', array('columns'), '20080910' );
     262
     263                $scripts->add( 'columns', '/wp-admin/js/columns.js', false, '20080910' );
     264                $scripts->localize( 'columns', 'columnsL10n', array(
     265                        'requestFile' => admin_url('admin-ajax.php'),
     266                ) );
    260267        }
    261268}
Note: See TracChangeset for help on using the changeset viewer.