Create a gist now

Instantly share code, notes, and snippets.

Override Core Joomla! Classes
<?php
/**
* @package Joomla.Plugin
* @subpackage System.Overrides
*
* @copyright Copyright (C) 2012 Don Gilbert. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
define('OVERRIDES', dirname(__FILE__).'/overrides');
// Use JLoader to register all the classes you want to override
JLoader::register('JClassToOverride', OVERRIDES.'/libraries/joomla/class/to/override.php', true);
silence is golden
<?php
/**
* @package Joomla.Plugin
* @subpackage System.Overrides
*
* @copyright Copyright (C) 2012 Don Gilbert. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_BASE') or die;
/**
* System plugin to override core classes terms.
*
* @package Joomla.Plugin
* @subpackage System.Overrides
* @since 2.5
*/
class PlgSystemOverrides extends JPlugin
{
/* We do our thing in the __construct method
* so that our overridden classes will be
* available everywhere
*/
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
include_once 'config.php';
}
}
<?xml version="1.0" encoding="utf-8"?>
<extension version="2.5" type="plugin" group="system" method="upgrade">
<name>plg_system_overrides</name>
<author>Don Gilbert</author>
<creationDate>Aug 2012</creationDate>
<copyright>(C) 2012 Don Gilbert. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>don@electriceasel.com</authorEmail>
<authorUrl>www.electriceasel.com</authorUrl>
<version>2.5.6</version>
<description>This plugin will override classes contained in the included config file.</description>
<files>
<filename plugin="overrides">overrides.php</filename>
<filename>config.php</filename>
<filename>index.html</filename>
<folder>overrides</folder>
</files>
</extension>
@BuenGenio

Life Saviour! ;-)

Fanksss!

(Works on J!3.x too!)

@mhalb1
mhalb1 commented Nov 22, 2015

This is very useful. Thanks very much.

A tip for anyone wanting to override one class from a larger namespace: use the whole namespace with the name of the class in the register() definition in config.php. For example I wanted to override Community Builder's UserTable class only,

JLoader::register('CB\Database\Table\UserTable', OVERRIDES.'/libraries/CBLib/CB/Database/Table/UserTable.php', true);

@amprodes
amprodes commented Nov 11, 2016 edited

hello noob question... with this plugin is posible to override JApplicationSite? i tried and didn't work ..

this is what i did

class PlgSystemOverrides extends JPlugin
{
/* We do our thing in the __construct method
* so that our overridden classes will be
* available everywhere
*/

public function __construct(&$subject, $config)
{
	
	parent::__construct($subject, $config);
	
	//Load config file only at frontend
	$app = JFactory::getApplication(); 

	if($app->isSite()) {
		// Use JLoader to register all the classes you want to override
		JLoader::register('JApplicationSite', '/baseappi_core/libraries/cms/application/site.php', true);
	}
}

Plugin folder structure is the following:

overrides
---baseappi_core
------- libraries
---------- cms
-------------application
----------------site.php
---install.script.php
---index.html
---overrides.php
---overrides.xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment