Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 3 years ago

#17805 closed defect (bug) (wontfix)

"Child of a child" Theme: Convert include(functions.php) to include_once().

Reported by: 5ubliminal Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.2
Component: Themes Keywords: has-patch
Focuses: Cc:


After some trickery, I managed to get child of a child themes working. Unfortunately bumped into a problem.

The wp-settings.php include(functions.php) breaks the whole thing as, in the first "child", you need to manually include the parent's functions.php when you use the "child of child" (2nd child).

I added a patch, seriously needs your attention or better child of child theme support, recursive location or master parent and reverse order functions.php inclusion.


Attachments (1)

include_once-functions.php.patch (744 bytes) - added by 5ubliminal 7 years ago.
The patch.

Download all attachments as: .zip

Change History (15)

#1 @hebbet
7 years ago

  • Keywords has-patch added

#2 @nacin
7 years ago

  • Keywords close added

We don't support child of child themes.

You can do this on your own. Additional trickery will require including one of the parent function.php calls manually. I don't see what a conversion to include_once has to do with it.

include_once is slower. I don't see a reason for the patch.

#3 @ericmann
7 years ago

I can understand what you're doing in the patch (you can't include() the file in wp-settings.php and then include() it again in the 2nd child theme. So kudos to figuring out how to fix it.

At the same time, I agree 100% with Nacin. We don't support child of child themes (grandchild themes) for several valid reasons already hashed out at-length elsewhere. Vote to close.

#4 @5ubliminal
7 years ago

If you guys say so: http://arin.me/blog/php-require-vs-include-vs-require_once-vs-include_once-performance-test

Net everyone agrees.

PS: I'll do some tests.

Version 0, edited 7 years ago by 5ubliminal (next)

#5 @5ubliminal
7 years ago

  • Keywords close removed

On my setup (Windows 7 x64, PHP 5.3.6, Apach 2.2+ VC9):

  • include_once = 0.023 - 0.025
  • include = 0.024 - 0.026

170 get_included_files() before I reach this line. Not really the holly grail of performance in my opinion considering it's just one lousy call.

#6 @nacin
7 years ago

Regardless of justification for performance reasons, you've yet to justify it for functional reasons.

There would be three functions.php files in this case -- grandchild, child, and parent.

Core, presumably, would believe that the grandchild is STYLESHEETPATH, and the child is TEMPLATEPATH. You've then hooked in and did final checks for parent templates in the various hierarchy trees, if I had to guess.

At that point, your grandchild theme should know it needs to include the grandparent functions.php. No extra juggling required.

#7 @5ubliminal
7 years ago

You can not include the parent as it's already include with include(). The inclusion is done before the include ends and PHP does not track it.

I know this error and it's how it should be. PHP marks a file as included at the end of the call. But there are three themes involved:

  1. Root
  2. Parent
  3. Child

Without include_once() Parent can not be activated. You can just use the Original and last Child. Do some tests. Including a file with include once in the same include breaks: Double declaration. No going around.

Last edited 7 years ago by 5ubliminal (previous) (diff)

#8 @nacin
7 years ago

Root, Parent, and Child. Which one is stylesheet, which one is template, which one is neither, and how are you loading the third one?

#9 @5ubliminal
7 years ago

Root is THEME. Fully featured theme I bought.

Parent is a brutal modification. Remove sidebars, added others, changed stylesheets, some hooks inside functions.php but rather empty. Child is another modification, this time of the Parent. It has its own extra hooks in functions.php and build on the parent. It's designed for one site only.. Each of these stylesheets use @include to pull the closest parent's.

Each child will be a blog. Special design for a VERY blog. But as the Parent is the Root changed drastically, I need them all. The child relies on the parent's changes while the parent depends on the root to exist.

Last edited 7 years ago by 5ubliminal (previous) (diff)

#10 @nacin
7 years ago

I'll rephrase. Which is STYLESHEETPATH, which is TEMPLATEPATH.

#11 @5ubliminal
7 years ago

STYLESHEETPATH is Parent or Child. TEMPLATEPATH is Root or Parent. So Parent/Child and Root/Parent combinations. But they include each other. Child includes Parent, Parent includes Root... and this is where it breaks. If Child went directly for Root, it will lose the Parent vital modifications, if it goes for Parent, the Parent has to load Root.

But if I use the Parent theme, WordPress includes Root.

Parent includes Root, WordPress includes Root when using Parent as theme. This is the breaking point.

#12 @nacin
7 years ago

You should be able to properly detect this already, without any help from WordPress.

In your Parent theme, you need to include Root, but *only* when the parent theme is being used as a child theme.

if ( STYLESHEETPATH == dirname( __FILE__ ) ) in the parent theme's functions.php. If that returns true, it's being used as a child theme. False, being used as a parent theme.

Can also do: if ( get_stylesheet() == 'parent_theme_name' ) -- serves the same purpose.

Point is, you can do all of these checks. You don't need to blindly include files. WordPress doesn't need to change for what you're trying to do.

#13 @nacin
7 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Severity changed from major to normal
  • Status changed from new to closed

This ticket was mentioned in Slack in #core by peterwilsoncc. View the logs.

3 years ago

Note: See TracTickets for help on using tickets.