示例#1
0
 /**
  * Runs on the `load-{$page}` hook.  This is the handler for form submissions and requests.
  *
  * @since  1.0.0
  * @access public
  * @return void
  */
 public function load()
 {
     // Get the current action if sent as request.
     $action = isset($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : false;
     // Get the current action if posted.
     if (isset($_POST['action']) && 'delete' == $_POST['action'] || isset($_POST['action2']) && 'delete' == $_POST['action2']) {
         $action = 'bulk-delete';
     }
     // Bulk delete role handler.
     if ('bulk-delete' === $action) {
         // If roles were selected, let's delete some roles.
         if (current_user_can('delete_roles') && isset($_POST['roles']) && is_array($_POST['roles'])) {
             // Verify the nonce. Nonce created via `WP_List_Table::display_tablenav()`.
             check_admin_referer('bulk-roles');
             // Loop through each of the selected roles.
             foreach ($_POST['roles'] as $role) {
                 $role = members_sanitize_role($role);
                 if (members_role_exists($role)) {
                     members_delete_role($role);
                 }
             }
             // Add roles deleted message.
             add_settings_error('members_roles', 'roles_deleted', esc_html__('Selected roles deleted.', 'members'), 'updated');
         }
         // Delete single role handler.
     } else {
         if ('delete' === $action) {
             // Make sure the current user can delete roles.
             if (current_user_can('delete_roles')) {
                 // Verify the referer.
                 check_admin_referer('delete_role', 'members_delete_role_nonce');
                 // Get the role we want to delete.
                 $role = members_sanitize_role($_GET['role']);
                 // Check that we have a role before attempting to delete it.
                 if (members_role_exists($role)) {
                     // Add role deleted message.
                     add_settings_error('members_roles', 'role_deleted', sprintf(esc_html__('%s role deleted.', 'members'), members_get_role_name($role)), 'updated');
                     // Delete the role.
                     members_delete_role($role);
                 }
             }
         }
     }
     // Load page hook.
     do_action('members_load_manage_roles');
 }
示例#2
0
     /* Break out of switch statement. */
     break;
     /* If a single role has been chosen to be deleted. */
 /* If a single role has been chosen to be deleted. */
 case 'delete':
     /* Make sure the current user can delete roles. */
     if (current_user_can('delete_roles')) {
         /* Verify the referer. */
         check_admin_referer(members_get_nonce('edit-roles'));
         /* Send role deleted message. */
         add_action('members_pre_edit_roles_form', 'members_message_role_deleted');
         /* Get the role we want to delete. */
         $role = esc_attr(strip_tags($_GET['role']));
         /* Delete the role and move its users to the default role. */
         if (!empty($role)) {
             members_delete_role($role);
         }
     }
     /* Load the edit roles page. */
     require_once MEMBERS_ADMIN . 'roles-list-table.php';
     /* Break out of switch statement. */
     break;
     /* If a role has been selected to be edited. */
 /* If a role has been selected to be edited. */
 case 'edit':
     /* Make sure the current user can edit roles. */
     if (current_user_can('edit_roles')) {
         /* Verify the referer. */
         check_admin_referer(members_get_nonce('edit-roles'));
         /* Load the edit role form. */
         require_once MEMBERS_ADMIN . 'role-edit.php';