![]() |
|
override a function - Printable Version +- ZenphotoCMS Forum (https://forum.zenphoto.org) +-- Forum: Support (https://forum.zenphoto.org/forum-1.html) +--- Forum: General support (https://forum.zenphoto.org/forum-4.html) +--- Thread: override a function (/thread-1661.html) |
override a function - jordi-kun - 2007-09-20 Is there any way to override a function? Let's say I want to customize a function in template-functions.php to fit my needs, but since the file is updated frequently, I'd have to be extra careful when updating. Is it possible to have a custom-functions.php that overrides these specific functions? jordi override a function - sbillard - 2007-09-21 PHP does not allow overriding a function. The only option is to have alternate PHP files and load the one with the version of the function you want to use. If the function you want is in the core, your only choice is to clone it with a different name. override a function - jordi-kun - 2007-09-21 I see, thanks anyway sbillard! override a function - gwmbox - 2010-12-06 WOW, a 3 year old post that is relevant.... is this still the case as the answer above is provided? If so when you say clone, where does the clone go and what do I edit so the system uses the clone? Thanks GW override a function - acrylian - 2010-12-06 Clone means take the function, rename it and move elsewhere. For example in a functions.php file (see the theming tutorial) in your theme or a custom plugin. Then you have of course to update your theme to use your custom function. override a function - gwmbox - 2010-12-13 How do you replace a template_function.php function correctly? I know to over-ride a function in functions.php you just clone it and place it in your themes functions.php file, but what about template-functions.php? For example I want to remove the added styles used for front end editing, as I do not use this and having For the moment I just edit the function in template_functions.php, but it would be good if an over-ride feature could be added. By that I mean if any file exists in the themes directory use that in place of the original, I am sure it could be just done by using something like the following at the top of the file, ` ` Probably not the best solution but it is an option. Another option would be for the theme functions.php file to be used as a file that holds all edited functions that are a copy by exact name of the original function, the system then checks for that function in the themes function file before it uses the function from the original file, but I would think that would be slower than having a clone of the whole file in the theme directory as suggested above. Your thoughts? GW override a function - sbillard - 2010-12-13 You cannot replace a function in PHP. Instead you need to create a new function with a different name. If your really want to remove the classes you could impelent a filter to strip them. But what problem are they causing? override a function - gwmbox - 2010-12-13 None, I am just one for wanting tidy code and to strip any unnecessary code were I can GW override a function - acrylian - 2010-12-13 Well, an attached CSS class is hardly really "code". You can always use the object model directly as well, then you get the "pure" stuff. override a function - gwmbox - 2010-12-13 What one defines as 'code' is not needed to be debated here, I merely made a request, you gave your reply and asked a question of which I replied to. Thanks GW override a function - acrylian - 2010-12-13 Just to make clear: No offence taken or meant actually (it was sbillard's question actually..;-)) override a function - gwmbox - 2010-12-13 No problem I'm actually having a little bit of fun playing with the nightly builds and seeing what is new and of course what needs to be fixed. Slightly off topic, but what is the line in the sand between making a post here about an issue versus making a ticket on bugtracker - the two seem to get inter-mixed if you know what I mean. Cheers GW override a function - acrylian - 2010-12-13 Tickets are the best way so that issues are not forgotten if they are not worked on initially. Forum posts are easily buried a few days later. Probably we should discuss the tinyZenpage issue on the ticket from now on..;-) |