Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto enable the plugin during installation in Joomla?

Does any good way in Joomla to auto enable the plugin during installation? I have followed the post topics but do not get any straight forward solution.

I have used below code during installation for auto enabling the plugin :

UPDATE `#__extensions` SET `enabled` = 1 WHERE `element` = 'plugin_name';

But I want to know better solution.

/Thanks

like image 250
Mohammad Faisal Islam Avatar asked Nov 22 '25 12:11

Mohammad Faisal Islam


1 Answers

That's the only way only way I'm aware of; detailed below for others who might stumble on this trying to figure out how to do it.

Add scripfile to the manifest (XML), below the </description> tag:

<scriptfile>my_script.php</scriptfile>

my_script.php:

class PlgSystemPluginnameInstallerScript
{
 public function install($parent)
 {
  // Enable plugin
  $db  = JFactory::getDbo();
  $query = $db->getQuery(true);
  $query->update('#__extensions');
  $query->set($db->quoteName('enabled') . ' = 1');
  $query->where($db->quoteName('element') . ' = ' . $db->quote('PLUGIN_NAME_GOES_HERE'));
  $query->where($db->quoteName('type') . ' = ' . $db->quote('plugin'));
  $db->setQuery($query);
  $db->execute();
 }
}

Tip: If it's a content plugin, replace PlgSystemPluginnameInstallerScript with PlgContentPluginnameInstallerScript.

like image 90
Andrew Bucklin Avatar answered Nov 24 '25 02:11

Andrew Bucklin