// Create the Maharashtra Reports Admin Role
function maharashtra_create_reports_admin_role() {
// Remove the role first if it exists to prevent capabilities stacking
remove_role('maharashtra_reports_admin');
add_role(
'maharashtra_reports_admin',
'Maharashtra Reports Admin',
array(
'read' => true,
// No other capabilities
)
);
}
register_activation_hook(__FILE__, 'maharashtra_create_reports_admin_role');
// Create the Chhattisgarh Reports Admin Role
function chhattisgarh_create_reports_admin_role() {
// Remove the role first if it exists to prevent capabilities stacking
remove_role('chhattisgarh_reports_admin');
add_role(
'chhattisgarh_reports_admin',
'Chhattisgarh Reports Admin',
array(
'read' => true,
// No other capabilities
)
);
}
register_activation_hook(__FILE__, 'chhattisgarh_create_reports_admin_role');
// Add menu only for Maharashtra reports
function maharashtra_add_reports_menu() {
global $current_user;
if (in_array('maharashtra_reports_admin', (array) $current_user->roles)) {
// Add main menu for Maharashtra
add_menu_page(
'Maharashtra Order Reports',
'Maharashtra Reports',
'read',
'maharashtra-reports',
'display_maharashtra_orders', // FIXED: added comma here
'dashicons-chart-area',
5
);
}
}
add_action('admin_menu', 'maharashtra_add_reports_menu');
// Add menu only for Chhattisgarh reports
function chhattisgarh_add_reports_menu() {
global $current_user;
if (in_array('chhattisgarh_reports_admin', (array) $current_user->roles)) {
// Add main menu for Chhattisgarh
add_menu_page(
'Chhattisgarh Order Reports',
'Chhattisgarh Reports',
'read',
'chhattisgarh-reports',
'display_chhattisgarh_orders', // FIXED: added comma here
'dashicons-chart-area',
5
);
}
}
add_action('admin_menu', 'chhattisgarh_add_reports_menu');
// Run this once
add_action('init', function() {
if (!get_option('custom_roles_created')) {
maharashtra_create_reports_admin_role();
chhattisgarh_create_reports_admin_role();
update_option('custom_roles_created', true);
}
});