Add permission for viewing and editing the blog
anselmbradford - May 13, 2009 - 23:48
| Project: | Profile Blog Information |
| Version: | 6.x-1.0 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
I added a permission for viewing and editing the blog info, so blog info is available in a user's profile based on their role. The following are the functions I added / modified (patch is attached as well):
<?php
/**
* Implementation of hook_perm()
*/
function profile_blog_info_perm() {
return array('access blog account');
}
function profile_blog_info_categories() {
$data = array();
$category = variable_get('profile_blog_info_profile_category', '');
if (!empty($category)) {
$data[] = array(
'name' => $category,
'title' => $category,
'weight' => 3,
'access callback' => 'profile_blog_info_category_access',
'access arguments' => array(1, 'access blog account')
);
}
return $data;
}
/**
* Menu item access callback - check if a user has access to a profile category.
*/
function profile_blog_info_category_access($account, $category) {
if (user_access('access blog account') && $account->uid > 0) {
return TRUE;
}
else {
return user_edit_access($account) && db_result(db_query("SELECT COUNT(*) FROM {profile_fields} WHERE category = '%s' AND visibility <> %d", $category, PROFILE_HIDDEN));
}
}
function profile_blog_info_view_profile(&$user) {
if ( user_access( 'access blog account') )
{
$category = variable_get('profile_blog_info_profile_category', '');
if (!empty($user->profile_blog_info_blog_url)&& !empty($user->profile_blog_info_title)) {
$user->content['summary']['profile_blog_info_title'] = array(
'#type' => 'user_profile_item',
'#value' => l($user->profile_blog_info_title, $user->profile_blog_info_blog_url),
);
}
}
}
?>| Attachment | Size |
|---|---|
| addpermissions.patch | 2.57 KB |
