Themes: Improve child theme file inheritance by introducing functions for locating and fetching the URL or path to files within child and parent themes.

The most useful function this introduces is `get_theme_file_uri()`, which returns the URL to the specified file in the child theme if it exists, and falls back to the URL to the specified file in the parent theme. This allows parent themes to reference files (including enqueuing CSS and JavaScript files) that can be overridden by the child theme simply by existing.

This change also introduces `get_theme_file_path()`, which is the file path equivalent of `get_theme_file_uri()`.

Finally, `get_parent_theme_file_uri()` and `get_parent_theme_file_path()` are also introduced, which allow a theme to specifically reference a file URL or file path in the parent theme. These can be used as replacements for `get_template_directory_uri()` and `get_template_directory()` respectively, for consistency.

Props johnbillion, georgestephanis, gma992.
Fixes #18302


git-svn-id: https://develop.svn.wordpress.org/trunk@38578 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
John Blackbourn
2016-09-08 22:53:57 +00:00
parent 8bae522ea8
commit 2aef21a55b
8 changed files with 282 additions and 2 deletions
@@ -0,0 +1 @@
<!-- child only -->
@@ -0,0 +1 @@
<!-- parent and child -->
@@ -0,0 +1,4 @@
/*
Theme Name: Child Theme
Template: theme-file-parent
*/
@@ -0,0 +1 @@
<!-- parent and child -->
@@ -0,0 +1 @@
<!-- parent only -->
@@ -0,0 +1,3 @@
/*
Theme Name: Parent Theme
*/