Mohammad Faisal Islam
Mohammad Faisal Islam

Reputation: 507

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

Upvotes: 3

Views: 923

Answers (1)

Andrew Bucklin
Andrew Bucklin

Reputation: 699

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.

Upvotes: 5

Related Questions