Make WordPress Core

Opened 6 years ago

Closed 4 years ago

#22273 closed enhancement (invalid)

Parent/child page template inheritance should be more consistent

Reported by: DrewAPicture Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Themes Keywords:
Focuses: Cc:


When page templates in sub-directories was introduced in 3.4, we also inadvertantly introduced some scenarios where page template inheritance from parent to child themes gets wonky.

After some testing on trunk (r22290), I came up with some interesting findings in what I like to call Battle of the page template inheritance:

Relationship: Parent:Child

Same filename, same Template Name:

  • root:root = Child wins
  • root:sub = Parent wins
  • sub:sub = Child wins
  • sub:root = Parent wins

Different filename, same Template Name:

  • root:root = Parent wins
  • root:sub = Parent wins
  • sub:sub = Parent wins
  • sub:root = Parent wins

Same filename, different Template Name:

  • root:root = Child wins
  • root:sub = Both available
  • sub:sub = Child wins
  • sub:root = Both available

In #22269, @duck_ made light of get_page_templates() making use of array_flip() which effectively gives preference to Parent templates in some situations. I think it's worth looking at whether we can't allow get_page_templates() to properly respect inheritance, regardless of sub or root path.

The other interesting tidbit of course is that in the third set, we see the Child can override the parent file of the same filename, even if the Template Name is different, which I take is expected, but odd in terms of inheritance.

Change History (2)

#1 @knutsp
5 years ago

  • Cc knut@… added

#2 @DrewAPicture
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

I think this is actually unnecessary now. The template hierarchy we have seems to be working as expected.

Note: See TracTickets for help on using tickets.