• Resolved cofri

    (@cofri)


    Hello,

    I encountered the following problem: I have conditional menus only visible for logged-in users with a specific UM-custom role (let’s say “UMroleA”). When I update a user to this role UMroleA via WPadmin interface, he/she is able to see the conditional menus for this user (this is the correct behaviour).

    However, if I update the role via php custom page using the code below, the conditional menus are not visible for the user. Only menu tabs for his previous role are visible. What is surprising is that the restricted pages to role UMroleA are accessible (directly using URL links).

    Have you any ideas of this behaviour? Is this a bug or a problem from me? Can I fix it?

    Code to update user role :
    $user = new WP_User($user_id);
    // either add_role or set_role
    $user->add_role(“UMroleA”);
    // OR
    $user->set_role(“UMroleA”);

    I’m using: WordPress 5.8.1, Ultimate Member 2.2.5, theme Spacious.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @cofri

    Please try clearing the user cache after changing the role:

    $user = new WP_User($user_id);
    // either add_role or set_role
    $user->add_role(“UMroleA”);
    // OR
    $user->set_role(“UMroleA”);
    // Delete cache
    UM()->user()->remove_cache( $user_id );

    Regards,

    Thread Starter cofri

    (@cofri)

    Hi @champsupertramp,

    Thank you very much for the quick answer. Your solution solved the problem ! The conditional menus are now visible for the user with the new role.

    By the way, is clearing cache something we should be aware when updating roles via php? Or is it considered as a bug from Ultimate Member?

    Thanks again !
    Regards,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @cofri

    It’s required to clear the user cache when updating the user role and data programmatically.

    Regards,

    Thread Starter cofri

    (@cofri)

    Thank you. I was looking for documentation about it but I was not able to find anything. It’s a tricky tip to know ?? Some doc could be helpful.

    Regards

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @cofri

    Thanks for your suggestion.

    Regards,

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Conditional menus not visible after updating role via php’ is closed to new replies.