Hello Minesh,
I copied your custom function with the name 'redirect-to-user-role-gesetzesliste`' and related this code to another view 'Gesetzesliste' on our website, where the second user role 'organisation' is important for selecting the items:
------------------------------------------------------------------------------------------
function update_menu_link($items){
global $current_user;
//look through the menu for items with Label "Link Title"
foreach($items as $item){
if($item->title === "Meine Gesetzesliste"){
$role = $current_user->roles[1];
$item->url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].'/gesetzesportal/gesetzesliste/?wpv-organisation='.$role ;
}
}
return $items;
}
add_filter('wp_nav_menu_objects', 'update_menu_link');
------------------------------------------------------------------------------------------
I modified the settings of 2 users, so that they have only one user role:
username: jasminstu, PW dAMUedANA8
When I deactivate the your custom function, the redirect hidden link (teufen ist the user role) opens the preslected view with about 198 items instead of the total of 2'080 items. But as discussed earlier, if I press the RESET button, all items will appear, which is not admissible.
If I activate your code, then all items are displayed, not restricted. The url is
hidden link
so the user role is missing. Something is not working with the code. However now, with just one role for this user, his role is displayed just above the view, which was not the case, when we had 2 roles for this user. That means the user role is really returned.
The second user is username stphangerosa , PW capAXm4Zryx7&Ecy1fGuhh@a, user role is 'aba', same situation as described above.
Would it be possible to optimize the code so that user role appears in the url?
Kind regards
Franz