Column hiding for users. see #7725

git-svn-id: http://svn.automattic.com/wordpress/trunk@8936 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-09-19 05:31:00 +00:00
parent e06c648ec2
commit a03f02f4b3
4 changed files with 96 additions and 25 deletions

View File

@ -555,6 +555,16 @@ function get_column_headers($page) {
);
return apply_filters('manage_link_categories_columns', $columns);
case 'user':
$columns = array(
'cb' => '<input type="checkbox" />',
'username' => __('Username'),
'name' => __('Name'),
'email' => __('E-mail'),
'role' => __('Role'),
'posts' => __('Posts')
);
return apply_filters('manage_users_columns', $columns);
}
return $columns;
@ -1390,21 +1400,49 @@ function user_row( $user_object, $style = '', $role = '' ) {
$edit = '<strong>' . $user_object->user_login . '</strong>';
}
$role_name = isset($wp_roles->role_names[$role]) ? translate_with_context($wp_roles->role_names[$role]) : __('None');
$r = "<tr id='user-$user_object->ID'$style>
<th scope='row' class='check-column'><input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' /></th>
<td>$edit</td>
<td>$user_object->first_name $user_object->last_name</td>
<td><a href='mailto:$email' title='" . sprintf( __('e-mail: %s' ), $email ) . "'>$email</a></td>
<td>$role_name</td>";
$r .= "\n\t\t<td class='num'>";
if ( $numposts > 0 ) {
$r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
$r .= $numposts;
$r .= '</a>';
} else {
$r .= 0;
$r = "<tr id='user-$user_object->ID'$style>";
$columns = get_column_headers('user');
$hidden = (array) get_user_option( 'manage-user-columns-hidden' );
foreach ( $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) {
case 'cb':
$r .= "<th scope='row' class='check-column'><input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' /></th>";
break;
case 'username':
$r .= "<td $attributes>$edit</td>";
break;
case 'name':
$r .= "<td $attributes>$user_object->first_name $user_object->last_name</td>";
break;
case 'email':
$r .= "<td $attributes><a href='mailto:$email' title='" . sprintf( __('e-mail: %s' ), $email ) . "'>$email</a></td>";
break;
case 'role':
$r .= "<td $attributes>$role_name</td>";
break;
case 'posts':
$attributes = 'class="posts column-posts num"' . $style;
$r .= "<td $attributes>";
if ( $numposts > 0 ) {
$r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
$r .= $numposts;
$r .= '</a>';
} else {
$r .= 0;
}
$r .= "</td>";
}
}
$r .= "</td>\n\t</tr>";
$r .= '</tr>';
return $r;
}
@ -2181,7 +2219,7 @@ function manage_columns_prefs($page) {
foreach ( $columns as $column => $title ) {
// Can't hide these
if ( 'cb' == $column || 'title' == $column || 'name' == $column || 'media' == $column )
if ( 'cb' == $column || 'title' == $column || 'name' == $column || 'username' == $column || 'media' == $column )
continue;
if ( empty($title) )
continue;

View File

@ -1 +1,26 @@
jQuery( function($) { $('#users').wpList(); } );
jQuery( function($) {
$('#users').wpList();
columns.init('user');
// 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

@ -261,6 +261,19 @@ if ( ! empty($messages) ) {
} ?>
<div class="wrap">
<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('user') ?>
<br class="clear" />
</div></div>
</div>
<form id="posts-filter" action="" method="get">
<?php if ( $wp_user_search->is_search() ) : ?>
<h2><?php printf( current_user_can('create_users') ? __('Users Matching "%2$s" (<a href="%1$s">Add New</a>)') : __('Add New'), '#add-new-user', wp_specialchars($wp_user_search->search_term) ); ?></h2>
@ -350,12 +363,7 @@ unset($role_links);
<table class="widefat">
<thead>
<tr class="thead">
<th scope="col" class="check-column"><input type="checkbox" /></th>
<th><?php _e('Username') ?></th>
<th><?php _e('Name') ?></th>
<th><?php _e('E-mail') ?></th>
<th><?php _e('Role') ?></th>
<th class="num"><?php _e('Posts') ?></th>
<?php print_column_headers('user') ?>
</tr>
</thead>
<tbody id="users" class="list:user user-list">
@ -383,7 +391,7 @@ foreach ( $wp_user_search->get_results() as $userid ) {
</div>
<?php endif; ?>
<?php wp_nonce_field( 'hiddencolumns', 'hiddencolumnsnonce', false ); ?>
</form>
</div>

View File

@ -150,7 +150,7 @@ function wp_default_scripts( &$scripts ) {
'how' => __('Separate multiple categories with commas.')
) );
$scripts->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists', 'columns'), '20071031' );
$scripts->add( 'admin-tags', '/wp-admin/js/tags.js', array('wp-lists', 'columns'), '20071031' );
$scripts->add( 'admin-tags', '/wp-admin/js/tags.js', array('wp-lists', 'columns'), '20080918' );
$scripts->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('wp-lists'), '20070823' );
$scripts->add( 'password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '20080824' );
$scripts->localize( 'password-strength-meter', 'pwsL10n', array(
@ -166,7 +166,7 @@ function wp_default_scripts( &$scripts ) {
'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']),
'hotkeys_highlight_last' => isset($_GET['hotkeys_highlight_last']),
) );
$scripts->add( 'admin-users', '/wp-admin/js/users.js', array('wp-lists'), '20070823' );
$scripts->add( 'admin-users', '/wp-admin/js/users.js', array('wp-lists', 'columns'), '20080918' );
$scripts->add( 'admin-forms', '/wp-admin/js/forms.js', array('jquery'), '20080729');
$scripts->add( 'xfn', '/wp-admin/js/xfn.js', false, '3517' );
$scripts->add( 'upload', '/wp-admin/js/upload.js', array('jquery'), '20070518' );