[wp-hackers] Child Themes in OOP flavour

Thomas Scholz info at toscho.de
Fri Nov 29 11:01:15 UTC 2013


Hi Filippo,

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

Offer a custom action in your parent theme:

# parent

new Parent_Theme;

class Parent_Theme
{
     public function __construct()
     {
         // set up autoloader, basic config etc, then
         do_action( 'parent_theme_loaded', $autoloader, $config, $this );
     }
}


# child

add_action( 'parent_theme_loaded', 'child_theme_init', 10, 3 );

function child_theme_init( $autoloader, $config, $parent )
{
     // load your classes, set up child theme config
}


Thomas


More information about the wp-hackers mailing list