Download the PHP package devgeniem/wp-geniem-roles without Composer
On this page you can find all versions of the php package devgeniem/wp-geniem-roles. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download devgeniem/wp-geniem-roles
More information about devgeniem/wp-geniem-roles
Files in devgeniem/wp-geniem-roles
Package wp-geniem-roles
Short Description Wrapper class for WordPress role creation and manipulation.
License GPL-3.0
Homepage https://github.com/devgeniem/wp-geniem-roles
Informations about the package wp-geniem-roles
Geniem Roles
Wrapper classes for developers to create and manipulate WordPress roles.
Table of contents
- Geniem Roles
- Table of contents
- Installation
- Composer installation
- Manual installation
- Development guidelines
- Reset roles with wp-geniem-roles
- Reset roles to WordPress default roles
- Reset roles on multisite with WP CLI
- WP CLI reset roles.
- Examples / Features
- Initializing Geniem Roles
- Create a new role with capabilities
- Get and manipulate a role
- Add caps for a role
- Remove caps from a role
- Remove a role.
- Rename a role.
- Remove menu pages from a role
- Remove admin bar nodes by a role
- Restrict post editing and deleting
- Grant post editing
- Restrict user management by role
- Restrict user template management by role
- Grant super admin cap for a single user
- Filters
- 'geniem/roles/add_menu_page_cap'
- Example usage
- 'geniem/roles/default_roles'
- Example usage
- Admin page role listing
- screenshot
- Admin page menu slugs
- Wiki
Installation
Composer installation
command line
composer.json
Manual installation
Move plugin to your WordPress installation plugins/
folder.
Development guidelines
User roles are stored in the database so you need to reset roles in the database after changes to the roles. This can be done with wp-geniem-roles or wp cli.
Reset roles with wp-geniem-roles
wp-geniem-roles resets WordPress standard and custom roles with one method. Note this is a slow process you don't want to run this on every page load. Helper function for debugging and controlled reseting of the roles.
Reset roles to WordPress default roles
wp-geniem-roles resets all roles to WordPress default ones with one method.
Reset roles on multisite with WP CLI
Reset roles on multisite with CLI command. This resets all default and custom roles.
WP CLI reset roles.
You can also reset roles with WP CLI see the documentation from here. https://developer.wordpress.org/cli/commands/role/
Examples / Features
Initializing Geniem Roles
Geniem roles plugin has been designed in singleton architecture. Singleton is created inside the plugin. After plugin has been activated you are able to use Geniem roles functions. It is still good practice to check that plugin has been activated.
Create a new role with capabilities
All new roles capabilities defaults to false
. So we add just capabilities that we want to apply for the role. See the example code for a hands on example.
Get and manipulate a role
You can call existing role from WordPress by calling function \Geniem\Roles::get( $role_slug );
. You can use a role as an object to manipulate the role. See the example from the below.
Add caps for a role
Remove caps from a role
Remove a role.
Rename a role.
Remove menu pages from a role
You can remove single admin menu page with string
value or multiple pages with an array
value. You can also remove submenu pages. See the example below for the details.
Remove admin bar nodes by a role
You can remove admin bar nodes by a role with a function remove_admin_bar_nodes()
. See the example below for the details.
Restrict post editing and deleting
This function makes easy and fast to restrict editing of certain posts. Pass restricted post as an array of post ids and choose which capabilities you want to restrict for them.
Grant post editing
This function makes easy and fast to grant posts by the given post ids and capabilities. Note you can also define caps for the other posts if not defined all caps will be blocked for the other posts.
Restrict user management by role
Function to restrict users to manage users by the given roles and capabilities.
Role will be removed from the WordPress admin user management dropdowns for example bulk action "Change role to" if the role has been restricted with the caps edit_user
or promote_user
.
Restrict user template management by role
Function to restrict roles available templates. Add only templates that you want to enable.
Array of slugs will be used ass a parameter. (You can inspect template slug from the wp-admin template dropdown.)
Note!: WordPress doesn't handle default template the same way as other templates. Default template will always be available for the users. If you want to enable only default template add string 'default' as a parameter.
Grant super admin cap for a single user
Filters
'geniem/roles/add_menu_page_cap'
Change wp-geniem-roles wp-admin menu capability.
- Default value:
'activate_plugins'
- Parameter type:
string
Example usage
'geniem/roles/default_roles'
Filter new role default capabilities.
- Parameter type:
array
Example usage
Admin page role listing
wp-geniem-roles
creates a admin page which lists all current active roles and their capabilities in the admin side. Admin page can be seen for roles that can can_activate_plugins
.
screenshot
Admin page menu slugs
wp-geniem-roles
creates a admin page which lists all menu slugs. This is helper page for usage of function remove_menu_pages()
. See the function documentation for more information.
Wiki
Tips and tricks https://github.com/devgeniem/wp-geniem-roles/wiki