WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#36091 closed feature request (invalid)

Resolve location of files in template and stylesheet directories

Reported by: screamingdev Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Themes Keywords: needs-patch reporter-feedback
Focuses: template Cc:

Description

Templates files are located in parent themes and can be extended by the child-theme. Unfortunately not all files can be extended or extending parent themes is a pain.

Imagine the functions.php is including multiple files but you want to replace some. Today you need to copy the functions.php and replace the original file with your own one in the child-theme.
The next theme-update might break your theme. Due to changes in the newer parent-theme/function.php that your child-theme/functions.php doesn't have the theme won't work as expected.

For better inheritance parent and child-themes can use the new get_theme_direcotry( $file ) function. It looks up if the required file is given in the child-theme. If so, then this one will be returned. Otherwise it gives you the desired path pointing to the parent-theme.

Attachments (1)

get-theme-directory.patch (3.1 KB) - added by screamingdev 6 years ago.
Patch-file for this functionality

Download all attachments as: .zip

Change History (5)

@screamingdev
6 years ago

Patch-file for this functionality

#1 @johnbillion
6 years ago

  • Keywords needs-patch reporter-feedback added
  • Version trunk deleted

Related: #18302.

@screamingdev Welcome to WordPress Trac. Can you provide a usage example of your patch in action please? It would be good to see what problem this solves. Also it looks like your patch is in reverse (the proposed get_theme_directory() function is being deleted instead of added).

#2 @SergeyBiryukov
6 years ago

For better inheritance parent and child-themes can use the new get_theme_direcotry( $file ) function. It looks up if the required file is given in the child-theme. If so, then this one will be returned. Otherwise it gives you the desired path pointing to the parent-theme.

How is that different from locate_template()?

#3 @screamingdev
6 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Gosh, it acutally is almost like locate_template. You are right @SergeyBiryukov .

Here is a case @johnbillion :

  • Parent-Theme has plenty of files.
  • Child-Theme inherits only the ones it likes.

Problem:

  • Usually the parent themes would use get_template_directory()
  • This causes that the ones from child themes won't be loaded automatically.
  • Inheritance is broken

Solution:

  • Parent themes use another function to resolve files.

Now that I see that there is locate_template it is quite obvious that themes could already have better inheritance for child-themes. I guess someone just have to use it :/

I have to blog about this and spread the words. Sorry for this issue.

#4 @netweb
6 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.