Re: [PHP] include() and duplicate function definition
Hi guys, :-) Just FYI, I got this answer from the theme dev: "David, You don't need the include statement. If you create your function in wp-content/themes/suffusion-child/functions.php it will get automatically included. Secondly, using the same function name wouldn't work, because it would require me to encase the original function definition in actions.php in a "function_exists" clause. I would suggest using a different function name, then using remove_action to remove the older action and add_action to add the new action." (http://www.aquoid.com/forum/viewtopic.php?f=4&t=3070) I'm not yet confident about how to actually implement this in code... Any tips or advice would be gratefully heard. On Thu, Nov 4, 2010 at 00:13, Steve Staples wrote: > I am curious on how this would work, if for some reason they were using > a different template? the function you want to "overwrite", wont be > used, and therefore, wouldn't your app/template/whatever be updated > improperly than waht you expect it to be? Steve, maybe the above informs? In any case, the function to be overwritten is likely to remain fairly stable... All the best, :-) David Nelson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include() and duplicate function definition
On Thu, 2010-11-04 at 00:00 +0800, David Nelson wrote: > Hi Thijs, :-) > > On Wed, Nov 3, 2010 at 20:38, Thijs Lensselink wrote: > > I re-read your original post. And noticed you include the function inside > > your child action.php > > Is there a special reason for that? You want to overwrite the original > > function in a child theme. > > probably to get different functionality. So why do you need the original > > function? > > > > Just create your action.php and define the same function. > > It's a WordPress issue. When theme updates become available from the > original vendor, you can update them from within the admin backend. In > that case, any hacks you've applied (such as removing a function) get > overwritten. So the evangelized solution is to create a child theme. > The child theme incorporates only files that you've added or changed, > with the original parent theme being used for all others. > > Easy peasy if you want to *add* a function. > > But, if you want to *modify* a function, you're faced with the problem > of the original function still being present in the parent theme files > and of your having to define a function of the same name in your child > theme (if you change the function name, you then have to hack other > code further upstream, and the work involved becomes not worth the > bother). Somehow, I would need to make my hacked function *replace* > the original function, *without* touching the original function... > > It seems like that's not possible and I'll have to find another > solution... unless my explanation gives you any good ideas? > > Just to put the dots on the I's, the original "actions.php" contains a > lot of *other* functions that I don't want to touch, and that I do > want to leave exposed to the updates process. It's just one single > function I want to hack... > > Sticky problem, huh? :-) > > In any case, thanks for your kind help, :-) > > David Nelson > > P.S. Sorry about the direct mails: I keep forgetting to hit the > "Replly to all" button. > I am curious on how this would work, if for some reason they were using a different template? the function you want to "overwrite", wont be used, and therefore, wouldn't your app/template/whatever be updated improperly than waht you expect it to be? Just curious... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] include() and duplicate function definition
Hi Thijs, :-) On Wed, Nov 3, 2010 at 20:38, Thijs Lensselink wrote: > I re-read your original post. And noticed you include the function inside > your child action.php > Is there a special reason for that? You want to overwrite the original > function in a child theme. > probably to get different functionality. So why do you need the original > function? > > Just create your action.php and define the same function. It's a WordPress issue. When theme updates become available from the original vendor, you can update them from within the admin backend. In that case, any hacks you've applied (such as removing a function) get overwritten. So the evangelized solution is to create a child theme. The child theme incorporates only files that you've added or changed, with the original parent theme being used for all others. Easy peasy if you want to *add* a function. But, if you want to *modify* a function, you're faced with the problem of the original function still being present in the parent theme files and of your having to define a function of the same name in your child theme (if you change the function name, you then have to hack other code further upstream, and the work involved becomes not worth the bother). Somehow, I would need to make my hacked function *replace* the original function, *without* touching the original function... It seems like that's not possible and I'll have to find another solution... unless my explanation gives you any good ideas? Just to put the dots on the I's, the original "actions.php" contains a lot of *other* functions that I don't want to touch, and that I do want to leave exposed to the updates process. It's just one single function I want to hack... Sticky problem, huh? :-) In any case, thanks for your kind help, :-) David Nelson P.S. Sorry about the direct mails: I keep forgetting to hit the "Replly to all" button. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include() and duplicate function definition
On Wed, 3 Nov 2010 19:53:52 +0800, David Nelson wrote: Hi, :-) On Wed, Nov 3, 2010 at 19:29, Peter Lind wrote: That's not going to happen. My point was you could check in the original file if the function is defined and if not then define it. OK, thanks, Thijs and Peter, it looks like I'm trying to do something that is not currently possible in PHP. Time for some lateral thinking. :-) David Nelson David, I re-read your original post. And noticed you include the function inside your child action.php Is there a special reason for that? You want to overwrite the original function in a child theme. probably to get different functionality. So why do you need the original function? Just create your action.php and define the same function. // include '../sometheme/functions/actions.php'; function foo($arg_1, $arg_2, /* ..., */ $arg_n) { echo "All my new code.\n"; } It's code duplication. But i don't think themes should have dependencies to one an other. You could also create a actions.php file outside the themes folder. wp-content/shared-functions/action.php And then in your themes do: theme 1 include "shared-function/action.php"; foo(); theme 2 include "shared-function/action.php"; foo(); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include() and duplicate function definition
Hi, :-) On Wed, Nov 3, 2010 at 19:29, Peter Lind wrote: > That's not going to happen. My point was you could check in the original > file if the function is defined and if not then define it. OK, thanks, Thijs and Peter, it looks like I'm trying to do something that is not currently possible in PHP. Time for some lateral thinking. :-) David Nelson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include() and duplicate function definition
That's not going to happen. My point was you could check in the original file if the function is defined and if not then define it. On Nov 3, 2010 11:55 AM, "David Nelson" wrote: > Hi Peter, :-) > > On Wed, Nov 3, 2010 at 18:44, Peter Lind wrote: >> You can check with function_exists to see if a function is already defined. >> If not, create it. > > The function is definitely already defined, I just need to replace it > without touching the file in which it's defined... > > David Nelson
Re: [PHP] include() and duplicate function definition
Hi Peter, :-) On Wed, Nov 3, 2010 at 18:44, Peter Lind wrote: > You can check with function_exists to see if a function is already defined. > If not, create it. The function is definitely already defined, I just need to replace it without touching the file in which it's defined... David Nelson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include() and duplicate function definition
You can check with function_exists to see if a function is already defined. If not, create it. Regards Peter On Nov 3, 2010 11:40 AM, "David Nelson" wrote: > Hi Thijs, :-) > > On Wed, Nov 3, 2010 at 18:18, Thijs Lensselink wrote: >> As far as I know it is not possible to overwrite functions in PHP (unless >> you use runkit, apd). Inside classes this is possible. But that's not the >> case here. Why do the functions have to be equally named? > > If the functions aren't named the same, my replacement function will > never get called by the code that uses the WordPress theme code... > >> Try to create a new function and call the original function from there if >> needed... > > Sadly, it wouldn't work for the above reason... > > But thanks for your answer. :-) > > David Nelson > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >
[PHP] include() and duplicate function definition
Hi Thijs, :-) On Wed, Nov 3, 2010 at 18:18, Thijs Lensselink wrote: > As far as I know it is not possible to overwrite functions in PHP (unless > you use runkit, apd). Inside classes this is possible. But that's not the > case here. Why do the functions have to be equally named? If the functions aren't named the same, my replacement function will never get called by the code that uses the WordPress theme code... > Try to create a new function and call the original function from there if > needed... Sadly, it wouldn't work for the above reason... But thanks for your answer. :-) David Nelson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] include() and duplicate function definition
On Wed, 3 Nov 2010 17:59:06 +0800, David Nelson wrote: Hi, :-) I'm making a child theme for WordPress. I need to rewrite one function defined in "../sometheme/functions/actions.php" and put that rewritten function in "wp-content/themes/sometheme-child/functions/actions.php". But I want to preserve "../sometheme/functions/actions.php" unchanged in any way. (Future theme updates would just overwrite any changes I made.) So, in my new "actions.php", I put an include followed by the replacement function definition, named identically to the one I want to replace: Because this duplicate foo() function definition comes after the foo() defined in the included file, does it replace the included foo()? Or how can I achieve what I want? Big thanks in advance for any suggestions. :-) David As far as I know it is not possible to overwrite functions in PHP (unless you use runkit, apd). Inside classes this is possible. But that's not the case here. Why do the functions have to be equally named? Try to create a new function and call the original function from there if needed... foo2() { foo() } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] include() and duplicate function definition
Hi, :-) I'm making a child theme for WordPress. I need to rewrite one function defined in "../sometheme/functions/actions.php" and put that rewritten function in "wp-content/themes/sometheme-child/functions/actions.php". But I want to preserve "../sometheme/functions/actions.php" unchanged in any way. (Future theme updates would just overwrite any changes I made.) So, in my new "actions.php", I put an include followed by the replacement function definition, named identically to the one I want to replace: Because this duplicate foo() function definition comes after the foo() defined in the included file, does it replace the included foo()? Or how can I achieve what I want? Big thanks in advance for any suggestions. :-) David -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php