Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|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
add comment

5 Answers 5

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!

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

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

share|improve this answer
    
AFAIK this was the original reason, not technically (you can organize that in a way it does not pose a problem to edit your install) but because of users then complaining in the Wordpress support forums that the update did break their site. As upgrading often did pose problems on it's own already, some users wanted to ensure to at least get the number of the "user-self-made" problems low and out of the equation. –  hakre May 23 '13 at 9:56
add comment

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. :)

share|improve this answer
    
The image is a cultural reference to: Every time you masturbate... God kills a kitten –  hakre May 23 '13 at 9:14
    
Thanks for that TMI @harke. ;-) –  MikeSchinkel May 24 '13 at 8:39
add comment

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.

share|improve this answer
    
I'd say number one reason to hack core files is to make them work like I need them not like others think I might need them. That can be temporarily (like in your debugging example) but this can be also per a full version or even across major versions because of issues that do not get fixed in the original wordpress package (being it wordpress.org or pre-packed by somebody else). –  hakre May 23 '13 at 9:53
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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