WP_Theme_JSON_Resolver::get_resolved_theme_uris()
Resolves relative paths in theme.json styles to theme absolute paths and returns them in an array that can be embedded as the value of _link object in REST API responses.
Метод класса: WP_Theme_JSON_Resolver{}
Хуков нет.
Возвращает
Массив
. An array of resolved paths.
Использование
$result = WP_Theme_JSON_Resolver::get_resolved_theme_uris( $theme_json );
- $theme_json(WP_Theme_JSON) (обязательный)
- A theme json instance.
Список изменений
С версии 6.6.0 | Введена. |
Код WP_Theme_JSON_Resolver::get_resolved_theme_uris() WP Theme JSON Resolver::get resolved theme uris WP 6.6.2
public static function get_resolved_theme_uris( $theme_json ) { $resolved_theme_uris = array(); if ( ! $theme_json instanceof WP_Theme_JSON ) { return $resolved_theme_uris; } $theme_json_data = $theme_json->get_raw_data(); // Top level styles. $background_image_url = isset( $theme_json_data['styles']['background']['backgroundImage']['url'] ) ? $theme_json_data['styles']['background']['backgroundImage']['url'] : null; /* * The same file convention when registering web fonts. * See: WP_Font_Face_Resolver::to_theme_file_uri. */ $placeholder = 'file:./'; if ( isset( $background_image_url ) && is_string( $background_image_url ) && // Skip if the src doesn't start with the placeholder, as there's nothing to replace. str_starts_with( $background_image_url, $placeholder ) ) { $file_type = wp_check_filetype( $background_image_url ); $src_url = str_replace( $placeholder, '', $background_image_url ); $resolved_theme_uri = array( 'name' => $background_image_url, 'href' => sanitize_url( get_theme_file_uri( $src_url ) ), 'target' => 'styles.background.backgroundImage.url', ); if ( isset( $file_type['type'] ) ) { $resolved_theme_uri['type'] = $file_type['type']; } $resolved_theme_uris[] = $resolved_theme_uri; } return $resolved_theme_uris; }