deconf.com

  • Home
  • Analytics Insights
  • Search Engine Insights

Changes needed to convert a Joomla 2.5 plugin into a Joomla 3.x plugin

October 11, 2012 by Alin Marcu

If you want to convert a common Joomla 1.5 or Joomla 2.5 plugin into a Joomla 3.x compatible plugin you will have to make some changes to plugin’s XML and PHP code.

Let’s start with the XML file:

1. The <install> tag is no longer supported, you will have to replace it with <extension> tag.

replace:

<install version="x.x" type="plugin" group="content" method="upgrade">

.....

</install>

with:

<extension version="x.x" type="plugin" group="content" method="upgrade">

.....

</extension>

Let’s continue with the PHP files:

2. Because the DS delimiter was removed, if you use it you will need to replace it with DIRECTORY_SEPARATOR

replace:

.DS.

with:

.DIRECTORY_SEPARATOR.

3. If your plugin uses parameters, you will have use JForm instead of JParameter. From Joomla 1.6 the parameters object is automatically available to you and you won’t need to use Plugin Helper to retrieve the plugin object and then JParameter to retrieve the parameters object.

The simplest approach is to remove this line from plugin’s PHP file:

jimport( 'joomla.html.parameter' );

replace this code:

parent::__construct($subject, $params); 
    
$this->plugin = &amp;JPluginHelper::getPlugin('content', 'PLUGIN_NAME');
    
$this->params = new JParameter($this->plugin->params);

with this:

parent::__construct($subject, $params); 
    
$mode = $this->params->def('mode', 1);

By doing this, you will be able to access a parameter in the parameters object like this:

$this->params->get('PARAMETER_NAME')

4. Because Joomla 3.x tends to throw exceptions instead of JError, JException or FALSE, you will have to use a “try-catch” approach. In the example below, if there is no #__ga_dash table, the function will return FALSE in Joomla 1.5 or Joomla 2.5. In Joomla 3.0 this function throws an exception, so i had to replace.

replace:

function get_token (){

	$db = JFactory::getDBO();
	$query = "SELECT token FROM #__ga_dash";
	$db->setQuery($query);	
	$result = $db->loadResult();
	
	return $result;
	
}

with:

function get_token (){

	$db = JFactory::getDBO();
	try { 
	$query = "SELECT token FROM #__ga_dash";
	$db->setQuery($query);	
	$result = $db->loadResult();
	}  
		catch(exception $e) {
		return; 
	}
	return $result;
	
}

These are the main modifications made to convert my Joomla 1.5 and Joomla 2.5 plugins into Joomla 3.0 plugins, hope it helps.

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook

Related

Tags: Joomla, upgrade

Follow deconf.com

Subscribe to receive free updates when new plugins, tutorials or posts are available.

Categories

  • WordPress Plugins
  • Joomla! Extensions
  • Analytics Insights FAQ
  • Tutorials
  • Donate or Contribute
  • Contact
  • Data Usage Policy for my Extensions
  • Privacy Policy
  • Tutorials & Tips

Copyright © 2025 · DeConf.com