• Resolved crib0669

    (@crib0669)


    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)
  • Hi there,

    I’ve run your code locally without issues. When I add my current user to the group with id 2, the menu item appears and vice versa.

    Perhaps this is what you should check, if you go to Groups > Groups, make sure that you have a group with id 2.

    Then go to Users > All users, select your current user and via the Bulk actions, add/remove this user from that group.

    Reference: Bulk actions

    Kind regards,

    George

Viewing 1 replies (of 1 total)
  • The topic ‘Creating a Custom Menu Based on User Groups’ is closed to new replies.