0

In a system plugin I need to have two flags, one to check if there are more than one language in administration and another flag to check if a two factor authentication is needed.

Tried the following script and it is working, but I would like to know if there is a better/recommended way of doing it.

// Check more than 1 installed language
jimport('joomla.language.helper');
$langs = JLanguageHelper::createLanguageList(null, JPATH_ADMINISTRATOR, false, true);
$flagLang  = (count($langs) > 1) ? true : false;

// Check two factor authentication need
FOFPlatform::getInstance()->importPlugin('twofactorauth');
$factor = FOFPlatform::getInstance()->runPlugins('onUserTwofactorIdentify', array());
$flagFactor  = (!empty($factor)) ? true : false;
1

There is better way for getting $flagFactor.

$flagFactor = JPluginHelper::isEnabled('twofactorauth');

This returns true if any of twofactorauth type plugins is enabled and accessible by current user or guest. False otherwise.

And your ? true : false is redundant, since (count($langs) > 1) returns boolean and therefore already equals to true or false.

// Check more than 1 installed language
jimport('joomla.language.helper');
$langs    = JLanguageHelper::createLanguageList(null, JPATH_ADMINISTRATOR, false, true);
$flagLang = (count($langs) > 1); // boolean

// Check two factor authentication need
$flagFactor = JPluginHelper::isEnabled('twofactorauth'); // boolean

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.