You are here

function message_ui_user_can_create_message in Message UI 7

Check if the user can create an instance for a message type.

Parameters

$type: The message type for which the info shall be returned, or NULL to return an array with info about all types.

$account: The user object or user uid.

Return value

array|bool TRUE or FALSE for a specific message type or an array of the message types

1 call to message_ui_user_can_create_message()
message_ui_create_new_message_instance_list in ./message_ui.module
Display list of message types to create an instance for them.

File

./message_ui.module, line 53
Main file for the message UI module.

Code

function message_ui_user_can_create_message($type = NULL, $account = NULL) {
  if (empty($account)) {
    global $user;
    $account = $user;
  }
  $account = entity_metadata_wrapper('user', $account)
    ->value();
  $types = message_ui_get_types();

  // User have access to create any instances.
  if (user_access('create any message instance', $account)) {
    return TRUE;
  }

  // Check access for a specific message.
  if ($type) {

    // Didn't found that type.
    if (!in_array($type, $types)) {
      return;
    }
    if (user_access('create a ' . $type . ' message instance', $account)) {
      return TRUE;
    }
  }

  // Build list of arrays for the permissions.
  $permissions = array();
  foreach (array_keys($types) as $type) {
    $permissions[$type] = user_access('create a ' . $type . ' message instance', $account);
  }
  return $permissions;
}