Often a quick solution to a problem, can be solved by hacking the WordPress core, that is changing the code that is WordPress itself.
This is a very dangerous road to take! Don’t do it, ever!
You can always change how WordPress works, by using plugins. This can sometimes be rather tiresome and difficult, but the extra work always outweighs the problems you get by changing the WordPress core itself.
Some would say that there can be situations where hacking the core is the only solution, but if you are here asking questions, you are definitely not in that situation.
This question, is meant to be an introduction to a collective work of why you should never hack the WordPress core, that we can use as a reference. If you have something to add, feel free to add it as a question.
The best reason not to hack core is that whatever you are doing should be reworked as a patch for core instead!
Obviously ALL of your code would not make a good patch at all, or at least it rarely would. Instead you need to figure out what hook (action or filter) is missing in core that would let you do whatever it is you need to do without hacking core. We don’t need to hack core when there are adequate filters/actions, so finding what the missing hook is will always remove the need to hack core.
This can often require some tough problem-solving and tricky legwork, but more often then not what happens is you discover that there already is a hook to solve your problem, so you don’t have to hack core!
In the rare scenario where there really is no hook you just need to post on trac explaining why your hook needs to exist. If you get your new hook committed then you have a temporary 1-line hack to core that won’t need to be worried about the next time you update.
Even if your suck at getting stuff done in the Core trac (it takes some convincing to get stuff committed), you have at least boiled your core hack to the minimum possible: 1 line of code for your action/filter. When you update WP you’ve now replaced all the code you shoved into core with one line that needs to be updated, and your plugin can stay the same!
There’s also the fact that once you upgrade wordpress to the latest version all your changes to the core files are overwritten
I believe this, directly from WordPress Codex, says it all:
🙂
This warning is way old, much before the times of decentralized version control systems like Git. Back in those days, to hack core, you needed to keep your changes as a set of patches your own. Because some (mostly inexperienced developers fiddling with WordPress) didn’t do patches to keep track of their changes, they ran into a problem: In the end they had problems with updating Worpdress to the new version and the saying was born.
The warning was more or less a cultural side-reference to the “Every time you masturbate… God kills a kitten” image caption and obviously meant as fun. However, the analogy between “hacking wordpress core” and “masturbating” was brought up. This probably has led to quite some popularity.
Sure hacking core is a two-sided sword and I guess this is why you have asked.
First of all it is perfectly valid, possible and feasible both in past and present to hack core. In the past with patch-sets and even more easy today by using git and the git repo of WordPress publicly available on Github.
Instead of telling users (who might not even understand what this is about) they are dumb by making jokes about them, it’s better to encourage them and educate them.
Also, and this is one of the more dark sides in the WordPress history, the WordPress community does not promote here well. Even though it sort-of encourages users to bring changes upstream (that means into the original code-repository) which is a good thing normally, WordPress didn’t do for the libraries they have taken over into their tree from upstream sources. So keep these sayings lightly, it’s nothing WordPress lead and core developers did follow for the code they have been taken over from others as well.
So if you judge on the saying by looking at the developers hands, it’s purely a joke, it’s just a vulgar cultural reference.
The best suggestion I can give is if you’re a developer and you want to make changes to core, do it. Do it in the way it pleases you not others. WordPress is Free Software for a reason and you should be proud of it and what yourself is doing with it. Publicly or privately. If you’re looking for ways to make this more feasible, create a workflow around it as you would also if you’re doing other kind of development work.
There have been 3-and-a-half times I’ve needed to hack core to solve a problem.
1) Was a bug fix. I reported it as a bug in Trac along with a diff patch. The functionality is being re-worked in the next version of WP already, basically invalidating the bug. Until then I can easily apply the patch I’ve created on current/new installs.
2) Was to add very detailed logging to try and track down a very specific problem a user was encountering. Not an every day situation, and certainly not functionality related.
3a) I wanted to add an extra field to Categories in WP 2.8.5. The built-in hooks to do this did not work properly (known issue), and I believe this particular issue was fixed in the 2.9 tree. At the end of the day, the implementation was flawed and we re-designed the feature to work in a different way that didn’t require a core modification.
3b) I thought I needed to modify core to change the comment moderation links, but while I was digging around I found some hooks I previously didn’t know about and was able to implement the feature as a plugin.