Help creating a user counter plugin for Elgg 6.2
Hello everyone,
I am working on an Elgg 6.2 community website and I would like some help creating a plugin that stores user counters directly in the user entity.
The idea is to avoid repeatedly counting friends and groups by loading all pages. Instead, I would like the plugin to maintain counters that are updated automatically whenever something changes.
For example:
friends_count value.groups_count value.Then, on the frontend, I would only need to display these stored values:
FRIENDS (153)
GROUPS (8)without making additional queries or scanning pagination pages.
My questions are:
I am trying to build this in a way that is efficient and follows Elgg's best practices, especially considering performance on a growing community.
Any examples, suggestions, or guidance would be greatly appreciated.
Thank you!
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.
- Jerome Bakker@jeabakker

Jerome Bakker - 0 likes
- $user->getGroups(['count' => true])
- elgg_count_entities(['relationship' => 'friend', 'relationship_guid' => $user->guid])
- there is the join/leave group event
- and the create/delete relationship event for the friends relationship
You must log in to post replies.First of having 2 count queries shouldn't be that heavy on the database (even with 100's of concurrent users).
But if you want to you can listen to some events to manipulate the values:
See https://learn.elgg.org/en/stable/guides/events-list.html#relationship-events
You can then store those values as metadata with the user.
If you then need a ajax view to (re)load the values look at https://learn.elgg.org/en/stable/guides/ajax.html