[wp-hackers] Child Themes in OOP flavour

Filippo Pisano filippo.pisano at gmail.com
Fri Nov 29 10:49:30 UTC 2013


Dear hackers,


I usually work with themes using OOP and classes to keep my code and
namespaces well organized and clean. The only limitation I have found with
this approach regards the use of child themes.
As you know, child themes' functions.php is *always* loaded before the
parent theme's one thus making impossible to create a hierarchical OO class
structrure between child and parent theme.
What I'd like to do is to use MyThemeClass as the parent class for
MyChildThemeClass (extended example: http://pastebin.com/KfufXTKM) and be
able to override parent's methods when needed.

By now the only way to obtain a similar result is through the pluggable
functions mechanism (if(!function_exists etc) which is limited to a non OO
oriented code (horrible prefixed functions).
Looking inside WP code there is no way to override the inclusion order of
template's file:

// Load the functions for the active theme, for both parent and child theme
if applicable.
if ( ! defined( 'WP_INSTALLING' ) || 'wp-activate.php' === $pagenow ) {
if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH .
'/functions.php' ) )
 include( STYLESHEETPATH . '/functions.php' );
if ( file_exists( TEMPLATEPATH . '/functions.php' ) )
 include( TEMPLATEPATH . '/functions.php' );
}

So my questions are: am I the only one using OO code with themes? Do you
really think that the pluggable mechanism is better than a stronger
hierarchical structure? Wouldn't it be better if template files inclusion
order was configurable?



F.


More information about the wp-hackers mailing list