"; $groups = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $group_table ORDER BY name" ) ); foreach( $groups as $group ) { $groups_select .= ""; } $groups_select .= ""; // we add this inside the form that contains the bulk // action and role change buttons $box = "
"; $box .= ""; $box .= " / "; $box .= ""; $box .= " "; $box .= __( 'selected to / from group:', GROUPS_PLUGIN_DOMAIN ); $box .= " "; $box .= ""; $box .= $groups_select; $box .= "
"; $nonce = wp_nonce_field( 'user-group', 'bulk-user-group-nonce', true, false ); $nonce = str_replace('"', "'", $nonce ); $box .= $nonce; // @todo replace when a hook allows us to add actions to the users table // Another option is to extend the users table and implement it in extra_tablenav() // but that would require either to replace the users admin screen with // that extended one or create our own section, e.g. Groups > Users. echo ''; } } /** * Adds or removes users to/from groups. */ public static function load_users() { if ( current_user_can( GROUPS_ADMINISTER_GROUPS ) ) { $group_id = isset( $_REQUEST['group_id'] ) ? $_REQUEST['group_id'] : null; $users = isset( $_REQUEST['users'] ) ? $_REQUEST['users'] : null; $action = null; if ( !empty( $_REQUEST['add-to-group'] ) ) { $action = 'add'; } else if ( !empty( $_REQUEST['remove-from-group'] ) ) { $action = 'remove'; } if ( $group_id !== null && $users !== null && $action !== null ) { if ( wp_verify_nonce( $_REQUEST['bulk-user-group-nonce'], 'user-group' ) ) { foreach( $users as $user_id ) { switch ( $action ) { case 'add': if ( !Groups_User_Group::read( $user_id, $group_id ) ) { Groups_User_Group::create( array( 'user_id' => $user_id, 'group_id' => $group_id ) ); } break; case 'remove': if ( Groups_User_Group::read( $user_id, $group_id ) ) { Groups_User_Group::delete( $user_id, $group_id ); } break; } } } } } } /** * Adds a new column to the users table to show the groups that users * belong to. * * @param array $column_headers * @return array column headers */ public static function manage_users_columns( $column_headers ) { $column_headers[self::GROUPS] = __( 'Groups', GROUPS_PLUGIN_DOMAIN ); return $column_headers; } /** * Renders custom column content. * * $foo : both filter invocations in class-wp-ms-users-list-table.php and * class-wp-users-list-table.php pass '' * * @param unknown_type $foo * @param string $column_name * @param int $user_id * @return string custom column content */ public static function manage_users_custom_column( $foo, $column_name, $user_id ) { $output = ''; switch ( $column_name ) { case self::GROUPS : $groups_user = new Groups_User( $user_id ); $groups = $groups_user->groups; if ( count( $groups ) > 0 ) { $output .= ''; } else { $output .= __( '--' ); } break; } return $output; } } Groups_Admin_Users::init();