function commerce_wishlist_manage_access in Commerce Wishlist 7.2
Determine whether the user has a privilege to manage a wishlist.
1 call to commerce_wishlist_manage_access()
- commerce_wishlist_handler_field_product_link_remove::render in includes/
views/ handlers/ commerce_wishlist_handler_field_product_link_remove.inc - Render the field.
1 string reference to 'commerce_wishlist_manage_access'
- commerce_wishlist_menu in ./
commerce_wishlist.module - Implements hook_menu().
File
- ./
commerce_wishlist.module, line 341 - Provides the wishlist for use in Drupal Commerce.
Code
function commerce_wishlist_manage_access($account, $wishlist_item_id) {
// Allow administrators to edit any wishlist on the site.
if (user_access('administer wishlists')) {
return TRUE;
}
// Check if the wishlist owner and the user who is trying to edit the wishlist
// are the same, and if they have permission to manage own wishlist.
global $user;
$query = db_select('commerce_wishlist_item', 'wi')
->addTag('commerce_wishlist')
->fields('cw', array(
'uid',
))
->condition('item_id', $wishlist_item_id);
$query
->join('commerce_wishlist', 'cw', 'cw.wishlist_id = wi.wishlist_id');
$wishlist_uid = $query
->execute()
->fetchField();
return $wishlist_uid == $user->uid && user_access('manage own wishlist');
}