Get Roles
// get roles
function get_editable_roles() {
global $wp_roles;
$all_roles = $wp_roles->roles;
$editable_roles = apply_filters('editable_roles', $all_roles);
return $editable_roles;
}
Add Roles
function wporg_simple_role() {
add_role('simple_role',
'Simple Role',
array(
'read' => true,
'edit_posts' => true,
'upload_files' => true,
,
);
)
}'init', 'wporg_simple_role' ); add_action(
Remove Roles
// removing roles
function wporg_simple_role_remove() {
'simple_role' );
remove_role(
}'init', 'wporg_simple_role_remove' ); add_action(
Add Capabilities
// adding capabilities
function wporg_simple_role_caps() {
$role = get_role( 'simple_role' );
$role->add_cap( 'edit_others_posts', true ); // for removing capability remove_cap()
}'init', 'wporg_simple_role_caps' ); add_action(
Get Roles
// get role
$role ); get_role(
Check User Capacibility
// Check if a user have a specified role or capability with user_can().
$user, $capability ); user_can(
Check Current User Capacibility
// current_user_can() is a wrapper function for user_can() using the current user object as the $user parameter.
$capability ); current_user_can(