Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.

Global Function Overriding

+1 vote
664 views
asked Jan 15, 2013 in Plugins by jatin.soni
edited Jan 17, 2013 by jatin.soni
I remember someone ask this question few days ago but no one answered and while developing one plugin I realized the sme issue.

Suppose advance theme is overriding the function and the same function if plugin overrides, than plugin is overriding function of advance theme and this breaking things completely.

Now this I have tested with only one theme and one plugin but I afraid that is possible to override function over and over again by one and another plugin with is realy need to take concern.

So is there any way to keep it always and yet can add overridden items to the same functions from all other plugins?
Q2A version: 1.5.4
commented Jan 15, 2013 by jatin.soni
Correct!.. so do you have any solution for this?

1 Answer

+2 votes
answered Jan 16, 2013 by Scott
selected Jan 22, 2013 by jatin.soni
 
Best answer

Yes, for function overrides you can call through to the "base" function as it says in the documentation:

When overriding functions, you should call through to the _base function as much as possible.

For theme layers it's similar, you should call through to the parent function. It can be a bit complex, especially if you want to change something that the parent function outputs. Generally you should just change variables. I can't think of a great example right now, but let's pretend the default CSS function is like this:

function css()
{
  $this->output('<link rel="stylesheet" href="'.$this->cssfile.'">');
}

If you want to output an extra CSS file you would do:

function css()
{
  parent::css();
  $this->output('<link rel="stylesheet" href="newfile/css">');
}

Or if you want to change what CSS file is output you would do something like this in your plugin:

function css()
{
  $this->cssfile = 'newfile.css';
  parent::css();
}

 

commented Feb 1, 2013 by jatin.soni
Actually I partially it worked but today I was working on one plugin and this issue again pops up. I have started another question here http://www.question2answer.org/qa/21060/overiding-function-reopened-the-question
commented Feb 1, 2013 by q2apro
thx for letting me know
...