Need help with the share content plugin and adding userpoints for sharing.

Hi all.

I've modified "addthis_share" plugin for my purpose.



elgg_register_event_handler('init', 'system', 'addthis_share_init');

    function addthis_share_init()
        elgg_extend_view('object/elements/summary', 'addthis_share/addthis');

And mod/addthis_share/views/default/addthis_share/addthis.php:


   $full = elgg_extract('full_view', $vars, FALSE);
   $context =  elgg_get_context();

if ($context != 'thewire' && $context != 'widgets' && $context != 'blog' && $context != 'groups' && $context != 'friends' && $context != 'videos' && $context != 'bookmarks')  {
echo '<br><div align="center"><table><tr><td class="ya_share"><div align="center" class="ya-share2" data-services="vkontakte,facebook,odnoklassniki,moimir,twitter,lj,viber,whatsapp,skype,telegram" data-title="Relax Time!" data-description="Relax time!" ></div></td></tr></table></div>';
echo '<script src="//" charset="utf-8" async="async"></script><br>';
} ?>

I want an userpoints (other plugin) will be adding to users for share content of my site.

Author of userpoints plugin are busy irl atm and can't help with that in the nearest days. But he gave me an explanation how to do it:

The main thing to get working is not the handling of userpoints as such. This could be implemented easily if there would be any kind of feedback available (as in terms of an Elgg plugin hook getting triggered) when something gets shared. The implementation of the triggering of the plugin hook is the tricky part. For this to work, the Javascript code of Addthis would have to be loaded in a different way, i.e. not just with a <script> tag but using elgg_define_js to allow for loading it in the right order together with Elgg's elgg.js library to have the Elgg JS API functions available. The Addthis code has event listeners. These can be used to trigger an Elgg plugin hook which in turn can be used to trigger the awarding of userpoints.

I'm not using exactly "AddThis service" for sharing content, it can be seen above from code.

In documentation of that service:

1. Add script block:

<script src=""></script>

2. Call method "Ya_share2":

var share = Ya.share2('my-share', {
    hooks: {
        onshare: function () {
            alert('Button pressed');


var myShare = document.getElementById('my-share');
var share = Ya.share2(my-share, {
    hooks: {
        onshare: function () {
            alert('Button pressed');

What and where I need to write for making it work? If I understand correctly- need to write elgg_register_plugin_hook_handler in the init function, but I don't understand how, especially with JS.

Thanks in advance.

  • You should have given us this link to documentation in your first post.

    As written in the documentation, you need to add the social network name to the trigger 'onshare'. Finally, I wrote a sample plugin that you can use.

    Keep in your mind that I'm not going to support or update this plugin in the future. This plugin is created as sample only.

  • Thanks in advance, RvR. I'll be able to test your plugin only tomorrow and will write result here.

    About documentation- what's the point of social network's name if "onready" hook doesn't work as simple alert function also?

    About support of your plugin- sure thing. I just need a working sample and can modify it for my purpose.

  • "onready" hook doesn't work as simple alert function 

    I just follow the documentation.  ¯\_(ツ)_/¯

    This doesn't work w/o a name.

    My sample plugin has an example with twitter and it's works very well including userpoints.

  • This doesn't work w/o a name.

    "onready" hook don't need a name of soc net. And it's not working in my implementation with your help.

    I saw your code of course. Directory "global", you didn't tell about that in this topic.

    If you have tested plugin and it works- it's just great.

    Will message tomorrow.

  • "onready" hook don't need a name of soc net

    I've meant 'onshare' of course

    Directory "global"

    It сame from NodeJS. I deleted it already. Download the plugin again

  • Download the plugin again

    Already did, thanks. Will test it tomorrow.

  • It's worked. Thanks for your time, RvR.

    p.s. it's worked even without social network name in JS script :) And it should work without it (from docs), that's why I didn't payed attention there.

  • Very useful post. Thanks