Allow editor for reports
-
Hi,
I have on admin page called “download_report”, and I want users with the Editor role to be able to download reports. Currently, it throws a “you do not have permission” error when an Editor tries to access the page.
I’ve already created a function that allows Editors to see the Icegram plugin, and i tried to extend also this page but no result. I just need guidance on how to allow Editors to access this custom admin page and download reports.
Here is my code
add_filter('user_has_cap', function ($all_caps, $caps, $args, $user) {
if (empty($user->roles) || !in_array('editor', (array) $user->roles, true)) {
return $all_caps;
}
// Icegram Express page slugs
$ig_es_pages = [
'es_dashboard', 'es_lists', 'es_forms', 'es_campaigns', 'es_notifications',
'es_newsletters', 'es_workflows', 'es_reports', 'es_logs', 'es_settings',
'es_general_information', 'es_pricing', 'es_gutenberg_editor'
];
$page = isset($_GET['page']) ? sanitize_text_field($_GET['page']) : '';
$post_type = isset($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : '';
$on_icegram_screen = ($page && in_array($page, $ig_es_pages, true)) ||
($post_type && strpos($post_type, 'ig_es_') === 0);
// 1) Grant on actual Icegram requests
if ($on_icegram_screen) {
$all_caps['manage_options'] = true;
return $all_caps;
}
// 2) Also grant during admin menu build so the Icegram menu shows up
// (but we'll hide global Settings right after).
if (is_admin() && doing_action('admin_menu')) {
$all_caps['manage_options'] = true;
}
return $all_caps;
}, 10, 4);Thanks in advance for any help!
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
The topic ‘Allow editor for reports’ is closed to new replies.
