W3cubDocs

/WordPress

WP_REST_Font_Faces_Controller::relative_fonts_path( string $path ): string

Returns relative path to an uploaded font file.

Description

The path is relative to the current fonts directory.

Parameters

$pathstringrequired
Full path to the file.

Return

string Relative path on success, unchanged path on failure.

Source

protected function relative_fonts_path( $path ) {
	$new_path = $path;

	$fonts_dir = wp_get_font_dir();
	if ( str_starts_with( $new_path, $fonts_dir['basedir'] ) ) {
		$new_path = str_replace( $fonts_dir['basedir'], '', $new_path );
		$new_path = ltrim( $new_path, '/' );
	}

	return $new_path;
}

Changelog

Version Description
6.5.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_rest_font_faces_controller/relative_fonts_path