Modifying Core Files?
-
I would like to make a few small changes to the way some parts of WordPress work on my site.
This ultimately means adding 1 or 2 lines of code to certain files in the wp-includes folder.The problem that I have is that they’ll most likely be overwritten when I update WordPress.
So, I’d like to know if there’s a way of making child templates for core files like there is for themes?
Or if my only option is to backup my custom files before updating and restore them afterwards?
-
No, but there are lots of actions and filters you can hook into to alter how WP works. I’ve done hundreds of hacks and it’s very rare to find a situation that can only be fixed by altering core files.
Restoring customized files is a very poor choice as other content on that file besides your changes may not work properly with updated files or may contain security weaknesses that were patched with the update.
Altering core files means you’re destined to modifying updated files manually line by line. Better to use that time to find a “clean” hack that does not require changing core files. There’s almost always a way.
I have a very specific idea that can be achieved with just 2 lines of code.
Unfortunately, it seems that no-one else has had the same idea and thus, there are no plugins that can achieve the level of control I’m after.So basically, I need to know if there is an easy way to have WordPress process my code for the relevant feature instead of it’s own. – like how child themes work.
The current plan is to just add the relevant code where it needs to be after each update.
It’s quite easy at just a single copy-paste, but I’d like a way to achieve this that wouldn’t require the extra step in the update process.I don’t exactly want to write a whole plugin with plenty of code to replace an entire WordPress module, which I will then have to keep up-to-date and worry about compatibility. Nor do I know how to do this and I’m lazy to learn. (since I’m short on time)
I just need to know if there is a way to have WordPress reference my PHP file for a single function instead of it’s own, without modifying it’s own one.
As bcworkz said, filters and actions. You will need to look through the source code (which I’m sure you’ve done so far) and see what filters or actions are available to modify the functionality that you’re looking for. If they are there in the code, use them. If they are not there, you would be stuck with either not being able to make the changes, or hacking the core and loosing the changes on every update.
Another note too, if you can’t find an action or filter that will work the way that you want it to you can always propose a change to the core code to add one in. Think of that as a way of givng back to the community. 🙂
Thanks.
You explained it a bit better.After looking through
http://codex.wordpress.org/Plugin_API/Filter_Reference
and
http://codex.wordpress.org/Function_Reference/add_filterI think I may me able to achieve my goal.
The topic ‘Modifying Core Files?’ is closed to new replies.