1

Using J3.7.2 with MySQL 5.7.14 and PHP 5.6.25. I have built a Joomla user plugin (let's name it "My_Plugin") which does all the things that the default Joomla user plugin "User-Joomla" does, plus some extras. The site works perfectly well when the plugin User-Joomla is unpublished and My_Plugin is published, EXCEPT... when trying to add a new registered user from the back-end user panel. Joomla then throws a (non-fatal) notice "trying to get property of non-object...". The reason is, that com_users/models/user.php is trying to retrieve $pluginParams in function getForm ($plugin->params on line 116). This line fails when the User-Joomla plugin is disabled.

However, for My_Plugin to work properly, the event function onUserLogin must be called only once. When User-Joomla is also enabled (which must be because of com_users), the function onUserLogin is executed twice: once by My_Plugin and once by User-Joomla.

QUESTION How can I stop or 'untrigger' this event in My_Plugin to prevent it from triggering the same function in User-Joomla? The same goes for all other event functions, e.g. onUserAfterDelete, onUserAfterSave, onUserLogout, etc. Needless to say that I don't want to hack the Joomla core.

My_Plugin class is declared as follows (all comments removed):

use Joomla\Registry\Registry;

class plgMy_Plugin_User extends JPlugin
{
protected $app;
protected $db;

public function onUserAfterDelete($user, $success, $msg)
{
     .............
}

public function onUserAfterSave($user, $isnew, $success, $msg)
{
     .............
}

public function onUserLogin($user, $options = array())
     .............
}

etcetera....

1 Answer 1

1

It seems that someone from the core team read your post, and, as such, added a condition to check if the user plugin is enabled, and if it is, then they get the plugin parameters. In essence, the developer changed this code:

$plugin = JPluginHelper::getPlugin('user', 'joomla');
$pluginParams = new Registry($plugin->params);

to:

$pluginParams = new Registry;

if (JPluginHelper::isEnabled('user', 'joomla'))
{
    $plugin = JPluginHelper::getPlugin('user', 'joomla');
    $pluginParams->loadString($plugin->params);
}

This means that if you update your Joomla version to the latest version, you won't have this problem anymore.

The credit goes to whoever developer read your post and fixed the code.

Now, to answer your original question, at the moment, you can't untrigger or stop an event from being triggered unless you do some core modifications. And, even if that was possible, it wouldn't solve your problem, because the problem that you were having was caused by a Joomla bug, which assumed that the core user plugin was always enabled.

Note: Joomla 4.0 will contain a stopPropagation() method which will stop the propagation of an event. Not exactly what you need, but a good feature nonetheless.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.