|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Polyfills used by Behat to support multiple versions of WP. |
| 4 | + * |
| 5 | + * This file will get installed as a must-use plugin in WP installs that are run |
| 6 | + * by the functional tests. |
| 7 | + */ |
| 8 | + |
| 9 | +/* |
| 10 | + * Add a polyfill for the get_theme_file_uri(), as it is required for the |
| 11 | + * TwentyTwenty theme's starter content, and will fatal the site if you install |
| 12 | + * WP 5.3 first (setting TwentyTwenty as the active theme) and then downgrade |
| 13 | + * to a version of WP lower than 4.7. |
| 14 | + * |
| 15 | + * Note: This is a quick fix, and a cleaner solution would be to change the |
| 16 | + * active theme on downgrading, if the current theme declares it is not |
| 17 | + * supported. |
| 18 | + * |
| 19 | + * See: https://github.com/WordPress/twentytwenty/issues/973 |
| 20 | + */ |
| 21 | +if ( ! function_exists( 'get_theme_file_uri' ) ) { |
| 22 | + /** |
| 23 | + * Retrieves the URL of a file in the theme. |
| 24 | + * |
| 25 | + * Searches in the stylesheet directory before the template directory so themes |
| 26 | + * which inherit from a parent theme can just override one file. |
| 27 | + * |
| 28 | + * @since 4.7.0 |
| 29 | + * |
| 30 | + * @param string $file Optional. File to search for in the stylesheet directory. |
| 31 | + * @return string The URL of the file. |
| 32 | + */ |
| 33 | + function get_theme_file_uri( $file = '' ) { |
| 34 | + $file = ltrim( $file, '/' ); |
| 35 | + |
| 36 | + if ( empty( $file ) ) { |
| 37 | + $url = get_stylesheet_directory_uri(); |
| 38 | + } elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { |
| 39 | + $url = get_stylesheet_directory_uri() . '/' . $file; |
| 40 | + } else { |
| 41 | + $url = get_template_directory_uri() . '/' . $file; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Filters the URL to a file in the theme. |
| 46 | + * |
| 47 | + * @since 4.7.0 |
| 48 | + * |
| 49 | + * @param string $url The file URL. |
| 50 | + * @param string $file The requested file to search for. |
| 51 | + */ |
| 52 | + return apply_filters( 'theme_file_uri', $url, $file ); |
| 53 | + } |
| 54 | +} |
0 commit comments