3

I have developed a custom component for a client and they needed to be able to reuse email addresses for users. As Joomla required unique email addresses, I created a system plugin that fires on the "onAfterRoute" and loads my JTableUser class instead.

I know this isn't ideal but it was the best way to achieve the end result.

I have just installed Joomla 3.6 and it is now throwing a fatal error saying I cannot redeclare the JTableUser class when I try to use anything from the . I am guessing that the original class is now being called before the onAfterRoute trigger.

class PlgSystemMyComponentOverride extends JPlugin
{
public function __construct(&$subject, $config = array()) {
      parent::__construct($subject, $config);
  }

  public function onAfterRoute() {
      $app = JFactory::getApplication();
      $option = JRequest::getCMD('option');
      if('com_users' == JRequest::getCMD('option')) {
          require_once('path_to_my_code.php');
      }
  }
}

Is there a way to fix this in Joomla 3.6?

Thanks

Lee

1

1 Answer 1

1

JTableUser is very tricky. Since it is loaded at the very first time the framework is initialized, it cannot be easily overloaded by a system plugin and it cannot be evicted from memory once it is there.

To solve the case, I had to create a patch function, where the original JUser class is replaced in the core by the system plugin:

$this->patch('JTableUser', '/libraries/joomla/table/user.php');
4
  • Do you mean that you added that code to the core files? This plugin worked very well until Joomla 3.6. Jul 14, 2016 at 9:52
  • I know it is against all rules. But, in this case, JTableUser can't be modified in any other way.
    – Anibal
    Jul 14, 2016 at 13:52
  • The problem comes from the fact that JUser is needed to determine if your plugin should be executed or not. Since they have an access level, they need to be authorised. Thus when the first plugin event fires, JUser and its files already need to be loaded.
    – Bakual
    Nov 11, 2016 at 15:21
  • Yes, you're totally right!
    – Anibal
    Nov 13, 2016 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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