Creating a Custom Menu Based on User Groups
-
Hello,
I have installed the Groups plugin on my site because I have multiple editor accounts, and I’m looking to display certain menus in the backend based on the group to which users are registered. I’m not sure if your plugin is the best solution, but I’ve used it to try to achieve this goal.
I’ve created a group named “Biologie” to gather teachers in this discipline. Then, in the functions.php file, I’ve added the following code:
add_action(‘admin_menu’, ‘add_custom_menu_pending_Biologie’);
function add_custom_menu_pending_Biologie() {
if (user_belongs_to_group_prof_biologie()) {
add_menu_page(
‘Pending Biologie’,
‘Pending Biologie’,
‘manage_options’,
‘pending-biologie’,
‘display_waiting_list_page’,
‘dashicons-clock’,
3
);
}
}
function display_waiting_list_page() {
$link = admin_url(‘edit.php’) . ‘?s&post_status=pending&post_type=listing&action=-1&m=0&features=pole-biologie&listing-category&price-plan-filter=all&filter_action=Filtrer&paged=1&action2=-1’;wp_redirect($link); exit;
}
function user_belongs_to_group_prof_biologie() {
$user = wp_get_current_user();
if (is_user_logged_in() && Groups_User_Group::read($user->ID, 2)) {
return true;
}
return false;
}However, the menu doesn’t seem to be added to the backend, but if I remove the condition, it appears normally.
Is there something I haven’t configured correctly in the plugin or the code?
Thank you for your assistance.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Creating a Custom Menu Based on User Groups’ is closed to new replies.