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.

link|improve this question
@googletorp: You rock dude! – MikeSchinkel Sep 11 '10 at 9:25
I do not agree that one should never do it, the original question has some answers that point to reasons why, so I give this question a downvote. Furthermore, I also don't agree that if you are here asking questions, you are definitely not in that situation. This is a site for experts too, so questions about hacking core should not be censored. But maybe we should discuss it further on the meta site. – Jan Fabry Sep 11 '10 at 10:45
feedback

4 Answers

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!

link|improve this answer
@Jeremy Clark - Good one! – MikeSchinkel Oct 21 '10 at 9:00
feedback

There's also the fact that once you upgrade wordpress to the latest version all your changes to the core files are overwritten

link|improve this answer
feedback

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.

link|improve this answer
feedback

I believe this, directly from WordPress Codex, says it all:

Photo: Don't Hack WordPress Core; Or the Kitten Get's it!

Hope this helps. :)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.