5 added 4 characters in body
source | link

You can't check anything about the user in hook_menu or hook_menu_alter. Whether or not a user has access to a given path is not determined at the time those hooks are run; instead, those hooks give you a chance to tell the system what functions should be called to determine access when the path is eventually accessed. That's the purpose of the access callback and access arguments options.

First, you need to determine the actual path that is registered. Since it's Views, the path is user/%views_arg/infos if you have validation turned on for the contextual filter, and user/%/infos if you don't have any validation for the contextual filter.

So try something like this:

function hide_tabs_menu_alter(&$items) {
  $items['user/%views_arg/infos']['access callback'] = 'hide_tabs_user_info_access_callback';
  $items['user/%views_arg/infos']['access arguments'] = array(1);
}

function hide_tabs_user_info_access_callback($uid) {
  if (($account = user_load($uid)) && ($role = user_role_load_by_name('moderator'))) {
    return !user_has_role($role->rid, $account);
  }
  return FALSE;
}

Also, since Views actually adds these paths in hook_menu_alter itself, you need to ensure your module runs after Views. So your module needs to either have a higher weight than Views, or implement hook_module_implements_alter. So add this to your module as well:

function hide_tabs_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'menu_alter') {
    $implementation = $implementations['hide_tabs'];
    unset($implementations['hide_tabs']);
    $implementations['hide_tabs'] = $implementation;
  }
}

You can't check anything about the user in hook_menu or hook_menu_alter. Whether or not a user has access to a given path is not determined at the time those hooks are run; instead, those hooks give you a chance to tell the system what functions should be called to determine access when the path is eventually accessed. That's the purpose of the access callback and access arguments options.

First, you need to determine the actual path that is registered. Since it's Views, the path is user/%views_arg/infos if you have validation turned on for the contextual filter, and user/%/infos if you don't have any validation for the contextual filter.

So try something like this:

function hide_tabs_menu_alter(&$items) {
  $items['user/%views_arg/infos']['access callback'] = 'hide_tabs_user_info_access_callback';
  $items['user/%views_arg/infos']['access arguments'] = array(1);
}

function hide_tabs_user_info_access_callback($uid) {
  if ($account = user_load($uid) && $role = user_role_load_by_name('moderator')) {
    return !user_has_role($role->rid, $account);
  }
  return FALSE;
}

Also, since Views actually adds these paths in hook_menu_alter itself, you need to ensure your module runs after Views. So your module needs to either have a higher weight than Views, or implement hook_module_implements_alter. So add this to your module as well:

function hide_tabs_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'menu_alter') {
    $implementation = $implementations['hide_tabs'];
    unset($implementations['hide_tabs']);
    $implementations['hide_tabs'] = $implementation;
  }
}

You can't check anything about the user in hook_menu or hook_menu_alter. Whether or not a user has access to a given path is not determined at the time those hooks are run; instead, those hooks give you a chance to tell the system what functions should be called to determine access when the path is eventually accessed. That's the purpose of the access callback and access arguments options.

First, you need to determine the actual path that is registered. Since it's Views, the path is user/%views_arg/infos if you have validation turned on for the contextual filter, and user/%/infos if you don't have any validation for the contextual filter.

So try something like this:

function hide_tabs_menu_alter(&$items) {
  $items['user/%views_arg/infos']['access callback'] = 'hide_tabs_user_info_access_callback';
  $items['user/%views_arg/infos']['access arguments'] = array(1);
}

function hide_tabs_user_info_access_callback($uid) {
  if (($account = user_load($uid)) && ($role = user_role_load_by_name('moderator'))) {
    return !user_has_role($role->rid, $account);
  }
  return FALSE;
}

Also, since Views actually adds these paths in hook_menu_alter itself, you need to ensure your module runs after Views. So your module needs to either have a higher weight than Views, or implement hook_module_implements_alter. So add this to your module as well:

function hide_tabs_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'menu_alter') {
    $implementation = $implementations['hide_tabs'];
    unset($implementations['hide_tabs']);
    $implementations['hide_tabs'] = $implementation;
  }
}
4 deleted 28 characters in body
source | link

You can't check anything about the user in hook_menu or hook_menu_alter. Whether or not a user has access to a given path is not determined at the time those hooks are run; instead, those hooks give you a chance to tell the system what functions should be called to determine access when the path is eventually accessed. That's the purpose of the access callback and access arguments options.

First, you need to determine the actual path that is registered. Since it's Views, the path is almost certainly user/%views_arg/infos instead ofif you have validation turned on for the more specificcontextual filter, and user/%user%/infos which it would not know to register (since it doesn't know the type of wildcard represented byif you don't have any validation for the %)contextual filter. 

So try something like this:

function hide_tabs_menu_alter(&$items) {
  $items['user/%views_arg/infos']['access callback'] = 'hide_tabs_user_info_access_callback';
  $items['user/%views_arg/infos']['access arguments'] = array(1);
}

function hide_tabs_user_info_access_callback($uid) {
  if ($account = user_load($uid) && $role = user_role_load_by_name('moderator')) {
    return !user_has_role($role->rid, $account);
  }
  return FALSE;
}

Also, since Views actually adds these paths in hook_menu_alter itself, you need to ensure your module runs after Views. So your module needs to either have a higher weight than Views, or implement hook_module_implements_alter. So add this to your module as well:

function hide_tabs_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'menu_alter') {
    $implementation = $implementations['hide_tabs'];
    unset($implementations['hide_tabs']);
    $implementations['hide_tabs'] = $implementation;
  }
}

You can't check anything about the user in hook_menu or hook_menu_alter. Whether or not a user has access to a given path is not determined at the time those hooks are run; instead, those hooks give you a chance to tell the system what functions should be called to determine access when the path is eventually accessed. That's the purpose of the access callback and access arguments options.

First, you need to determine the actual path that is registered. Since it's Views, the path is almost certainly user/%views_arg/infos instead of the more specific user/%user/infos which it would not know to register (since it doesn't know the type of wildcard represented by the %).

So try something like this:

function hide_tabs_menu_alter(&$items) {
  $items['user/%views_arg/infos']['access callback'] = 'hide_tabs_user_info_access_callback';
  $items['user/%views_arg/infos']['access arguments'] = array(1);
}

function hide_tabs_user_info_access_callback($uid) {
  if ($account = user_load($uid) && $role = user_role_load_by_name('moderator')) {
    return !user_has_role($role->rid, $account);
  }
  return FALSE;
}

Also, since Views actually adds these paths in hook_menu_alter itself, you need to ensure your module runs after Views. So your module needs to either have a higher weight than Views, or implement hook_module_implements_alter. So add this to your module as well:

function hide_tabs_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'menu_alter') {
    $implementation = $implementations['hide_tabs'];
    unset($implementations['hide_tabs']);
    $implementations['hide_tabs'] = $implementation;
  }
}

You can't check anything about the user in hook_menu or hook_menu_alter. Whether or not a user has access to a given path is not determined at the time those hooks are run; instead, those hooks give you a chance to tell the system what functions should be called to determine access when the path is eventually accessed. That's the purpose of the access callback and access arguments options.

First, you need to determine the actual path that is registered. Since it's Views, the path is user/%views_arg/infos if you have validation turned on for the contextual filter, and user/%/infos if you don't have any validation for the contextual filter. 

So try something like this:

function hide_tabs_menu_alter(&$items) {
  $items['user/%views_arg/infos']['access callback'] = 'hide_tabs_user_info_access_callback';
  $items['user/%views_arg/infos']['access arguments'] = array(1);
}

function hide_tabs_user_info_access_callback($uid) {
  if ($account = user_load($uid) && $role = user_role_load_by_name('moderator')) {
    return !user_has_role($role->rid, $account);
  }
  return FALSE;
}

Also, since Views actually adds these paths in hook_menu_alter itself, you need to ensure your module runs after Views. So your module needs to either have a higher weight than Views, or implement hook_module_implements_alter. So add this to your module as well:

function hide_tabs_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'menu_alter') {
    $implementation = $implementations['hide_tabs'];
    unset($implementations['hide_tabs']);
    $implementations['hide_tabs'] = $implementation;
  }
}
3 added 27 characters in body
source | link

You can't check anything about the user in hook_menu or hook_menu_alter. Whether or not a user has access to a given path is not determined at the time those hooks are run; instead, those hooks give you a chance to tell the system what functions should be called to determine access when the path is eventually accessed. That's the purpose of the access callback and access arguments options.

First, you need to determine the actual path that is registered. Since it's Views, the path is almost certainly user/%%views_arg/infos instead of the more specific user/%user/infos which it would not know to register (since it doesn't know the type of wildcard represented by the %).

So try something like this:

function hide_tabs_menu_alter(&$items) {
  $items['user/%%views_arg/infos']['access callback'] = 'hide_tabs_user_info_access_callback';
  $items['user/%%views_arg/infos']['access arguments'] = array(1);
}

function hide_tabs_user_info_access_callback($uid) {
  if ($account = user_load($uid) && $role = user_role_load_by_name('moderator')) {
    return !user_has_role($role->rid, $account);
  }
  return FALSE;
}

Also, since Views actually adds these paths in hook_menu_alter itself, you need to ensure your module runs after Views. So your module needs to either have a higher weight than Views, or implement hook_module_implements_alter. So add this to your module as well:

function hide_tabs_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'menu_alter') {
    $implementation = $implementations['hide_tabs'];
    unset($implementations['hide_tabs']);
    $implementations['hide_tabs'] = $implementation;
  }
}

You can't check anything about the user in hook_menu or hook_menu_alter. Whether or not a user has access to a given path is not determined at the time those hooks are run; instead, those hooks give you a chance to tell the system what functions should be called to determine access when the path is eventually accessed. That's the purpose of the access callback and access arguments options.

First, you need to determine the actual path that is registered. Since it's Views, the path is almost certainly user/%/infos instead of the more specific user/%user/infos which it would not know to register (since it doesn't know the type of wildcard represented by the %).

So try something like this:

function hide_tabs_menu_alter(&$items) {
  $items['user/%/infos']['access callback'] = 'hide_tabs_user_info_access_callback';
  $items['user/%/infos']['access arguments'] = array(1);
}

function hide_tabs_user_info_access_callback($uid) {
  if ($account = user_load($uid) && $role = user_role_load_by_name('moderator')) {
    return !user_has_role($role->rid, $account);
  }
  return FALSE;
}

Also, since Views actually adds these paths in hook_menu_alter itself, you need to ensure your module runs after Views. So your module needs to either have a higher weight than Views, or implement hook_module_implements_alter. So add this to your module as well:

function hide_tabs_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'menu_alter') {
    $implementation = $implementations['hide_tabs'];
    unset($implementations['hide_tabs']);
    $implementations['hide_tabs'] = $implementation;
  }
}

You can't check anything about the user in hook_menu or hook_menu_alter. Whether or not a user has access to a given path is not determined at the time those hooks are run; instead, those hooks give you a chance to tell the system what functions should be called to determine access when the path is eventually accessed. That's the purpose of the access callback and access arguments options.

First, you need to determine the actual path that is registered. Since it's Views, the path is almost certainly user/%views_arg/infos instead of the more specific user/%user/infos which it would not know to register (since it doesn't know the type of wildcard represented by the %).

So try something like this:

function hide_tabs_menu_alter(&$items) {
  $items['user/%views_arg/infos']['access callback'] = 'hide_tabs_user_info_access_callback';
  $items['user/%views_arg/infos']['access arguments'] = array(1);
}

function hide_tabs_user_info_access_callback($uid) {
  if ($account = user_load($uid) && $role = user_role_load_by_name('moderator')) {
    return !user_has_role($role->rid, $account);
  }
  return FALSE;
}

Also, since Views actually adds these paths in hook_menu_alter itself, you need to ensure your module runs after Views. So your module needs to either have a higher weight than Views, or implement hook_module_implements_alter. So add this to your module as well:

function hide_tabs_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'menu_alter') {
    $implementation = $implementations['hide_tabs'];
    unset($implementations['hide_tabs']);
    $implementations['hide_tabs'] = $implementation;
  }
}
2 added 565 characters in body
source | link
1
source | link