Permalink
Browse files

* Adds a screen option for number of users per page

* Makes it more obvious when an ajax action is loading
* Doesn't allow current user to remove themself
  • Loading branch information...
1 parent d8d73a0 commit b7fb6bae8210ddde7072b2b48a30711241f8b184 @joshbetz joshbetz committed Aug 3, 2012
Showing with 93 additions and 17 deletions.
  1. +8 −1 README.md
  2. +38 −7 bulk-user-management.php
  3. +18 −0 css/bulk-user-management.css
  4. +14 −2 includes/class-bulk-user-table.php
  5. +5 −3 js/bulk-user-management-inline-edit.js
  6. +10 −4 readme.txt
View
9 README.md
@@ -6,6 +6,13 @@ A WordPress plugin that lets you manage users across all your sites from one pla
Filters
-----
+<<<<<<< HEAD
* `bulk_user_management_blogs` - array of blogs to limit against.
* `bulk_user_management_parent_page` - sets parent page.
-* `bulk_user_management_admin_users` - array of users that the plugin is active for
+* `bulk_user_management_admin_users` - array of users that the plugin is active for
+=======
+* `bulk_user_management_blogs` - array of sites that can be managed
+* `bulk_user_management_parent_page` - sets parent page
+* `bulk_user_management_admin_users` - array of users by id that the plugin is active for
+* `bulk_user_management_admins_by_username` - array of users by username that the plugin is active for
+>>>>>>> develop
View
45 bulk-user-management.php
@@ -5,7 +5,7 @@
Plugin Name: Multisite Bulk User Management
Plugin URI: http://wordpress.org/extend/plugins/bulk-user-management/
Description: A plugin that lets you manage users across all your sites from one place on a multisite install
-Version: 1.0.1
+Version: 1.1
Author: Automattic
Author URI: http://automattic.com/wordpress-plugins/
License: GPLv2 or later
@@ -20,7 +20,7 @@
class Bulk_User_Management {
- const VERSION = '1.0.0';
+ const VERSION = '1.1';
const PAGE_SLUG = 'bulk_user_management';
const PER_PAGE = 20;
@@ -47,6 +47,8 @@ function __construct() {
add_action( 'admin_init', array( $this, 'handle_remove_users_form' ) );
add_action( 'wp_ajax_bulk_user_management_show_form', array( $this, 'show_users' ) );
+
+ add_filter( 'set-screen-option', array( $this, 'bulk_user_management_set_option' ), 10, 3 );
}
public function init() {
@@ -72,8 +74,26 @@ public function enqueue_scripts() {
}
public function register_menus() {
- if ( $this->current_user_can_bulk_edit() )
- add_submenu_page( $this->parent_page, esc_html__( 'Bulk User Management', 'bulk-user-management' ), esc_html__( 'User Management', 'bulk-user-management' ), 'manage_options', self::PAGE_SLUG, array( $this, 'users_page' ) );
+ if ( $this->current_user_can_bulk_edit() ) {
+ $hook = add_submenu_page( $this->parent_page, esc_html__( 'Bulk User Management', 'bulk-user-management' ), esc_html__( 'User Management', 'bulk-user-management' ), 'manage_options', self::PAGE_SLUG, array( $this, 'users_page' ) );
+ add_action( "load-$hook", array( $this, 'per_page' ) );
+ }
+ }
+
+ public function per_page() {
+ $option = 'per_page';
+
+ $args = array(
+ 'label' => __( 'Users', 'bulk-user-management' ),
+ 'default' => self::PER_PAGE,
+ 'option' => 'bulk_user_management_per_page'
+ );
+
+ add_screen_option( $option, $args );
+ }
+
+ public function bulk_user_management_set_option( $status, $option, $value ) {
+ if ( 'bulk_user_management_per_page' == $option ) return $value;
}
/**
@@ -142,6 +162,9 @@ public function users_page() {
case 'user_email_pair':
$messages[] = __( 'Each new user must have an email address specified.', 'bulk-user-management' );
break;
+ case 'cant-remove-current':
+ $messages[] = __( "Can't remove the current user", 'bulk-user-management' );
+ break;
case 'add_user_errors':
foreach ( $_POST['errors'] as $email => $error ) {
$email = sanitize_email( $email );
@@ -308,6 +331,10 @@ public function handle_remove_users_form() {
$blogids = array_map('intval', $_REQUEST['blogs']);
$userids = array_map('intval', $_REQUEST['users']);
+ // Don't let a user remove themself
+ if ( in_array( get_current_user_id(), $userids ) )
+ $update = 'cant-remove-current';
+
// Check that the current user can remove users on all target blogs
$errors = array();
foreach ( $blogids as $blogid ) {
@@ -318,8 +345,6 @@ public function handle_remove_users_form() {
}
}
- //TODO: handle case where user removes themself?
-
if ( 'remove' == $update )
$this->remove_users($blogids, $userids);
@@ -342,10 +367,16 @@ public static function current_user_can_bulk_edit() {
if ( is_super_admin() )
return true;
- $admins = array_map( 'sanitize_user', apply_filters( 'bulk_user_management_admin_users', array() ) );
+ // Add users by username
+ $admins = array_map( 'sanitize_user', apply_filters( 'bulk_user_management_admins_by_username', array() ) );
if ( in_array( wp_get_current_user()->user_login, $admins ) )
return true;
+ // Add users by id
+ $admins = array_map( 'intval', apply_filters( 'bulk_user_management_admin_users', array() ) );
+ if( in_array( get_current_user_id(), $admins ) )
+ return true;
+
return false;
}
}
View
18 css/bulk-user-management.css
@@ -7,4 +7,22 @@ input[type=checkbox] { width: auto; }
.site-checklist li {
display: inline-block;
min-width: 49%;
+}
+
+#loading {
+ position: absolute;
+ top: 125px;
+ left: 50%;
+ text-align: center;
+ font-size: 20px;
+ width: 150px;
+ margin-left: -75px;
+ height: 45px;
+ line-height: 45px;
+ border-radius: 5px;
+ background: rgba( 0,0,0,.1 );
+}
+#loading span:before {
+ content: url(../images/wpspin_light.gif);
+ margin-right: 5px;
}
View
16 includes/class-bulk-user-table.php
@@ -98,7 +98,20 @@ function get_bulk_actions() {
function prepare_items( $queryitems = true ) {
global $wpdb;
- $per_page = 20;
+ $screen = get_current_screen();
+
+ if ( isset( $screen ) ) {
+ // First check for a screen option the right way.
+ // If we're loaded with ajax, this won't work
+ $option = $screen->get_option( 'per_page', 'option' );
+ $per_page = get_user_meta( get_current_user_id(), $option, true );
+ } elseif ( isset( $_REQUEST['per_page'] ) ) {
+ // Check for per_page request variable
+ $per_page = intval( $_REQUEST['per_page' ] );
+ } else {
+ // Fall back to a reasonable default
+ $per_page = 20;
+ }
$paged = $this->get_pagenum();
@@ -131,7 +144,6 @@ function prepare_items( $queryitems = true ) {
}
// orderby and order
-
usort( $query, array( $this, 'compare_users' ) );
// search
View
8 js/bulk-user-management-inline-edit.js
@@ -93,11 +93,13 @@ inlineEditUser = {
paged: getParameterByName('paged'),
s: getParameterByName('s'),
orderby: getParameterByName('orderby'),
- order: getParameterByName('order')
+ order: getParameterByName('order'),
+ per_page: $("#bulk_user_management_per_page").val()
};
+ $("#wpbody-content").prepend("<div id='loading'><span>Loading...</span></div>");
$(".actions").prepend("<img class='ajax-spinner' src='" + bulk_user_management_images + "/wpspin_light.gif'>");
- $(".wp-list-table").animate({"opacity":".4"});
+ $(".wp-list-table").animate({"opacity":".3"});
$.post(ajaxurl, data, function(response) {
$('.widefat tbody').html( $(response).find('#the-list').html() );
@@ -138,7 +140,7 @@ inlineEditUser = {
return false;
});
}).success(function(){
- $(".ajax-spinner").hide();
+ $(".ajax-spinner, #loading").hide();
$(".wp-list-table").animate({"opacity":"1"});
$('.widefat tbody tr').each(function(){
var id = $(this).find('th.check-column input[type="checkbox"]').val();
View
14 readme.txt
@@ -3,7 +3,7 @@ Contributors: automattic, betzster, danielbachhuber
Tags: admin, users, bulk
Requires at least: 3.4
Tested up to: 3.4.1
-Stable tag: 1.0.1
+Stable tag: 1.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -24,7 +24,8 @@ The following filters will let you customize the plugin:
* `bulk_user_management_blogs` - array of sites that can be managed
* `bulk_user_management_parent_page` - sets parent page
-* `bulk_user_management_admin_users` - array of users that the plugin is active for
+* `bulk_user_management_admin_users` - array of users by id that the plugin is active for
+* `bulk_user_management_admins_by_username` - array of users by username that the plugin is active for
== Frequently Asked Questions ==
@@ -34,8 +35,13 @@ Because you haven't asked one yet.
== Changelog ==
-= 1.0 =
-* Initial Release
+= 1.1 =
+* Adds a screen option for number of users per page
+* Makes it more obvious when an ajax action is loading
+* Doesn't allow current user to remove themself
= 1.0.1 =
* Fix fatal error in PHP 5.2
+
+= 1.0 =
+* Initial Release

0 comments on commit b7fb6ba

Please sign in to comment.