[wp-hackers] Child Themes in OOP flavour
Nikola Nikolov
nikolov.tmw at gmail.com
Fri Nov 29 11:08:25 UTC 2013
What Thomas suggested, except for maybe I would hook onto the
'after_setup_theme' hook with priority 0 - the reason for this is that this
way you wouldn't be able to make a mistake - as in let's say that for some
reason you include another vital file(containing a class definition) after
you call your custom action - this way, you can get a fatal error(well
obviously that's something you can't miss, but still).
Anyway - my thinking is that it might be better to do extensions in the
child theme after the theme is completely set-up(this means all code in
child and parent theme's functions.php completes executing.
On Fri, Nov 29, 2013 at 1:01 PM, Thomas Scholz <info at toscho.de> wrote:
> 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
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list