Skip to content

Commit fc5529e

Browse files
committed
Move polyfills to separate file
1 parent 012151f commit fc5529e

File tree

2 files changed

+51
-47
lines changed

2 files changed

+51
-47
lines changed

features/bootstrap/polyfills.php

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

features/bootstrap/support.php

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -215,50 +215,3 @@ function check_that_yaml_string_contains_yaml_string( $actual_yaml, $expected_ya
215215

216216
return compare_contents( $expected_value, $actual_value );
217217
}
218-
219-
/*
220-
* Add a polyfill for the get_theme_file_uri(), as it is required for the
221-
* TwentyTwenty theme's starter content, and will fatal the site if you install
222-
* WP 5.3 first (setting TwentyTwenty as the active theme) and then downgrade
223-
* to a version of WP lower than 4.7.
224-
*
225-
* Note: This is a quick fix, and a cleaner solution would be to change the
226-
* active theme on downgrading, if the current theme declares it is not
227-
* supported.
228-
*
229-
* See: https://github.com/WordPress/twentytwenty/issues/973
230-
*/
231-
if ( ! function_exists( 'get_theme_file_uri' ) ) {
232-
/**
233-
* Retrieves the URL of a file in the theme.
234-
*
235-
* Searches in the stylesheet directory before the template directory so themes
236-
* which inherit from a parent theme can just override one file.
237-
*
238-
* @since 4.7.0
239-
*
240-
* @param string $file Optional. File to search for in the stylesheet directory.
241-
* @return string The URL of the file.
242-
*/
243-
function get_theme_file_uri( $file = '' ) {
244-
$file = ltrim( $file, '/' );
245-
246-
if ( empty( $file ) ) {
247-
$url = get_stylesheet_directory_uri();
248-
} elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
249-
$url = get_stylesheet_directory_uri() . '/' . $file;
250-
} else {
251-
$url = get_template_directory_uri() . '/' . $file;
252-
}
253-
254-
/**
255-
* Filters the URL to a file in the theme.
256-
*
257-
* @since 4.7.0
258-
*
259-
* @param string $url The file URL.
260-
* @param string $file The requested file to search for.
261-
*/
262-
return apply_filters( 'theme_file_uri', $url, $file );
263-
}
264-
}

0 commit comments

Comments
 (0)