Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
1.7k views
in Plugins by
edited by
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
by
Correct!.. so do you have any solution for this?

1 Answer

+2 votes
by
selected by
 
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();
}

 

by
@pixelngrain: So this issue is gone? ... I mean do you have two plugins with layers that both override a core function? And both sustain their code(s) now?
by
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
by
thx for letting me know
...