I don't my user to join more than 5 groups. I wrote a custom plugin and here's my start.php file.. I am not sure why its not getting executed.
<?php elgg_register_event_handler('init', 'system', 'improvement_init'); function improvement_init() { // Exeture this before joining a group elgg_register_event_handler('update', 'group', 'chk_group_count'); } function chk_group_count($hook, $type, $result, $params){ // Admin does not have any limit if(elgg_is_admin_logged_in()){ system_message("Checking group count deactivated for admins."); return true; }
$owner = elgg_get_logged_in_user_entity();$usergroups_count = elgg_get_entities_from_relationship_count(array('relationship'=> 'member', 'relationship_guid'=> $owner->guid, 'inverse_relationship'=> FALSE, 'type'=> 'group')); system_message(elgg_echo("You can join " . (5 - $usergroups_count) . " more groups.")); if($usergroups_count > 5){ register_error("You cannot join more that 5 groups!"); return false; } return true; } ?>
Thanks in advance!
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- ihayredinov@ihayredinov
ihayredinov - 0 likes
- Rohit Gupta@Rohit_1990_3676
Rohit Gupta - 0 likes
- ihayredinov@ihayredinov
ihayredinov - 0 likes
- Rohit Gupta@Rohit_1990_3676
Rohit Gupta - 0 likes
You must log in to post replies.Listen to create,relationship or join, group event and return false to prevent relationship from being created.
This is my updated code. I used elgg_register_event_handler with priority 1, but the user is joining the group first and then my custom plugin is getting executed.
Try create, relationship event and sniff the relationship name.
Awesome, create, relationship event did the trick.!!!