Column hiding for media library. see #7725

git-svn-id: http://svn.automattic.com/wordpress/trunk@8894 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-09-15 17:53:30 +00:00
parent 659463e56d
commit cb6611d1f0
5 changed files with 81 additions and 18 deletions

View File

@ -12,16 +12,25 @@ if ( ! defined('ABSPATH') ) die();
<thead> <thead>
<tr> <tr>
<?php $posts_columns = wp_manage_media_columns(); ?> <?php
<?php foreach($posts_columns as $post_column_key => $column_display_name) { $posts_columns = wp_manage_media_columns();
$hidden = (array) get_user_option( 'manage-media-columns-hidden' );
?>
<?php foreach ($posts_columns as $post_column_key => $column_display_name ) {
if ( 'cb' === $post_column_key ) if ( 'cb' === $post_column_key )
$class = ' class="check-column"'; $class = ' class="check-column"';
elseif ( 'comments' === $post_column_key ) elseif ( 'comments' === $post_column_key )
$class = ' class="num"'; $class = ' class="manage-column column-comments num"';
elseif ( 'modified' === $post_column_key )
$class = ' class="manage-column column-date"';
else else
$class = ''; $class = " class=\"manage-column column-$post_column_key\"";
$style = '';
if ( in_array($post_column_key, $hidden) )
$style = ' style="display:none;"';
?> ?>
<th scope="col"<?php echo $class; ?>><?php echo $column_display_name; ?></th> <th scope="col"<?php echo "id=\"$post_column_key\""; echo $class; echo $style?>><?php echo $column_display_name; ?></th>
<?php } ?> <?php } ?>
</tr> </tr>
@ -44,17 +53,25 @@ if ( empty($att_title) )
<?php <?php
foreach($posts_columns as $column_name=>$column_display_name) { foreach ($posts_columns as $column_name => $column_display_name ) {
$class = "class=\"$column_name column-$column_name\"";
$style = '';
if ( in_array($column_name, $hidden) )
$style = ' style="display:none;"';
$attributes = "$class$style";
switch($column_name) { switch($column_name) {
case 'cb': case 'cb':
?> ?>
<th scope="row" class="check-column"><input type="checkbox" name="media[]" value="<?php the_ID(); ?>" /></th> <th scope="row" <?php echo $attributes ?>><input type="checkbox" name="media[]" value="<?php the_ID(); ?>" /></th>
<?php <?php
break; break;
case 'icon': case 'icon':
$attributes = 'class="post-title column-title"' . $style;
?> ?>
<td class="media-icon"><?php <td class="media-icon"><?php
if ( $thumb = wp_get_attachment_image( $post->ID, array(80, 60), true ) ) { if ( $thumb = wp_get_attachment_image( $post->ID, array(80, 60), true ) ) {
@ -72,7 +89,7 @@ foreach($posts_columns as $column_name=>$column_display_name) {
case 'media': case 'media':
?> ?>
<td><strong><a href="<?php echo get_edit_post_link( $post->ID ); ?>" title="<?php echo attribute_escape(sprintf(__('Edit "%s"'), $att_title)); ?>"><?php echo $att_title; ?></a></strong><br /> <td <?php echo $attributes ?>><strong><a href="<?php echo get_edit_post_link( $post->ID ); ?>" title="<?php echo attribute_escape(sprintf(__('Edit "%s"'), $att_title)); ?>"><?php echo $att_title; ?></a></strong><br />
<?php echo strtoupper(preg_replace('/^.*?\.(\w+)$/', '$1', get_attached_file($post->ID))); ?> <?php echo strtoupper(preg_replace('/^.*?\.(\w+)$/', '$1', get_attached_file($post->ID))); ?>
<p> <p>
<a href="media.php?action=edit&amp;attachment_id=<?php the_ID(); ?>" title="<?php echo attribute_escape(sprintf(__('Edit "%s"'), $att_title)); ?>"><?php _e('Edit'); ?></a> | <a href="media.php?action=edit&amp;attachment_id=<?php the_ID(); ?>" title="<?php echo attribute_escape(sprintf(__('Edit "%s"'), $att_title)); ?>"><?php _e('Edit'); ?></a> |
@ -86,7 +103,7 @@ foreach($posts_columns as $column_name=>$column_display_name) {
case 'tags': case 'tags':
?> ?>
<td><?php <td <?php echo $attributes ?>><?php
$tags = get_the_tags(); $tags = get_the_tags();
if ( !empty( $tags ) ) { if ( !empty( $tags ) ) {
$out = array(); $out = array();
@ -102,7 +119,7 @@ foreach($posts_columns as $column_name=>$column_display_name) {
case 'desc': case 'desc':
?> ?>
<td><?php echo has_excerpt() ? $post->post_excerpt : ''; ?></td> <td <?php echo $attributes ?>><?php echo has_excerpt() ? $post->post_excerpt : ''; ?></td>
<?php <?php
break; break;
@ -123,7 +140,7 @@ foreach($posts_columns as $column_name=>$column_display_name) {
} }
} }
?> ?>
<td><?php echo $h_time ?></td> <td <?php echo $attributes ?>><?php echo $h_time ?></td>
<?php <?php
break; break;
@ -136,19 +153,20 @@ foreach($posts_columns as $column_name=>$column_display_name) {
$title = $parent_title; $title = $parent_title;
} }
?> ?>
<td><strong><a href="<?php echo get_edit_post_link( $post->post_parent ); ?>"><?php echo $title ?></a></strong>, <?php echo get_the_time(__('Y/m/d')); ?></td> <td <?php echo $attributes ?>><strong><a href="<?php echo get_edit_post_link( $post->post_parent ); ?>"><?php echo $title ?></a></strong>, <?php echo get_the_time(__('Y/m/d')); ?></td>
<?php <?php
} else { } else {
?> ?>
<td>&nbsp;</td> <td <?php echo $attributes ?>>&nbsp;</td>
<?php <?php
} }
break; break;
case 'comments': case 'comments':
$attributes = 'class="comments column-comments num"' . $style;
?> ?>
<td class="num"><div class="post-com-count-wrapper"> <td <?php echo $attributes ?>><div class="post-com-count-wrapper">
<?php <?php
$left = get_pending_comments_num( $post->ID ); $left = get_pending_comments_num( $post->ID );
$pending_phrase = sprintf( __('%s pending'), number_format( $left ) ); $pending_phrase = sprintf( __('%s pending'), number_format( $left ) );
@ -164,7 +182,7 @@ foreach($posts_columns as $column_name=>$column_display_name) {
case 'actions': case 'actions':
?> ?>
<td> <td <?php echo $attributes ?>>
<a href="media.php?action=edit&amp;attachment_id=<?php the_ID(); ?>" title="<?php echo attribute_escape(sprintf(__('Edit "%s"'), $att_title)); ?>"><?php _e('Edit'); ?></a> | <a href="media.php?action=edit&amp;attachment_id=<?php the_ID(); ?>" title="<?php echo attribute_escape(sprintf(__('Edit "%s"'), $att_title)); ?>"><?php _e('Edit'); ?></a> |
<a href="<?php the_permalink(); ?>"><?php _e('Get permalink'); ?></a> <a href="<?php the_permalink(); ?>"><?php _e('Get permalink'); ?></a>
</td> </td>
@ -173,7 +191,7 @@ foreach($posts_columns as $column_name=>$column_display_name) {
default: default:
?> ?>
<td><?php do_action('manage_media_custom_column', $column_name, $id); ?></td> <td <?php echo $attributes ?>><?php do_action('manage_media_custom_column', $column_name, $id); ?></td>
<?php <?php
break; break;
} }

View File

@ -371,7 +371,8 @@ function wp_manage_media_columns() {
// $posts_columns['desc'] = _c('Description|media column header'); // $posts_columns['desc'] = _c('Description|media column header');
$posts_columns['date'] = _c('Date Added|media column header'); $posts_columns['date'] = _c('Date Added|media column header');
$posts_columns['parent'] = _c('Appears with|media column header'); $posts_columns['parent'] = _c('Appears with|media column header');
$posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="images/comment-grey-bubble.png" /></div>'; //$posts_columns['comments'] = '<div class="vers"><img alt="Comments" src="images/comment-grey-bubble.png" /></div>';
$posts_columns['comments'] = __('Comments');
// $posts_columns['actions'] = _c('Actions|media column header'); // $posts_columns['actions'] = _c('Actions|media column header');
$posts_columns = apply_filters('manage_media_columns', $posts_columns); $posts_columns = apply_filters('manage_media_columns', $posts_columns);
@ -1992,8 +1993,11 @@ function manage_columns_prefs($page) {
foreach ( $columns as $column => $title ) { foreach ( $columns as $column => $title ) {
// Can't hide these // Can't hide these
if ( 'cb' == $column || 'title' == $column || 'name' == $column ) if ( 'cb' == $column || 'title' == $column || 'name' == $column || 'media' == $column )
continue; continue;
if ( empty($title) )
continue;
if ( 'comments' == $column ) if ( 'comments' == $column )
$title = __('Comments'); $title = __('Comments');
$id = "$column-hide"; $id = "$column-hide";

24
wp-admin/js/media.js Normal file
View File

@ -0,0 +1,24 @@
jQuery(document).ready( function($) {
columns.init('media');
// Edit Settings
$('#show-settings-link').click(function () {
$('#edit-settings').slideDown('normal', function(){
$('#show-settings-link').hide();
$('#hide-settings-link').show();
});
$('#show-settings').addClass('show-settings-opened');
return false;
});
$('#hide-settings-link').click(function () {
$('#edit-settings').slideUp('normal', function(){
$('#hide-settings-link').hide();
$('#show-settings-link').show();
$('#show-settings').removeClass('show-settings-opened');
});
return false;
});
});

View File

@ -48,6 +48,7 @@ if ( isset($_GET['action']) && isset($_GET['media']) ) {
$title = __('Media Library'); $title = __('Media Library');
$parent_file = 'edit.php'; $parent_file = 'edit.php';
wp_enqueue_script( 'admin-forms' ); wp_enqueue_script( 'admin-forms' );
wp_enqueue_script('media');
list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
@ -74,6 +75,19 @@ if ( !isset( $_GET['paged'] ) )
<div class="wrap"> <div class="wrap">
<form id="posts-filter" action="" method="get"> <form id="posts-filter" action="" method="get">
<div id="show-settings"><a href="#edit_settings" id="show-settings-link" class="hide-if-no-js"><?php _e('Advanced Options') ?></a>
<a href="#edit_settings" id="hide-settings-link" class="hide-if-js hide-if-no-js"><?php _e('Hide Options') ?></a></div>
<div id="edit-settings" class="hide-if-js hide-if-no-js">
<div id="edit-settings-wrap">
<h5><?php _e('Show on screen') ?></h5>
<div class="metabox-prefs">
<?php manage_columns_prefs('media') ?>
<br class="clear" />
</div></div>
</div>
<h2><?php <h2><?php
if ( is_singular() ) { if ( is_singular() ) {
printf(__('Comments on %s'), apply_filters( "the_title", $post->post_title)); printf(__('Comments on %s'), apply_filters( "the_title", $post->post_title));
@ -214,6 +228,8 @@ foreach ($arc_result as $arc_row) {
<?php include( 'edit-attachment-rows.php' ); ?> <?php include( 'edit-attachment-rows.php' ); ?>
<?php wp_nonce_field( 'hiddencolumns', 'hiddencolumnsnonce', false ); ?>
</form> </form>
<div id="ajax-response"></div> <div id="ajax-response"></div>

View File

@ -263,6 +263,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'posts', '/wp-admin/js/posts.js', array('columns'), '20080910' ); $scripts->add( 'posts', '/wp-admin/js/posts.js', array('columns'), '20080910' );
$scripts->add( 'pages', '/wp-admin/js/pages.js', array('columns'), '20080910' ); $scripts->add( 'pages', '/wp-admin/js/pages.js', array('columns'), '20080910' );
$scripts->add( 'links', '/wp-admin/js/links.js', array('columns'), '20080913' ); $scripts->add( 'links', '/wp-admin/js/links.js', array('columns'), '20080913' );
$scripts->add( 'media', '/wp-admin/js/media.js', array('columns'), '20080915' );
$scripts->add( 'columns', '/wp-admin/js/columns.js', false, '20080910' ); $scripts->add( 'columns', '/wp-admin/js/columns.js', false, '20080910' );
$scripts->localize( 'columns', 'columnsL10n', array( $scripts->localize( 'columns', 'columnsL10n', array(