Title: custom roles, php
Last modified: May 30, 2024

---

# custom roles, php

 *  Resolved [Dennis Bareis](https://wordpress.org/support/users/dbareis/)
 * (@dbareis)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/custom-roles-php/)
 * I have created a number of customer roles which show up and can be selected in
   your checkbox UI. They don’t get saved though. Non-custom ones do get saved.
 * I’m on PHP 8.3 and WordPress 6.5.3 , nothing shows in the PHP error log.
 *     ```wp-block-code
       //============================================================================
       function AddBungalookRole($RoleName, $RoleOptions)
       // CREATE ROLES
       //============================================================================
       {
       add_role("Bungalook_{$RoleName}", "Bungalook {$RoleName}", $RoleOptions);
       }
       //============================================================================
       function CreateBungalookUserSecurityRoles()
       // CREATE ROLES
       //============================================================================
       {
       $RoleOptions = [
       'read' => true,
       'create_posts' => true,
       'edit_posts' => true,
       'edit_others_posts' => true,
       'publish_posts' => true,
       'manage_categories' => true,
       ];
       AddBungalookRole('Newsletters', $RoleOptions);
       AddBungalookRole('Orders', $RoleOptions);
       AddBungalookRole('Plants', $RoleOptions);
       AddBungalookRole('Reimbursements', $RoleOptions);
       }
       add_action( 'init', 'CreateBungalookUserSecurityRoles' );
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [Dennis Bareis](https://wordpress.org/support/users/dbareis/)
 * (@dbareis)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/custom-roles-php/#post-17793037)
 * I’ve worked out what the bug is, the plugin assumes that the ID of the role is
   in lower case and from the typically little information WP provides I can’t see
   anything about that being a legit restriction. I’m now lower casing them until
   the plugin is updated.
 *  Plugin Author [Christian Neumann](https://wordpress.org/support/users/cneumann/)
 * (@cneumann)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/custom-roles-php/#post-17793374)
 * The plugin uses WordPress’ sanitize_key function ([https://developer.wordpress.org/reference/functions/sanitize_key/](https://developer.wordpress.org/reference/functions/sanitize_key/))
   to sanitize the role id. WordPress does this in lots of places for different 
   ids/keys (post type ids, menu ids etc). It does not do this for roles, but there
   is no UI for adding roles in WordPress, so WordPress does not have to sanitize
   user input for that. I would assume that role ids *should* be lower cased. If
   you have other examples, where WordPress or popular plugins allow creation of
   non-lowercased role ids, I will have a look. But for now, it doesn’t seem right
   to remove this sanitization.
 *  Thread Starter [Dennis Bareis](https://wordpress.org/support/users/dbareis/)
 * (@dbareis)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/custom-roles-php/#post-17793388)
 * that may be but letting me select it and save it and not apply it without any
   errors message is definately not right.
 *  Plugin Author [Christian Neumann](https://wordpress.org/support/users/cneumann/)
 * (@cneumann)
 * [2 years, 2 months ago](https://wordpress.org/support/topic/custom-roles-php/#post-17793416)
 * Okay, I will reconsider this. Might as well accept these roles as they have been
   added anyway.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘custom roles, php’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/multiple-roles_182732.svg)
 * [Multiple Roles](https://wordpress.org/plugins/multiple-roles/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/multiple-roles/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/multiple-roles/)
 * [Active Topics](https://wordpress.org/support/plugin/multiple-roles/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/multiple-roles/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/multiple-roles/reviews/)

## Tags

 * [lower case](https://wordpress.org/support/topic-tag/lower-case/)

 * 4 replies
 * 2 participants
 * Last reply from: [Christian Neumann](https://wordpress.org/support/users/cneumann/)
 * Last activity: [2 years, 2 months ago](https://wordpress.org/support/topic/custom-roles-php/#post-17793416)
 * Status: resolved