WP_REST_Font_Faces_Controller::relative_fonts_path()protectedWP 6.5.0

Returns relative path to an uploaded font file.

The path is relative to the current fonts directory.

Method of the class: WP_REST_Font_Faces_Controller{}

Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.

No Hooks.

Return

String. Relative path on success, unchanged path on failure.

Usage

// protected - for code of main (parent) or child class
$result = $this->relative_fonts_path( $path );
$path(string) (required)
Full path to the file.

Changelog

Since 6.5.0 Introduced.

WP_REST_Font_Faces_Controller::relative_fonts_path() code WP 6.6.2

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;
}