how customize drupal 7 for multi user instance - drupal

When generating a new drupal site (multisite), I would like to define the default user profile as an admin user without acces to administration menu.
How can I create this new user as an install profile with default login infos, keeping at the same time the admin user?
i found this node ,but i can't understand ! how can I apply !?
Thank you for suggestions.

This tutorial lays out how to create roles and accounts in an install profile.
The core idea is to programmatically create a new role and user account in the profile .install file. For example (untested):
// Create a role for site content managers
$admin_role = new stdClass();
$admin_role->name = 'content manager';
$admin_role->weight = 2;
user_role_save($admin_role);
// Grant all admin permissions
user_role_grant_permissions($admin_role->rid, array_keys(module_invoke_all('permission')));
// Revoke the toolbar permissions
user_role_revoke_permissions($admin_role->rid, array(
'access administration menu', // The admin_menu module toolbar
'access toolbar', // The core toolbar
));
// Create a user with the content manager role
$new_user = array();
$new_user['name'] = 'manager';
$new_user['mail'] = 'manager#example.com';
$new_user['roles'] = array($admin_role->rid => $admin_role->rid);
$new_user['pass'] = 'incredibly-secure-password-here';
$new_user['status'] = 1;
$account = user_save(drupal_anonymous_user(), $new_user);

Related

Wordpress user role, that can only edit users with another user role?

I created a new user role, but I need this user role to only be able to edit users with another user role, I do not want this new user role to be able to edit users like, editors, author, etc...
Ideas?
you can add roles so:
$result = add_role(
'editor_of_users',
__( 'Editor of Users' ),
array(
'edit_users' => true,
// Add more capabilities...
)
);
if ( null !== $result ) {
echo 'Yay! New role created!';
}
else {
echo 'Oh... the editor_of_users role already exists.';
}
For more information you can read the documentation about: add_role
And the all users capabilities here: Roles and Capabilities
EDIT:
Read this post: to know how add to users the capabilities to edit specific roles...
How to allow an user role to create a new user under a role which lower than his level only?
I hope you resolve it... Good Look! ;)

Facebook app friends list Laravel + Facebook SDK

I am using Laravel + Facebook SDK ( https://github.com/SammyK/LaravelFacebookSdk) to get a friends list from my app. The weird thing is for some reason that I don't know why, some users I can fetch their friends, some users I can't.
For example, under my own user, I can fetch all my friends who are also using my app.
However, I have created a new user in Facebook just for testing. I've became a friend of this new user. In addition, this user has approved the app in their facebook. As a result, I can't see this user in my friends list and also this new user can't see me in their friends list.
My code base is
$q = \Facebook::get('/me/friends', $token);
$friends = json_decode($q->getBody())->data;
Facebook V2.0 upgraded. So you can try like this "user_friends".
Refer Link
I just figure out what was wrong! I was logging in the Facebook without the right permission scope.
Every login it must pass as a parameter "user_friends" according to this url https://developers.facebook.com/docs/facebook-login/permissions and https://developers.facebook.com/docs/php/howto/example_facebook_login
Basically, the code is
$fb = new Facebook\Facebook([
'app_id' => '{app-id}', // Replace {app-id} with your app id
'app_secret' => '{app-secret}',
'default_graph_version' => 'v2.2',
]);
$helper = $fb->getRedirectLoginHelper();
$permissions = ['email']; // Optional permissions
$loginUrl = $helper->getLoginUrl('https://example.com/fb-callback.php', $permissions);

How to enable administrator role

I have Drupal 7.22 with "minimal" install profile.
When I create new user, I have disabled option in "Administration role".
How can I enable administrator role for new user?
Create at least one role (maybe call it "Administrator") and it will show up in the dropdown. (The 2 default roles don't count)
you can create anew role and give all privilege (edit,add,remove ..Etc) and give it to new user
Execute this PHP code in the devil module (taken from the file \drupal-site\profiles\standard\standard.install):
// Create a default role for site administrators, with all available permissions assigned.
$admin_role = new stdClass();
$admin_role->name = 'administrator';
$admin_role->weight = 2;
user_role_save($admin_role);
user_role_grant_permissions($admin_role->rid, array_keys(module_invoke_all('permission')));
// Set this as the administrator role.
variable_set('user_admin_role', $admin_role->rid);
// Assign user 1 the "administrator" role.
db_insert('users_roles')
->fields(array('uid' => 1, 'rid' => $admin_role->rid))
->execute();

drupal programmatically disable or remove node create node link(s)

In the context of organic groups, I am writing a module which will stop users who are not members of a group from adding group posts into that group.
My module currently sets the permissions necessary and detects whether a user has the permission.
So when a user(s) are looking at a group page, I want to disable/remove the standard link to create group posts.
Try this method.
function mymodule_menu_alter(&$items) {
global $user;
// Perform code for finding out users permissions.
// lets suppose we set true or false to $restricted after all
if ($restricted && isset($items['node/add/yourtype'])) {
$items['node/add/yourtype']['access arguments'] = FALSE;
// or unset($items['node/add/yourtype']) to remove item for user
}
}
If I understood right you don't want certain users to create a content type.
So the steps are:
1) Create a menu hook.
// Here we make sure if the user goes to for creating this node type
// we can use the appropriate call back function to stop it.
function yourmodoule_menu() {
$items = array();
$items['node/add/page'] = array(
'page arguments' => array('yourmodule_additional_actions'),
'access arguments' => array('administer create content')
);
}
2) Then make a permission hook to make sure only certain users have this permission.
// drupal will only allow access to to path 'node/add/page' with people
// who have access given by you.
function yourmodule_permission() {
return array(
'add content' => array(
'title' => t('Administer create conent'),
'description' => t('Perform administration tasks and create content')
)
)
}
3) Write your code for those users who have the permission.
// Only affter they have this permisson drupal will allow them access
// to the below function.
function yourmodule_additional_actions() {
// this code will only execute if the user has the permission
// "Administer create conent"
}

How to manually register a user in Drupal 6.x?

The website has a normal registration form which allows users to register and the likes.
I have created a new custom form in which I am capturing the username/password etc. How do I manually register the user in Drupal system?
Thank You
Check out hook_user and user_save().
http://api.drupal.org/api/function/hook_user
http://api.drupal.org/api/function/user_save/6
Just expanding on Kevin's suggestion of hook_user and user_save here, the code might look something like:
// store user name
$user_name = "user123";
// store user email
$email = "user123#gmail.com";
// set up the user fields, use user_password function for 8 character password
$fields = array(
'name' => $user_name,
'mail' => $email,
'pass' => user_password(8),
'status' => 1,
);
// give new user roles if needed, as shown below
$fields['roles'] = array('new_role');
// pass the fields to user_save() and leave first param empty to create new user
$account = user_save('', $fields);
It's not the answer you want, but you'd save yourself a lot of trouble by using hook_form_alter to change the current registration form:
http://www.lullabot.com/articles/modifying-forms-drupal-5-and-6

Resources