Best way to extends core classes in theme?

What you are doing will work, and is correct as far as the PHP goes.

Whether it is a good idea or not really depends on what you are doing specifically and whether you can do it with hooks— actions and filters– instead. If you can do it with hooks you probably should but your question doesn’t have detail enough to really allow for a great answer.

I don’t think that extending Core classes is “wrong” necessarily but you can set yourself up for higher than normal maintenance as your extended class may need to change if the parent does, so be aware. Its the “fragile base class” problem.

This is not really “overloading”, by the way, and in PHP “overloading” is not really that anyway.

Leave a Comment