So I've got this in a system plugin for event onAfterInitialize -
$app = JFactory::getApplication(); $referrer = $app->input->getInt('ref'); $app->setUserState('com_mycomponent.referrer', $referrer);
And I know it's setting the variable because on that file this works -
//get ref_uid from session variable $ref_uid = $app->getUserState('com_mycomponent.referrer', null); var_dump($ref_uid); die;
Also, when I put the getUseState on an external php file for testing, it reads as well -
define( '_JEXEC', 1 ); define( '_VALID_MOS', 1 ); define( 'JPATH_BASE', realpath(dirname(__FILE__).'/' )); define( 'DS', DIRECTORY_SEPARATOR ); require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' ); require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' ); $mainframe = JFactory::getApplication('site'); $mainframe->initialise(); $app = JFactory::getApplication(); //get ref_uid from session variable $ref_uid = $app->getUserState('com_mycomponent.referrer'); var_dump($ref_uid);die;
However - when I put that same exact getUserState call in a user plugin for onUserAfterSave, it fails to read the session variable and returns null.
I"m sure the code is firing because I get output while testing, echo this and die that etc.
Anyone have any ideas why this isn't working?
Someone on stackexchange had a similar issue so I tried their suggestion and added this to no avail -
$session = JFactory::getSession(); $session->set('registry', new JRegistry('session'));
Also worth noting is that getUserState is working fine in my custom component, just not in this onUserAfterSave plugin.
Any help would be greatly appreciated, I'm all out of ideas!