function privatemsg_menu_access in Privatemsg 6.2
Checks access to a menu entry.
Contains special checks if the privatemsg menu entries are displayed as a local task in the profile.
Parameters
$permission: Permission string, defaults to read privatemsg
$account: User account to check permissions. If NULL, default to current user.
$deny_if_other: Deny access if user is viewing another user's messages and does not have proper permissions.
Return value
TRUE if user has access, FALSE if not.
3 string references to 'privatemsg_menu_access'
- pm_block_user_menu in pm_block_user/
pm_block_user.module - Implements hook_menu().
- privatemsg_filter_menu in privatemsg_filter/
privatemsg_filter.module - Implements hook_menu().
- privatemsg_menu in ./
privatemsg.module - Implements hook_menu().
File
- ./
privatemsg.module, line 315 - Allows users to send private messages to other users.
Code
function privatemsg_menu_access($permission = 'read privatemsg', $deny_if_other = FALSE) {
static $disabled_displayed = FALSE;
global $user;
// Disallow anonymous access, regardless of permissions.
if (!$user->uid) {
return FALSE;
}
// Check that we are not viewing another user's private messages under
// their account page. And if we are, check permissions and deny others flag.
$url_prefix = variable_get('privatemsg_url_prefix', 'messages');
$url_prefix_user_arg_position = array_search('%user', explode('/', $url_prefix));
if ($url_prefix_user_arg_position !== FALSE && (!user_access('read all private messages') || $deny_if_other) && arg($url_prefix_user_arg_position) > 0 && $user->uid != arg($url_prefix_user_arg_position)) {
return FALSE;
}
// Check if the user has disabled privatemsg.
if (privatemsg_is_disabled($user) && $permission == 'write privatemsg') {
// Only show the message once and only if configured to do so.
if (strpos($_GET['q'], variable_get('privatemsg_url_prefix', 'messages')) === 0 && variable_get('privatemsg_display_disabled_message', TRUE) && !$disabled_displayed) {
$disabled_displayed = TRUE;
drupal_set_message(t('You have disabled Privatemsg and are not allowed to write messages. Go to your <a href="@settings_url">Account settings</a> to enable it again.', array(
'@settings_url' => url('user/' . $user->uid . '/edit'),
)), 'warning');
}
return FALSE;
}
if (!user_access($permission)) {
return FALSE;
}
return TRUE;
}