?> " scope="col"><?php echo $col; ?> </th> <?php $n++; } ?> </tr> </thead> <tbody> <?php $style = ''; foreach ($wp_user_search->get_results() as $user) { $user_object = new Instructor($user->ID); $roles = $user_object->roles; $role = array_shift($roles); $style = ' alternate' == $style ? '' : ' alternate'; ?> <tr id='user-<?php echo $user_object->ID; ?> ' class="<?php echo $style; ?> "> <th scope='row' class='check-column'> <input type='checkbox' name='users[]' id='user_<?php echo $user_object->ID;
<?php global $wp_roles; if (isset($_POST['submit']) && current_user_can('manage_options') && isset($_POST['instructor_capability'])) { /* Set capabilities for each instructor user */ $wp_user_search = new Instructor_Search(); // $wp_user_search = new Instructor_Search( $usersearch, $page_num ); foreach ($wp_user_search->get_results() as $user) { CoursePress_Capabilities::grant_private_caps($user->ID); // Don't remove capabilities from administrators /* if( user_can( $user->ID, 'manage_options' ) ){ continue; } */ $role = new WP_User($user->ID); $user_capabilities = $role->wp_capabilities; // More than the hidden field needs to be present to add roles. if (isset($_POST['instructor_capability']) && 1 < count($_POST['instructor_capability'])) { foreach ($user_capabilities as $key => $old_cap) { // Make sure to only remove CoursePress instructor capabilities if (!in_array($key, $_POST['instructor_capability']) && in_array($key, array_keys(CoursePress_Capabilities::$capabilities['instructor']))) { //making the operation less expensive if (!user_can($user->ID, 'manage_options')) { $role->remove_cap($key); } } } foreach ($_POST['instructor_capability'] as $new_cap) { $role->add_cap($new_cap); } } else { //all unchecked, remove all instructor capabilities