Skip to content

Instantly share code, notes, and snippets.

@hazratbilal0079
Created September 25, 2024 07:38
Show Gist options
  • Save hazratbilal0079/c544f348a974a462d7586a7350a09bcc to your computer and use it in GitHub Desktop.
Save hazratbilal0079/c544f348a974a462d7586a7350a09bcc to your computer and use it in GitHub Desktop.
Add Custom Roles in WordPress website
function add_custom_roles_via_snippet() {
// Capabilities for CEO, Operational Manager, and Listing Manager
$full_capabilities = array(
'edit_post' => true,
'edit_others_posts' => true,
'delete_post' => true,
'delete_others_posts' => true,
'publish_posts' => true,
'read_post' => true,
'publish_others_posts' => true,
'edit_pages' => true,
'delete_pages' => true,
'edit_others_pages' => true,
'delete_others_pages' => true,
'edit_private_posts' => true,
'delete_private_posts' => true,
'read_private_posts' => true,
'publish_pages' => true,
'edit_private_pages' => true,
'delete_private_pages' => true,
'read_private_pages' => true
);
// Capabilities for Lead Supervisor and Broker (no private post/page access)
$edit_capabilities = array(
'edit_post' => true,
'edit_others_posts' => true,
'read_post' => true,
'edit_pages' => true,
'edit_others_pages' => true,
'read_pages' => true
);
// Capabilities for Call Center, Receptionist, Landlord, Tenant, Outside Broker (can only read others' posts/pages)
$limited_capabilities = array(
'edit_post' => true,
'delete_post' => true,
'publish_posts' => true,
'read_post' => true,
'edit_pages' => true,
'delete_pages' => true,
'publish_pages' => true,
'read_others_posts' => true,
'read_others_pages' => true
);
// CEO Role
add_role('ceo', 'CEO', $full_capabilities);
// Operational Manager Role
add_role('operational_manager', 'Operational Manager', $full_capabilities);
// Listing Manager Role
add_role('listing_manager', 'Listing Manager', $full_capabilities);
// Leads Supervisor Role
add_role('leads_supervisor', 'Leads Supervisor', $edit_capabilities);
// Broker Role
add_role('broker', 'Broker', $edit_capabilities);
// Call Center Agent Role
add_role('call_center_agent', 'Call Center Agent', $limited_capabilities);
// Receptionist Role
add_role('receptionist', 'Receptionist', $limited_capabilities);
// Outside Broker Role
add_role('outside_broker', 'Outside Broker', $limited_capabilities);
// Landlord Role
add_role('landlord', 'Landlord', $limited_capabilities);
// Tenant Role
add_role('tenant', 'Tenant', $limited_capabilities);
}
// Hook into 'init' to ensure roles are created
add_action('init', 'add_custom_roles_via_snippet');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment