Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Here's another rule, I just wrote that someone else might like. When a new user registers, it checks whether he/she is my friend on Facebook. If so, he/she is automatically unblocked and added to a role. This makes sense on a blog-type of site.
Replace XXX by your user id on Facebook (http://socialmediaseo.net/2010/02/20/how-to-find-facebook-id/), and adapt the role...
array (
'rules' =>
array (
'rules_unblock_facebook_friend' =>
array (
'#type' => 'rule',
'#set' => 'event_user_insert',
'#label' => 'Unblock user if my friend on Facebook',
'#active' => 1,
'#weight' => '0',
'#categories' =>
array (
),
'#status' => 'custom',
'#conditions' =>
array (
0 =>
array (
'#info' =>
array (
'label' => 'Is my friend on Facebook',
'label callback' => false,
'module' => 'PHP',
'eval input' =>
array (
0 => 'code',
),
),
'#name' => 'rules_condition_custom_php',
'#settings' =>
array (
'code' => 'try {
$fb = fb_api_init($fb_app);
$data = fb_api(\'/me/friends\');
$friends = $data[\'data\'];
foreach ($friends as $friend) {
if( $friend[\'id\'] == \'XXX\' ) {
return true;
}
}
}
catch (FacebookApiException $e) {}
return false;',
'vars' =>
array (
),
),
'#type' => 'condition',
'#weight' => 0,
),
),
'#actions' =>
array (
3 =>
array (
'#weight' => -2,
'#type' => 'action',
'#settings' =>
array (
'code' => 'user_user_operations_unblock(array($account->uid));',
'vars' =>
array (
0 => 'account',
),
),
'#name' => 'rules_action_custom_php',
'#info' =>
array (
'label' => 'Unblock new user',
'label callback' => false,
'module' => 'PHP',
'eval input' =>
array (
0 => 'code',
),
),
),
0 =>
array (
'#type' => 'action',
'#settings' =>
array (
'roles' =>
array (
0 => 8,
),
'#argument map' =>
array (
'user' => 'account',
),
),
'#name' => 'rules_action_user_addrole',
'#info' =>
array (
'label' => 'Add user role facebook_friends',
'label callback' => false,
'arguments' =>
array (
'user' =>
array (
'type' => 'user',
'label' => 'User whos roles should be changed',
),
),
'module' => 'User',
),
'#weight' => 0,
),
1 =>
array (
'#type' => 'action',
'#settings' =>
array (
'message' => 'You have been automatically unblocked and given some permissions, because you are Ingo\'s friend on Facebook.',
'error' => 0,
'#eval input' =>
array (
'rules_input_evaluator_php' =>
array (
'message' =>
array (
),
),
),
),
'#name' => 'rules_action_drupal_message',
'#info' =>
array (
'label' => 'Show modified welcome message',
'label callback' => false,
'module' => 'System',
'eval input' =>
array (
0 => 'message',
),
),
'#weight' => 0,
),
2 =>
array (
'#weight' => 0,
'#info' =>
array (
'label' => 'Send a mail to the new user',
'label callback' => false,
'arguments' =>
array (
'user' =>
array (
'type' => 'user',
'label' => 'Recipient',
),
),
'module' => 'System',
'eval input' =>
array (
0 => 'subject',
1 => 'message',
2 => 'from',
),
),
'#name' => 'rules_action_mail_to_user',
'#settings' =>
array (
'from' => '',
'subject' => 'Your account on ingomueller.net has been unblocked',
'message' => 'You have been automatically unblocked and given some permissions, because you are Ingo\'s friend on Facebook. You can use the following link to log in:
http://ingomueller.net/user',
'#argument map' =>
array (
'user' => 'user',
),
),
'#type' => 'action',
),
),
'#version' => 6003,
),
),
)
Comments welcome!
Cheers,
Ingo